diff --git a/src/Creator.php b/src/Creator.php index 5aee0d6..dfa249b 100644 --- a/src/Creator.php +++ b/src/Creator.php @@ -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 = 'toArray(); } + public function getListByID($"."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[$primary_key_name]] = $"."row; + } + return $"."ret; + } + public function ".$entity_one."Combo($"."col_key, $"."col_value, $"."add_empty = false) { return $"."this->search('".$entity."') ->toCombo($"."col_key, $"."col_value, $"."add_empty); diff --git a/src/DBmodel.php b/src/DBmodel.php index 8885e54..0faa2b6 100644 --- a/src/DBmodel.php +++ b/src/DBmodel.php @@ -851,7 +851,7 @@ class DBmodel return $this->allowNextError(); } - public function import($objModel) + public function import(DBmodel $objModel) { if (is_null($objModel)) return false; if ( diff --git a/src/Maintenance.php b/src/Maintenance.php index 181634c..cf034d6 100644 --- a/src/Maintenance.php +++ b/src/Maintenance.php @@ -87,7 +87,7 @@ class Maintenance ); } - public function checkDBTable($table_name, $definition) + public function checkDBTable($table_name, $definition, $after_definition = '') { if (strlen($table_name) <= 0) { $this->lastMessage = 'Table ' . strtoupper($table_name) . ' - invalid index'; @@ -99,7 +99,7 @@ class Maintenance // TEST output $table_name, // FIX query - 'CREATE TABLE `' . $table_name . '` (' . $definition . ')' + 'CREATE TABLE `' . $table_name . '` (' . $definition . ') ' . $after_definition ); $this->lastMessage = 'Table ' . strtoupper($table_name) . ' (' . $table_name . ')'; return $status; @@ -146,7 +146,7 @@ class Maintenance public function checkDBRetype($table_name, $column, $new_type, $definition) { - if (!$this->existsColumn($table_name, $column_old)) { + if (!$this->existsColumn($table_name, $column)) { return Maintenance::ABNORMAL; } $status = $this->checkDB(