|
|
|
|
@ -23,10 +23,11 @@ class Creator {
|
|
|
|
|
$name = $this->readline('New model name: ');
|
|
|
|
|
$table = $this->readline('Table name: ');
|
|
|
|
|
$entity = $this->readline('Entity name: ');
|
|
|
|
|
$namespace = $this->readline('Namespace [App\Models]: ', 'App\Models');
|
|
|
|
|
if (strlen($entity) <= 0) {
|
|
|
|
|
$entity = $table;
|
|
|
|
|
}
|
|
|
|
|
$model_filepath = $this->rootDir().'/models/'.$name.'.php';
|
|
|
|
|
$model_filepath = $this->rootDir().'/Models/'.$name.'.php';
|
|
|
|
|
if ($this->readline("Create MODEL class '$model_filepath'? (y - yes, other - no) ") != 'y') {
|
|
|
|
|
echo "Creating of MODEL class is skipped\n";
|
|
|
|
|
return false;
|
|
|
|
|
@ -47,11 +48,11 @@ class Creator {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$table_columns = $this->dbh->getTableColumns($table);
|
|
|
|
|
$suc = $this->modelSave($model_filepath, $name, $table, $entity, $table_columns['pks'], $table_columns['columns'], $table_columns['types']);
|
|
|
|
|
$suc = $this->modelSave($model_filepath, $name, $table, $entity, $table_columns['pks'], $table_columns['columns'], $table_columns['types'], $namespace);
|
|
|
|
|
echo $suc ? "MODEL class created" : 'Error: MODEL class not created';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function modelSave($filepath, $name, $tablename, $entity, $pks, $columns, $types) {
|
|
|
|
|
private function modelSave($filepath, $name, $tablename, $entity, $pks, $columns, $types, $namespace) {
|
|
|
|
|
if (is_array($pks) && count($pks) > 1) {
|
|
|
|
|
$primary_key_name = "array('".implode("', '", $pks)."')";
|
|
|
|
|
$columns = array_merge($pks, $columns);
|
|
|
|
|
@ -93,6 +94,7 @@ class Creator {
|
|
|
|
|
$data[\'changed_dt\'] = date(\'Y-m-d H:i:s\');
|
|
|
|
|
}'
|
|
|
|
|
: '';
|
|
|
|
|
$namespace_str = strlen($namespace) > 0 ? "\nnamespace $namespace;\n" : '';
|
|
|
|
|
$content = '<?'."php
|
|
|
|
|
/*
|
|
|
|
|
TPsoft.org 2000-".date('Y')."
|
|
|
|
|
@ -101,7 +103,7 @@ class Creator {
|
|
|
|
|
Milestones:
|
|
|
|
|
".date('Y-m-d H:i')." Created
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
".$namespace_str."
|
|
|
|
|
class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
|
|
|
|
|
|
|
|
|
public $"."tables = array(
|
|
|
|
|
@ -149,6 +151,19 @@ class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
|
|
|
|
->toArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getListOrganize($"."cola_name, $"."search = array(), $"."reverse = false, $"."concat_or = false) {
|
|
|
|
|
$"."all = $"."this->getList($"."search, $"."reverse, $"."concat_or);
|
|
|
|
|
$"."ret = array();
|
|
|
|
|
if (is_array($"."all)) foreach ($"."all as $"."key => $"."row) {
|
|
|
|
|
$"."ret[$"."row[$"."cola_name]] = $"."row;
|
|
|
|
|
}
|
|
|
|
|
return $"."ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getListByID($"."search = array(), $"."reverse = false, $"."concat_or = false) {
|
|
|
|
|
return $"."this->getListOrganize($primary_key_name, $"."search, $"."reverse, $"."concat_or);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ".$entity_one."Combo($"."col_key, $"."col_value, $"."add_empty = false) {
|
|
|
|
|
return $"."this->search('".$entity."')
|
|
|
|
|
->toCombo($"."col_key, $"."col_value, $"."add_empty);
|
|
|
|
|
|