Commit 3983db68 authored by Ortiz-Troncoso, Alvaro's avatar Ortiz-Troncoso, Alvaro
Browse files

Do not change names of tables (e.g. Species becomes Specie ???)

parent 0c37f1f6
......@@ -4,7 +4,7 @@ namespace Iber\Generator\Commands;
use Illuminate\Database\Connection;
use Illuminate\Database\Events\StatementPrepared;
use Illuminate\Support\Pluralizer;
// use Illuminate\Support\Pluralizer;
use Illuminate\Console\GeneratorCommand;
use Iber\Generator\Utilities\RuleProcessor;
use Iber\Generator\Utilities\SetGetGenerator;
......@@ -188,11 +188,18 @@ class MakeModelsCommand extends GeneratorCommand {
$class = VariableConversion::convertTableNameToClassName($prefixRemovedTableName);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
if (method_exists($this, 'qualifyClass')) {
$name = Pluralizer::singular($this->qualifyClass($prefix . $class));
} else {
$name = Pluralizer::singular($this->parseName($prefix . $class));
}
*/
if (method_exists($this, 'qualifyClass')) {
$name = $this->qualifyClass($prefix . $class);
} else {
$name = $this->parseName($prefix . $class);
}
$path = $this->getPath($name);
$this->info(basename($path) . ":\t is data table: created. ");
......@@ -307,9 +314,13 @@ class MakeModelsCommand extends GeneratorCommand {
// Hence we use the following naming convention:
//tableName_columnName where columnName contains the foreign key instead of the target table's name as function name.
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$referenced_model = ucfirst(Pluralizer::singular($relation['referenced_table']));
//$referenced_table_trunc = Pluralizer::singular($relation['referenced_table']) . "_" . explode("_",$foreign_key)[0];
$referenced_table_trunc = Pluralizer::singular($relation['referenced_table']) . "_" . explode("_",$foreign_key)[0];
$referenced_table_trunc = Pluralizer::singular($relation['referenced_table']) . "_" . strtolower(explode("_", $foreign_key)[0]);
*/
$referenced_model = ucfirst($relation['referenced_table']);
$referenced_table_trunc = $relation['referenced_table'] . "_" . strtolower(explode("_", $foreign_key)[0]);
$stub = <<<RELATION
......
......@@ -734,10 +734,16 @@ if (substr($name, 0, 3) != "Gdm") {
// $content = str_replace('GDM_NAME', GDM_NAME, $content);
$content = str_replace('/GDM_DATAMODEL_VERSION/', '/' . GDM_DATAMODEL_VERSION .'/', $content);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('SINGULAR_NAME', singularize($name), $content);
*/
$content = str_replace('SINGULAR_NAME', $name, $content);
$content = str_replace('ROUTE_NAME', toCamelCase($name), $content);
$content = str_replace('CAP_NAME', ucfirst($name), $content);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', ucfirst(singularize($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('DB_TABLE_NAME', $table_name, $content);
$content = str_replace('THIS_TABLE_NAME', $name, $content);
$content = str_replace('COLUMNS', $cols, $content);
......@@ -787,15 +793,21 @@ PHPCODE;
$relation_content = str_replace('THIS_REQUEST', $_SERVER['PHP_SELF'], $relation_content);
// @todo !! to CamelCase
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$relation_content = str_replace('REFERENCED_MODEL', ucfirst(singularize($referenced_table)), $relation_content);
$relation_content = str_replace('REFERENCED_TABLE_SINGULAR_NAME', singularize($referenced_table), $relation_content);
*/
$relation_content = str_replace('REFERENCED_MODEL', ucfirst($referenced_table), $relation_content);
$relation_content = str_replace('REFERENCED_TABLE_SINGULAR_NAME', $referenced_table, $relation_content);
$relation_content = str_replace('REFERENCED_TABLE_NAME', toCamelCase($referenced_table), $relation_content);
$relation_content = str_replace('THIS_TABLE_NAME', toCamelCase($table_name), $relation_content);
$relations .= "\n\t" . $relation_content;
$relation_content2 = $relation_stub2;
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$relation_content2 = str_replace('REFERENCED_TABLE_SINGULAR_NAME', singularize($referenced_table), $relation_content2);
*/
$relation_content2 = str_replace('REFERENCED_TABLE_SINGULAR_NAME', $referenced_table, $relation_content2);
$relations2 .= "\n\t" . $relation_content2;
}
$related_tables = str_replace(" ", ", ", trim($related_tables));
......
......@@ -128,7 +128,10 @@ COMMAND;
foreach ($foreignKeys as $fk) {
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$modelName = ucfirst(singularize(explode("_", $fk['foreign_key'])[0]));
*/
$modelName = ucfirst(explode("_", $fk['foreign_key'])[0]);
$modelTableName = $fk['referenced_table'];
if ($modelName == "User") {
......
......@@ -218,7 +218,10 @@ if (substr($name, 0, 3) != "Gdm") {
PHPCODE;
$content = str_replace('CNAME', ucfirst($name), $content);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('NAME', $name, $content);
$content = str_replace('COLUMNS', $cols, $content);
$content = str_replace('GDM_PAGE_LENGTH', GDM_PAGE_LENGTH, $content);
......@@ -421,7 +424,10 @@ PHPCODE;
PHPCODE;
$content = str_replace('CNAME', ucfirst($name), $content);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('NAME', $name, $content);
$content = str_replace('COLUMNS', $cols, $content);
$content = str_replace('GDM_PAGE_LENGTH', GDM_PAGE_LENGTH, $content);
......@@ -527,7 +533,10 @@ PHPCODE;
PHP_CODE;
$content = str_replace('CNAME', ucfirst($name), $content);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('NAME', $name, $content);
@mkdir("../../resources/views/data/" . $name);
......@@ -639,7 +648,10 @@ PHPCODE;
$content = str_replace('CNAME', ucfirst($name), $content);
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('NAME', $name, $content);
@mkdir("../../resources/views/data/" . $name);
......@@ -670,7 +682,10 @@ PHPCODE;
@endsection
PHPCODE;
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('NAME', $name, $content);
@mkdir("../../resources/views/data/" . $name);
......@@ -706,7 +721,10 @@ PHPCODE;
@endsection
PHPCODE;
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
$content = str_replace('NAME', $name, $content);
@mkdir("../../resources/views/data/" . $name);
......@@ -762,7 +780,10 @@ PHPCODE;
PHPCODE;
/* Do not change names of tables (e.g. "Species" becomes "Specie" ???)
$content = str_replace('MODEL_NAME', singularize(ucfirst($name)), $content);
*/
$content = str_replace('MODEL_NAME', ucfirst($name), $content);
@mkdir("../../resources/views/data/" . $name);
file_put_contents("../../resources/views/data/" . $name . "/edit.blade.php", $content);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment