From e3bd3c1e66eec5aae220aa5b6520d870f4562205 Mon Sep 17 00:00:00 2001 From: Peter Mueller <4649833+pmalsenz@users.noreply.github.com> Date: Sun, 21 Jul 2019 13:58:23 +0200 Subject: [PATCH 1/4] Modified console.php Modification in line 171 according to issue #95 in the original dev issues list --- console.php | 387 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 console.php diff --git a/console.php b/console.php new file mode 100644 index 00000000..60871031 --- /dev/null +++ b/console.php @@ -0,0 +1,387 @@ + + * Web: http://crud-admin-generator.com + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Doctrine\DBAL\Schema\Table; + +$console = new Application('CRUD Admin Generator command instalation', '1.0'); + +$console + ->register('generate:admin') + ->setDefinition(array()) + ->setDescription("Generate administrator") + ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { + + $getTablesQuery = "SHOW TABLES"; + $getTablesResult = $app['db']->fetchAll($getTablesQuery, array()); + + $_dbTables = array(); + $dbTables = array(); + + foreach($getTablesResult as $getTableResult){ + + $_dbTables[] = reset($getTableResult); + + $dbTables[] = array( + "name" => reset($getTableResult), + "columns" => array() + ); + } + + foreach($dbTables as $dbTableKey => $dbTable){ + $getTableColumnsQuery = "SHOW COLUMNS FROM `" . $dbTable['name'] . "`"; + $getTableColumnsResult = $app['db']->fetchAll($getTableColumnsQuery, array()); + + foreach($getTableColumnsResult as $getTableColumnResult){ + $dbTables[$dbTableKey]['columns'][] = $getTableColumnResult; + } + + } + + $tables = array(); + foreach($dbTables as $dbTable){ + + if(count($dbTable['columns']) <= 1){ + continue; + } + + $table_name = $dbTable['name']; + $table_columns = array(); + $primary_key = false; + + $primary_keys = 0; + $primary_keys_auto = 0; + foreach($dbTable['columns'] as $column){ + if($column['Key'] == "PRI"){ + $primary_keys++; + } + if($column['Extra'] == "auto_increment"){ + $primary_keys_auto++; + } + } + + if($primary_keys === 1 || ($primary_keys > 1 && $primary_keys_auto === 1)){ + + foreach($dbTable['columns'] as $column){ + + $external_table = false; + + if($primary_keys > 1 && $primary_keys_auto == 1){ + if($column['Extra'] == "auto_increment"){ + $primary_key = $column['Field']; + } + } + else if($primary_keys == 1){ + if($column['Key'] == "PRI"){ + $primary_key = $column['Field']; + } + } + else{ + continue 2; + } + + if(substr($column['Field'], -3) == "_id"){ + $_table_name = substr($column['Field'], 0, -3); + + if(in_array($_table_name, $_dbTables)){ + $external_table = $_table_name; + } + } + + $table_columns[] = array( + "name" => $column['Field'], + "primary" => $column['Field'] == $primary_key ? true : false, + "nullable" => $column['Null'] == "NO" ? true : false, + "auto" => $column['Extra'] == "auto_increment" ? true : false, + "external" => $column['Field'] != $primary_key ? $external_table : false, + "type" => $column['Type'] + ); + } + + } + else{ + continue; + } + + + $tables[$table_name] = array( + "primary_key" => $primary_key, + "columns" => $table_columns + ); + + } + + $MENU_OPTIONS = ""; + $BASE_INCLUDES = ""; + + foreach($tables as $table_name => $table){ + + $table_columns = $table['columns']; + + $TABLENAME = $table_name; + $TABLE_PRIMARYKEY = $table['primary_key']; + + $TABLECOLUMNS_ARRAY = ""; + $TABLECOLUMNS_TYPE_ARRAY = ""; + $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY = ""; + $TABLECOLUMNS_INITIALDATA_ARRAY = ""; + + $EXTERNALS_FOR_LIST = ""; + $EXTERNALSFIELDS_FOR_FORM = ""; + $FIELDS_FOR_FORM = ""; + + $INSERT_QUERY_FIELDS = array(); + $INSERT_EXECUTE_FIELDS = array(); + $UPDATE_QUERY_FIELDS = array(); + $UPDATE_EXECUTE_FIELDS = array(); + + $EDIT_FORM_TEMPLATE = ""; + + $MENU_OPTIONS .= "" . + "
  • " . "\n" . + " " . "\n" . + " " . "\n" . + " " . $TABLENAME . "" . "\n" . + " " . "\n" . + " " . "\n" . + " " . "\n" . + "
  • " . "\n\n"; + + $BASE_INCLUDES .= "require_once __DIR__.'/" . $TABLENAME . "/index.php';" . "\n"; + + $count_externals = 0; + foreach($table_columns as $table_column){ + $TABLECOLUMNS_ARRAY .= "\t\t" . "'". $table_column['name'] . "', \n"; + //$TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". $table_column['type'] . "', \n"; + $TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". addslashes($table_column['type']) . "', \n"; + if(!$table_column['primary'] || ($table_column['primary'] && !$table_column['auto'])){ + $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY .= "\t\t" . "'". $table_column['name'] . "' => '', \n"; + $TABLECOLUMNS_INITIALDATA_ARRAY .= "\t\t" . "'". $table_column['name'] . "' => \$row_sql['".$table_column['name']."'], \n"; + + $INSERT_QUERY_FIELDS[] = "`" . $table_column['name'] . "`"; + $INSERT_EXECUTE_FIELDS[] = "\$data['" . $table_column['name'] . "']"; + $UPDATE_QUERY_FIELDS[] = "`" . $table_column['name'] . "` = ?"; + $UPDATE_EXECUTE_FIELDS[] = "\$data['" . $table_column['name'] . "']"; + + if(strpos($table_column['type'], 'text') !== false){ + $EDIT_FORM_TEMPLATE .= "" . + "\t\t\t\t\t\t\t\t\t" . "
    " . "\n" . + "\t\t\t\t\t\t\t\t\t" . " {{ form_label(form." . $table_column['name'] . ") }}" . "\n" . + "\t\t\t\t\t\t\t\t\t" . " {{ form_widget(form." . $table_column['name'] . ", { attr: { 'class': 'form-control textarea', 'style': 'width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;' }}) }}" . "\n" . + "\t\t\t\t\t\t\t\t\t" . "
    " . "\n\n"; + } + else { + $EDIT_FORM_TEMPLATE .= "" . + "\t\t\t\t\t\t\t\t\t" . "
    " . "\n" . + "\t\t\t\t\t\t\t\t\t" . " {{ form_label(form." . $table_column['name'] . ") }}" . "\n" . + "\t\t\t\t\t\t\t\t\t" . " {{ form_widget(form." . $table_column['name'] . ", { attr: { 'class': 'form-control' }}) }}" . "\n" . + "\t\t\t\t\t\t\t\t\t" . "
    " . "\n\n"; + } + } + + $field_nullable = $table_column['nullable'] ? "true" : "false"; + + if($table_column['external']){ + $external_table = $tables[$table_column['external']]; + + $external_primary_key = $external_table['primary_key']; + $external_select_field = false; + $search_names_foreigner_key = array('name','title','e?mail','username'); + + if(!empty($app['usr_search_names_foreigner_key'])){ + $search_names_foreigner_key = array_merge( + $app['usr_search_names_foreigner_key'], + $search_names_foreigner_key); + } + + // pattern to match a name column, with or whitout a 3 to 4 Char prefix + $search_names_foreigner_key = '#^(.{3,4}_)?('.implode('|',$search_names_foreigner_key).')$#i'; + + foreach($external_table['columns'] as $external_column){ + if( preg_match($search_names_foreigner_key, $external_column['name'])){ + $external_select_field = $external_column['name']; + } + } + + if(!$external_select_field){ + $external_select_field = $external_primary_key; + } + + $external_cond = $count_externals > 0 ? "else if" : "if"; + + $EXTERNALS_FOR_LIST .= "" . + "\t\t\t" . $external_cond . "(\$table_columns[\$i] == '" . $table_column['name'] . "'){" . "\n" . + "\t\t\t" . " \$findexternal_sql = 'SELECT `" . $external_select_field . "` FROM `" . $table_column['external'] . "` WHERE `" . $external_primary_key . "` = ?';" . "\n" . + "\t\t\t" . " \$findexternal_row = \$app['db']->fetchAssoc(\$findexternal_sql, array(\$row_sql[\$table_columns[\$i]]));" . "\n" . + "\t\t\t" . " \$rows[\$row_key][\$table_columns[\$i]] = \$findexternal_row['" . $external_select_field . "'];" . "\n" . + "\t\t\t" . "}" . "\n"; + + + $EXTERNALSFIELDS_FOR_FORM .= "" . + "\t" . "\$options = array();" . "\n" . + "\t" . "\$findexternal_sql = 'SELECT `" . $external_primary_key . "`, `" . $external_select_field . "` FROM `" . $table_column['external'] . "`';" . "\n" . + "\t" . "\$findexternal_rows = \$app['db']->fetchAll(\$findexternal_sql, array());" . "\n" . + "\t" . "foreach(\$findexternal_rows as \$findexternal_row){" . "\n" . + "\t" . " \$options[\$findexternal_row['" . $external_primary_key . "']] = \$findexternal_row['" . $external_select_field . "'];" . "\n" . + "\t" . "}" . "\n" . + "\t" . "if(count(\$options) > 0){" . "\n" . + "\t" . " \$form = \$form->add('" . $table_column['name'] . "', 'choice', array(" . "\n" . + "\t" . " 'required' => " . $field_nullable . "," . "\n" . + "\t" . " 'choices' => \$options," . "\n" . + "\t" . " 'expanded' => false," . "\n" . + "\t" . " 'constraints' => new Assert\Choice(array_keys(\$options))" . "\n" . + "\t" . " ));" . "\n" . + "\t" . "}" . "\n" . + "\t" . "else{" . "\n" . + "\t" . " \$form = \$form->add('" . $table_column['name'] . "', 'text', array('required' => " . $field_nullable . "));" . "\n" . + "\t" . "}" . "\n\n"; + + $count_externals++; + } + else{ + if(!$table_column['primary']){ + + if(strpos($table_column['type'], 'text') !== false){ + $FIELDS_FOR_FORM .= "" . + "\t" . "\$form = \$form->add('" . $table_column['name'] . "', 'textarea', array('required' => " . $field_nullable . "));" . "\n"; + } + else{ + $FIELDS_FOR_FORM .= "" . + "\t" . "\$form = \$form->add('" . $table_column['name'] . "', 'text', array('required' => " . $field_nullable . "));" . "\n"; + } + } + else if($table_column['primary'] && !$table_column['auto']){ + $FIELDS_FOR_FORM .= "" . + "\t" . "\$form = \$form->add('" . $table_column['name'] . "', 'text', array('required' => " . $field_nullable . "));" . "\n"; + } + } + } + + if($count_externals > 0){ + $EXTERNALS_FOR_LIST .= "" . + "\t\t\t" . "else{" . "\n" . + "\t\t\t" . " \$rows[\$row_key][\$table_columns[\$i]] = \$row_sql[\$table_columns[\$i]];" . "\n" . + "\t\t\t" . "}" . "\n"; + } + + if($EXTERNALS_FOR_LIST == ""){ + $EXTERNALS_FOR_LIST .= "" . + "\t\t" . "if( \$table_columns_type[\$i] != \"blob\") {" . "\n" . + "\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] = \$row_sql[\$table_columns[\$i]];" . "\n" . + "\t\t" . "} else {" . + + "\t\t\t\t" . "if( !\$row_sql[\$table_columns[\$i]] ) {" . "\n" . + "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] = \"0 Kb.\";" . "\n" . + "\t\t\t\t" . "} else {" . "\n" . + + "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] = \" \";" . "\n" . + "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] .= number_format(strlen(\$row_sql[\$table_columns[\$i]]) / 1024, 2) . \" Kb.\";" . "\n" . + "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] .= \"\";" . "\n" . + + "\t\t\t\t" . "}" . "\n" . + + "\t\t" . "}"; + } + + + $INSERT_QUERY_VALUES = array(); + foreach($INSERT_QUERY_FIELDS as $INSERT_QUERY_FIELD){ + $INSERT_QUERY_VALUES[] = "?"; + } + $INSERT_QUERY_VALUES = implode(", ", $INSERT_QUERY_VALUES); + $INSERT_QUERY_FIELDS = implode(", ", $INSERT_QUERY_FIELDS); + $INSERT_EXECUTE_FIELDS = implode(", ", $INSERT_EXECUTE_FIELDS); + + $UPDATE_QUERY_FIELDS = implode(", ", $UPDATE_QUERY_FIELDS); + $UPDATE_EXECUTE_FIELDS = implode(", ", $UPDATE_EXECUTE_FIELDS); + + $_controller = file_get_contents(__DIR__.'/../gen/controller.php'); + $_controller = str_replace("__TABLENAME__", $TABLENAME, $_controller); + $_controller = str_replace("__TABLE_PRIMARYKEY__", $TABLE_PRIMARYKEY, $_controller); + $_controller = str_replace("__TABLECOLUMNS_ARRAY__", $TABLECOLUMNS_ARRAY, $_controller); + $_controller = str_replace("__TABLECOLUMNS_TYPE_ARRAY__", $TABLECOLUMNS_TYPE_ARRAY, $_controller); + $_controller = str_replace("__TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY__", $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY, $_controller); + $_controller = str_replace("__TABLECOLUMNS_INITIALDATA_ARRAY__", $TABLECOLUMNS_INITIALDATA_ARRAY, $_controller); + $_controller = str_replace("__EXTERNALS_FOR_LIST__", $EXTERNALS_FOR_LIST, $_controller); + $_controller = str_replace("__EXTERNALSFIELDS_FOR_FORM__", $EXTERNALSFIELDS_FOR_FORM, $_controller); + $_controller = str_replace("__FIELDS_FOR_FORM__", $FIELDS_FOR_FORM, $_controller); + + $_controller = str_replace("__INSERT_QUERY_FIELDS__", $INSERT_QUERY_FIELDS, $_controller); + $_controller = str_replace("__INSERT_QUERY_VALUES__", $INSERT_QUERY_VALUES, $_controller); + $_controller = str_replace("__INSERT_EXECUTE_FIELDS__", $INSERT_EXECUTE_FIELDS, $_controller); + + $_controller = str_replace("__UPDATE_QUERY_FIELDS__", $UPDATE_QUERY_FIELDS, $_controller); + $_controller = str_replace("__UPDATE_EXECUTE_FIELDS__", $UPDATE_EXECUTE_FIELDS, $_controller); + + + $_list_template = file_get_contents(__DIR__.'/../gen/list.html.twig'); + $_list_template = str_replace("__TABLENAME__", $TABLENAME, $_list_template); + $_list_template = str_replace("__TABLENAMEUP__", ucfirst(strtolower($TABLENAME)), $_list_template); + + $_create_template = file_get_contents(__DIR__.'/../gen/create.html.twig'); + $_create_template = str_replace("__TABLENAME__", $TABLENAME, $_create_template); + $_create_template = str_replace("__TABLENAMEUP__", ucfirst(strtolower($TABLENAME)), $_create_template); + $_create_template = str_replace("__EDIT_FORM_TEMPLATE__", $EDIT_FORM_TEMPLATE, $_create_template); + + $_edit_template = file_get_contents(__DIR__.'/../gen/edit.html.twig'); + $_edit_template = str_replace("__TABLENAME__", $TABLENAME, $_edit_template); + $_edit_template = str_replace("__TABLENAMEUP__", ucfirst(strtolower($TABLENAME)), $_edit_template); + $_edit_template = str_replace("__EDIT_FORM_TEMPLATE__", $EDIT_FORM_TEMPLATE, $_edit_template); + + $_menu_template = file_get_contents(__DIR__.'/../gen/menu.html.twig'); + $_menu_template = str_replace("__MENU_OPTIONS__", $MENU_OPTIONS, $_menu_template); + + $_base_file = file_get_contents(__DIR__.'/../gen/base.php'); + $_base_file = str_replace("__BASE_INCLUDES__", $BASE_INCLUDES, $_base_file); + + @mkdir(__DIR__."/../web/controllers/".$TABLENAME, 0755); + @mkdir(__DIR__."/../web/views/".$TABLENAME, 0755); + + $fp = fopen(__DIR__."/../web/controllers/".$TABLENAME."/index.php", "w+"); + fwrite($fp, $_controller); + fclose($fp); + + $fp = fopen(__DIR__."/../web/views/".$TABLENAME."/create.html.twig", "w+"); + fwrite($fp, $_create_template); + fclose($fp); + + $fp = fopen(__DIR__."/../web/views/".$TABLENAME."/edit.html.twig", "w+"); + fwrite($fp, $_edit_template); + fclose($fp); + + $fp = fopen(__DIR__."/../web/views/".$TABLENAME."/list.html.twig", "w+"); + fwrite($fp, $_list_template); + fclose($fp); + + $fp = fopen(__DIR__."/../web/controllers/base.php", "w+"); + fwrite($fp, $_base_file); + fclose($fp); + + $fp = fopen(__DIR__."/../web/views/menu.html.twig", "w+"); + fwrite($fp, $_menu_template); + fclose($fp); + + } + +}); + +return $console; From 41a1a3eaa74a3051618db775ce5f422169a24caa Mon Sep 17 00:00:00 2001 From: Peter Mueller <4649833+pmalsenz@users.noreply.github.com> Date: Sun, 21 Jul 2019 13:58:51 +0200 Subject: [PATCH 2/4] Wrong place to commit --- console.php | 387 ---------------------------------------------------- 1 file changed, 387 deletions(-) delete mode 100644 console.php diff --git a/console.php b/console.php deleted file mode 100644 index 60871031..00000000 --- a/console.php +++ /dev/null @@ -1,387 +0,0 @@ - - * Web: http://crud-admin-generator.com - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Component\Console\Application; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Doctrine\DBAL\Schema\Table; - -$console = new Application('CRUD Admin Generator command instalation', '1.0'); - -$console - ->register('generate:admin') - ->setDefinition(array()) - ->setDescription("Generate administrator") - ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { - - $getTablesQuery = "SHOW TABLES"; - $getTablesResult = $app['db']->fetchAll($getTablesQuery, array()); - - $_dbTables = array(); - $dbTables = array(); - - foreach($getTablesResult as $getTableResult){ - - $_dbTables[] = reset($getTableResult); - - $dbTables[] = array( - "name" => reset($getTableResult), - "columns" => array() - ); - } - - foreach($dbTables as $dbTableKey => $dbTable){ - $getTableColumnsQuery = "SHOW COLUMNS FROM `" . $dbTable['name'] . "`"; - $getTableColumnsResult = $app['db']->fetchAll($getTableColumnsQuery, array()); - - foreach($getTableColumnsResult as $getTableColumnResult){ - $dbTables[$dbTableKey]['columns'][] = $getTableColumnResult; - } - - } - - $tables = array(); - foreach($dbTables as $dbTable){ - - if(count($dbTable['columns']) <= 1){ - continue; - } - - $table_name = $dbTable['name']; - $table_columns = array(); - $primary_key = false; - - $primary_keys = 0; - $primary_keys_auto = 0; - foreach($dbTable['columns'] as $column){ - if($column['Key'] == "PRI"){ - $primary_keys++; - } - if($column['Extra'] == "auto_increment"){ - $primary_keys_auto++; - } - } - - if($primary_keys === 1 || ($primary_keys > 1 && $primary_keys_auto === 1)){ - - foreach($dbTable['columns'] as $column){ - - $external_table = false; - - if($primary_keys > 1 && $primary_keys_auto == 1){ - if($column['Extra'] == "auto_increment"){ - $primary_key = $column['Field']; - } - } - else if($primary_keys == 1){ - if($column['Key'] == "PRI"){ - $primary_key = $column['Field']; - } - } - else{ - continue 2; - } - - if(substr($column['Field'], -3) == "_id"){ - $_table_name = substr($column['Field'], 0, -3); - - if(in_array($_table_name, $_dbTables)){ - $external_table = $_table_name; - } - } - - $table_columns[] = array( - "name" => $column['Field'], - "primary" => $column['Field'] == $primary_key ? true : false, - "nullable" => $column['Null'] == "NO" ? true : false, - "auto" => $column['Extra'] == "auto_increment" ? true : false, - "external" => $column['Field'] != $primary_key ? $external_table : false, - "type" => $column['Type'] - ); - } - - } - else{ - continue; - } - - - $tables[$table_name] = array( - "primary_key" => $primary_key, - "columns" => $table_columns - ); - - } - - $MENU_OPTIONS = ""; - $BASE_INCLUDES = ""; - - foreach($tables as $table_name => $table){ - - $table_columns = $table['columns']; - - $TABLENAME = $table_name; - $TABLE_PRIMARYKEY = $table['primary_key']; - - $TABLECOLUMNS_ARRAY = ""; - $TABLECOLUMNS_TYPE_ARRAY = ""; - $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY = ""; - $TABLECOLUMNS_INITIALDATA_ARRAY = ""; - - $EXTERNALS_FOR_LIST = ""; - $EXTERNALSFIELDS_FOR_FORM = ""; - $FIELDS_FOR_FORM = ""; - - $INSERT_QUERY_FIELDS = array(); - $INSERT_EXECUTE_FIELDS = array(); - $UPDATE_QUERY_FIELDS = array(); - $UPDATE_EXECUTE_FIELDS = array(); - - $EDIT_FORM_TEMPLATE = ""; - - $MENU_OPTIONS .= "" . - "
  • " . "\n" . - " " . "\n" . - " " . "\n" . - " " . $TABLENAME . "" . "\n" . - " " . "\n" . - " " . "\n" . - " " . "\n" . - "
  • " . "\n\n"; - - $BASE_INCLUDES .= "require_once __DIR__.'/" . $TABLENAME . "/index.php';" . "\n"; - - $count_externals = 0; - foreach($table_columns as $table_column){ - $TABLECOLUMNS_ARRAY .= "\t\t" . "'". $table_column['name'] . "', \n"; - //$TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". $table_column['type'] . "', \n"; - $TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". addslashes($table_column['type']) . "', \n"; - if(!$table_column['primary'] || ($table_column['primary'] && !$table_column['auto'])){ - $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY .= "\t\t" . "'". $table_column['name'] . "' => '', \n"; - $TABLECOLUMNS_INITIALDATA_ARRAY .= "\t\t" . "'". $table_column['name'] . "' => \$row_sql['".$table_column['name']."'], \n"; - - $INSERT_QUERY_FIELDS[] = "`" . $table_column['name'] . "`"; - $INSERT_EXECUTE_FIELDS[] = "\$data['" . $table_column['name'] . "']"; - $UPDATE_QUERY_FIELDS[] = "`" . $table_column['name'] . "` = ?"; - $UPDATE_EXECUTE_FIELDS[] = "\$data['" . $table_column['name'] . "']"; - - if(strpos($table_column['type'], 'text') !== false){ - $EDIT_FORM_TEMPLATE .= "" . - "\t\t\t\t\t\t\t\t\t" . "
    " . "\n" . - "\t\t\t\t\t\t\t\t\t" . " {{ form_label(form." . $table_column['name'] . ") }}" . "\n" . - "\t\t\t\t\t\t\t\t\t" . " {{ form_widget(form." . $table_column['name'] . ", { attr: { 'class': 'form-control textarea', 'style': 'width: 100%; height: 200px; font-size: 14px; line-height: 18px; border: 1px solid #dddddd; padding: 10px;' }}) }}" . "\n" . - "\t\t\t\t\t\t\t\t\t" . "
    " . "\n\n"; - } - else { - $EDIT_FORM_TEMPLATE .= "" . - "\t\t\t\t\t\t\t\t\t" . "
    " . "\n" . - "\t\t\t\t\t\t\t\t\t" . " {{ form_label(form." . $table_column['name'] . ") }}" . "\n" . - "\t\t\t\t\t\t\t\t\t" . " {{ form_widget(form." . $table_column['name'] . ", { attr: { 'class': 'form-control' }}) }}" . "\n" . - "\t\t\t\t\t\t\t\t\t" . "
    " . "\n\n"; - } - } - - $field_nullable = $table_column['nullable'] ? "true" : "false"; - - if($table_column['external']){ - $external_table = $tables[$table_column['external']]; - - $external_primary_key = $external_table['primary_key']; - $external_select_field = false; - $search_names_foreigner_key = array('name','title','e?mail','username'); - - if(!empty($app['usr_search_names_foreigner_key'])){ - $search_names_foreigner_key = array_merge( - $app['usr_search_names_foreigner_key'], - $search_names_foreigner_key); - } - - // pattern to match a name column, with or whitout a 3 to 4 Char prefix - $search_names_foreigner_key = '#^(.{3,4}_)?('.implode('|',$search_names_foreigner_key).')$#i'; - - foreach($external_table['columns'] as $external_column){ - if( preg_match($search_names_foreigner_key, $external_column['name'])){ - $external_select_field = $external_column['name']; - } - } - - if(!$external_select_field){ - $external_select_field = $external_primary_key; - } - - $external_cond = $count_externals > 0 ? "else if" : "if"; - - $EXTERNALS_FOR_LIST .= "" . - "\t\t\t" . $external_cond . "(\$table_columns[\$i] == '" . $table_column['name'] . "'){" . "\n" . - "\t\t\t" . " \$findexternal_sql = 'SELECT `" . $external_select_field . "` FROM `" . $table_column['external'] . "` WHERE `" . $external_primary_key . "` = ?';" . "\n" . - "\t\t\t" . " \$findexternal_row = \$app['db']->fetchAssoc(\$findexternal_sql, array(\$row_sql[\$table_columns[\$i]]));" . "\n" . - "\t\t\t" . " \$rows[\$row_key][\$table_columns[\$i]] = \$findexternal_row['" . $external_select_field . "'];" . "\n" . - "\t\t\t" . "}" . "\n"; - - - $EXTERNALSFIELDS_FOR_FORM .= "" . - "\t" . "\$options = array();" . "\n" . - "\t" . "\$findexternal_sql = 'SELECT `" . $external_primary_key . "`, `" . $external_select_field . "` FROM `" . $table_column['external'] . "`';" . "\n" . - "\t" . "\$findexternal_rows = \$app['db']->fetchAll(\$findexternal_sql, array());" . "\n" . - "\t" . "foreach(\$findexternal_rows as \$findexternal_row){" . "\n" . - "\t" . " \$options[\$findexternal_row['" . $external_primary_key . "']] = \$findexternal_row['" . $external_select_field . "'];" . "\n" . - "\t" . "}" . "\n" . - "\t" . "if(count(\$options) > 0){" . "\n" . - "\t" . " \$form = \$form->add('" . $table_column['name'] . "', 'choice', array(" . "\n" . - "\t" . " 'required' => " . $field_nullable . "," . "\n" . - "\t" . " 'choices' => \$options," . "\n" . - "\t" . " 'expanded' => false," . "\n" . - "\t" . " 'constraints' => new Assert\Choice(array_keys(\$options))" . "\n" . - "\t" . " ));" . "\n" . - "\t" . "}" . "\n" . - "\t" . "else{" . "\n" . - "\t" . " \$form = \$form->add('" . $table_column['name'] . "', 'text', array('required' => " . $field_nullable . "));" . "\n" . - "\t" . "}" . "\n\n"; - - $count_externals++; - } - else{ - if(!$table_column['primary']){ - - if(strpos($table_column['type'], 'text') !== false){ - $FIELDS_FOR_FORM .= "" . - "\t" . "\$form = \$form->add('" . $table_column['name'] . "', 'textarea', array('required' => " . $field_nullable . "));" . "\n"; - } - else{ - $FIELDS_FOR_FORM .= "" . - "\t" . "\$form = \$form->add('" . $table_column['name'] . "', 'text', array('required' => " . $field_nullable . "));" . "\n"; - } - } - else if($table_column['primary'] && !$table_column['auto']){ - $FIELDS_FOR_FORM .= "" . - "\t" . "\$form = \$form->add('" . $table_column['name'] . "', 'text', array('required' => " . $field_nullable . "));" . "\n"; - } - } - } - - if($count_externals > 0){ - $EXTERNALS_FOR_LIST .= "" . - "\t\t\t" . "else{" . "\n" . - "\t\t\t" . " \$rows[\$row_key][\$table_columns[\$i]] = \$row_sql[\$table_columns[\$i]];" . "\n" . - "\t\t\t" . "}" . "\n"; - } - - if($EXTERNALS_FOR_LIST == ""){ - $EXTERNALS_FOR_LIST .= "" . - "\t\t" . "if( \$table_columns_type[\$i] != \"blob\") {" . "\n" . - "\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] = \$row_sql[\$table_columns[\$i]];" . "\n" . - "\t\t" . "} else {" . - - "\t\t\t\t" . "if( !\$row_sql[\$table_columns[\$i]] ) {" . "\n" . - "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] = \"0 Kb.\";" . "\n" . - "\t\t\t\t" . "} else {" . "\n" . - - "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] = \" \";" . "\n" . - "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] .= number_format(strlen(\$row_sql[\$table_columns[\$i]]) / 1024, 2) . \" Kb.\";" . "\n" . - "\t\t\t\t\t\t" . "\$rows[\$row_key][\$table_columns[\$i]] .= \"\";" . "\n" . - - "\t\t\t\t" . "}" . "\n" . - - "\t\t" . "}"; - } - - - $INSERT_QUERY_VALUES = array(); - foreach($INSERT_QUERY_FIELDS as $INSERT_QUERY_FIELD){ - $INSERT_QUERY_VALUES[] = "?"; - } - $INSERT_QUERY_VALUES = implode(", ", $INSERT_QUERY_VALUES); - $INSERT_QUERY_FIELDS = implode(", ", $INSERT_QUERY_FIELDS); - $INSERT_EXECUTE_FIELDS = implode(", ", $INSERT_EXECUTE_FIELDS); - - $UPDATE_QUERY_FIELDS = implode(", ", $UPDATE_QUERY_FIELDS); - $UPDATE_EXECUTE_FIELDS = implode(", ", $UPDATE_EXECUTE_FIELDS); - - $_controller = file_get_contents(__DIR__.'/../gen/controller.php'); - $_controller = str_replace("__TABLENAME__", $TABLENAME, $_controller); - $_controller = str_replace("__TABLE_PRIMARYKEY__", $TABLE_PRIMARYKEY, $_controller); - $_controller = str_replace("__TABLECOLUMNS_ARRAY__", $TABLECOLUMNS_ARRAY, $_controller); - $_controller = str_replace("__TABLECOLUMNS_TYPE_ARRAY__", $TABLECOLUMNS_TYPE_ARRAY, $_controller); - $_controller = str_replace("__TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY__", $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY, $_controller); - $_controller = str_replace("__TABLECOLUMNS_INITIALDATA_ARRAY__", $TABLECOLUMNS_INITIALDATA_ARRAY, $_controller); - $_controller = str_replace("__EXTERNALS_FOR_LIST__", $EXTERNALS_FOR_LIST, $_controller); - $_controller = str_replace("__EXTERNALSFIELDS_FOR_FORM__", $EXTERNALSFIELDS_FOR_FORM, $_controller); - $_controller = str_replace("__FIELDS_FOR_FORM__", $FIELDS_FOR_FORM, $_controller); - - $_controller = str_replace("__INSERT_QUERY_FIELDS__", $INSERT_QUERY_FIELDS, $_controller); - $_controller = str_replace("__INSERT_QUERY_VALUES__", $INSERT_QUERY_VALUES, $_controller); - $_controller = str_replace("__INSERT_EXECUTE_FIELDS__", $INSERT_EXECUTE_FIELDS, $_controller); - - $_controller = str_replace("__UPDATE_QUERY_FIELDS__", $UPDATE_QUERY_FIELDS, $_controller); - $_controller = str_replace("__UPDATE_EXECUTE_FIELDS__", $UPDATE_EXECUTE_FIELDS, $_controller); - - - $_list_template = file_get_contents(__DIR__.'/../gen/list.html.twig'); - $_list_template = str_replace("__TABLENAME__", $TABLENAME, $_list_template); - $_list_template = str_replace("__TABLENAMEUP__", ucfirst(strtolower($TABLENAME)), $_list_template); - - $_create_template = file_get_contents(__DIR__.'/../gen/create.html.twig'); - $_create_template = str_replace("__TABLENAME__", $TABLENAME, $_create_template); - $_create_template = str_replace("__TABLENAMEUP__", ucfirst(strtolower($TABLENAME)), $_create_template); - $_create_template = str_replace("__EDIT_FORM_TEMPLATE__", $EDIT_FORM_TEMPLATE, $_create_template); - - $_edit_template = file_get_contents(__DIR__.'/../gen/edit.html.twig'); - $_edit_template = str_replace("__TABLENAME__", $TABLENAME, $_edit_template); - $_edit_template = str_replace("__TABLENAMEUP__", ucfirst(strtolower($TABLENAME)), $_edit_template); - $_edit_template = str_replace("__EDIT_FORM_TEMPLATE__", $EDIT_FORM_TEMPLATE, $_edit_template); - - $_menu_template = file_get_contents(__DIR__.'/../gen/menu.html.twig'); - $_menu_template = str_replace("__MENU_OPTIONS__", $MENU_OPTIONS, $_menu_template); - - $_base_file = file_get_contents(__DIR__.'/../gen/base.php'); - $_base_file = str_replace("__BASE_INCLUDES__", $BASE_INCLUDES, $_base_file); - - @mkdir(__DIR__."/../web/controllers/".$TABLENAME, 0755); - @mkdir(__DIR__."/../web/views/".$TABLENAME, 0755); - - $fp = fopen(__DIR__."/../web/controllers/".$TABLENAME."/index.php", "w+"); - fwrite($fp, $_controller); - fclose($fp); - - $fp = fopen(__DIR__."/../web/views/".$TABLENAME."/create.html.twig", "w+"); - fwrite($fp, $_create_template); - fclose($fp); - - $fp = fopen(__DIR__."/../web/views/".$TABLENAME."/edit.html.twig", "w+"); - fwrite($fp, $_edit_template); - fclose($fp); - - $fp = fopen(__DIR__."/../web/views/".$TABLENAME."/list.html.twig", "w+"); - fwrite($fp, $_list_template); - fclose($fp); - - $fp = fopen(__DIR__."/../web/controllers/base.php", "w+"); - fwrite($fp, $_base_file); - fclose($fp); - - $fp = fopen(__DIR__."/../web/views/menu.html.twig", "w+"); - fwrite($fp, $_menu_template); - fclose($fp); - - } - -}); - -return $console; From 6865f4d8abeab33b03b97a121137c755725f0951 Mon Sep 17 00:00:00 2001 From: Peter Mueller <4649833+pmalsenz@users.noreply.github.com> Date: Sun, 21 Jul 2019 13:59:55 +0200 Subject: [PATCH 3/4] Modified line 171 to work with enum fields Modified line 171 to work with enum fields according to issue #95 in the original developer issues list --- src/console.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/console.php b/src/console.php index b2649e5b..60871031 100644 --- a/src/console.php +++ b/src/console.php @@ -168,7 +168,8 @@ $count_externals = 0; foreach($table_columns as $table_column){ $TABLECOLUMNS_ARRAY .= "\t\t" . "'". $table_column['name'] . "', \n"; - $TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". $table_column['type'] . "', \n"; + //$TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". $table_column['type'] . "', \n"; + $TABLECOLUMNS_TYPE_ARRAY .= "\t\t" . "'". addslashes($table_column['type']) . "', \n"; if(!$table_column['primary'] || ($table_column['primary'] && !$table_column['auto'])){ $TABLECOLUMNS_INITIALDATA_EMPTY_ARRAY .= "\t\t" . "'". $table_column['name'] . "' => '', \n"; $TABLECOLUMNS_INITIALDATA_ARRAY .= "\t\t" . "'". $table_column['name'] . "' => \$row_sql['".$table_column['name']."'], \n"; From c77433d926158a6c9652f6a1ee3e8c5d22da6672 Mon Sep 17 00:00:00 2001 From: Peter Mueller <4649833+pmalsenz@users.noreply.github.com> Date: Sun, 21 Jul 2019 14:08:53 +0200 Subject: [PATCH 4/4] Update README.md Modified VirtualHosts to match Apache 2.x Require and added a simple Lighttpd VirtaulHost --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1192b4b0..632362df 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,16 @@ Install vendors: You need point the document root of your virtual host to /path_to/admingenerator/web -This is an example of VirtualHost: +These are examples for VirtualHosts + +Apache 2.x: DocumentRoot /path_to/admingenerator/web DirectoryIndex index.php Options Indexes FollowSymLinks - Order Allow,Deny - Allow from all + Require alle granted AllowOverride all php_admin_flag engine on @@ -50,6 +51,13 @@ This is an example of VirtualHost: +Lighttpd (a simple one, running with php-fpm on a pi-hole server): + + $HTTP["host"] == "myhostname.example.com" { + server.document-root = "/path_to/admingenerator/web/" + url.access-allow = ( "" ) + } + You can customize the url using the .htaccess file, maybe this will help you: [http://stackoverflow.com/questions/24952846/how-do-i-remove-the-web-from-my-url/24953439#24953439](http://stackoverflow.com/questions/24952846/how-do-i-remove-the-web-from-my-url/24953439#24953439)