Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
ae59ffaa97 | |||
616dc01c21 |
@ -23,10 +23,11 @@ class Creator {
|
|||||||
$name = $this->readline('New model name: ');
|
$name = $this->readline('New model name: ');
|
||||||
$table = $this->readline('Table name: ');
|
$table = $this->readline('Table name: ');
|
||||||
$entity = $this->readline('Entity name: ');
|
$entity = $this->readline('Entity name: ');
|
||||||
|
$namespace = $this->readline('Namespace [App\Models]: ', 'App\Models');
|
||||||
if (strlen($entity) <= 0) {
|
if (strlen($entity) <= 0) {
|
||||||
$entity = $table;
|
$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') {
|
if ($this->readline("Create MODEL class '$model_filepath'? (y - yes, other - no) ") != 'y') {
|
||||||
echo "Creating of MODEL class is skipped\n";
|
echo "Creating of MODEL class is skipped\n";
|
||||||
return false;
|
return false;
|
||||||
@ -47,11 +48,11 @@ class Creator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$table_columns = $this->dbh->getTableColumns($table);
|
$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';
|
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) {
|
if (is_array($pks) && count($pks) > 1) {
|
||||||
$primary_key_name = "array('".implode("', '", $pks)."')";
|
$primary_key_name = "array('".implode("', '", $pks)."')";
|
||||||
$columns = array_merge($pks, $columns);
|
$columns = array_merge($pks, $columns);
|
||||||
@ -93,6 +94,7 @@ class Creator {
|
|||||||
$data[\'changed_dt\'] = date(\'Y-m-d H:i:s\');
|
$data[\'changed_dt\'] = date(\'Y-m-d H:i:s\');
|
||||||
}'
|
}'
|
||||||
: '';
|
: '';
|
||||||
|
$namespace_str = strlen($namespace) > 0 ? "\nnamespace $namespace;\n" : '';
|
||||||
$content = '<?'."php
|
$content = '<?'."php
|
||||||
/*
|
/*
|
||||||
TPsoft.org 2000-".date('Y')."
|
TPsoft.org 2000-".date('Y')."
|
||||||
@ -101,7 +103,7 @@ class Creator {
|
|||||||
Milestones:
|
Milestones:
|
||||||
".date('Y-m-d H:i')." Created
|
".date('Y-m-d H:i')." Created
|
||||||
*/
|
*/
|
||||||
|
".$namespace_str."
|
||||||
class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
||||||
|
|
||||||
public $"."tables = array(
|
public $"."tables = array(
|
||||||
@ -149,6 +151,19 @@ class ".$name." extends \TPsoft\DBmodel\DBmodel {
|
|||||||
->toArray();
|
->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) {
|
public function ".$entity_one."Combo($"."col_key, $"."col_value, $"."add_empty = false) {
|
||||||
return $"."this->search('".$entity."')
|
return $"."this->search('".$entity."')
|
||||||
->toCombo($"."col_key, $"."col_value, $"."add_empty);
|
->toCombo($"."col_key, $"."col_value, $"."add_empty);
|
||||||
|
@ -851,7 +851,7 @@ class DBmodel
|
|||||||
return $this->allowNextError();
|
return $this->allowNextError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function import($objModel)
|
public function import(DBmodel $objModel)
|
||||||
{
|
{
|
||||||
if (is_null($objModel)) return false;
|
if (is_null($objModel)) return false;
|
||||||
if (
|
if (
|
||||||
|
@ -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) {
|
if (strlen($table_name) <= 0) {
|
||||||
$this->lastMessage = 'Table ' . strtoupper($table_name) . ' - invalid index';
|
$this->lastMessage = 'Table ' . strtoupper($table_name) . ' - invalid index';
|
||||||
@ -99,7 +99,7 @@ class Maintenance
|
|||||||
// TEST output
|
// TEST output
|
||||||
$table_name,
|
$table_name,
|
||||||
// FIX query
|
// FIX query
|
||||||
'CREATE TABLE `' . $table_name . '` (' . $definition . ')'
|
'CREATE TABLE `' . $table_name . '` (' . $definition . ') ' . $after_definition
|
||||||
);
|
);
|
||||||
$this->lastMessage = 'Table ' . strtoupper($table_name) . ' (' . $table_name . ')';
|
$this->lastMessage = 'Table ' . strtoupper($table_name) . ' (' . $table_name . ')';
|
||||||
return $status;
|
return $status;
|
||||||
@ -146,7 +146,7 @@ class Maintenance
|
|||||||
|
|
||||||
public function checkDBRetype($table_name, $column, $new_type, $definition)
|
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;
|
return Maintenance::ABNORMAL;
|
||||||
}
|
}
|
||||||
$status = $this->checkDB(
|
$status = $this->checkDB(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user