示例#1
0
 public static function page_entities()
 {
     $block = new HTML\HTMLLongTag('div');
     $form = new HTML\HTMLForm();
     $block->add_content($form);
     $form->set_id('tables-form');
     $form->action = '';
     $form->method = 'post';
     $form->add_content('<style type="text/css">#tables-form legend {font-weight: bold; border-bottom: solid 1px #333; } #tables-form div.table { border-bottom: solid 1px #CCC; padding: 0 0 20px 0; } #tables-form div.table input.text{ border: solid 1px #999; padding: 4px 3px; }</style>');
     $form->add_content('<style type="text/css">#tables-form .action .row { padding: 10px 20px; } </style>');
     $form->add_content('<style type="text/css">#tables-form .form-buttons { padding: 30px 0px; margin: 30px 0 0 0; border-top: solid 1px #444; text-align: right; background: #DDD; } #tables-form .form-buttons  button { margin: 0 40px 0 0; padding: 5px 30px; border: solid 1px #999;} </style>');
     $tables = \DB::select(\DB::raw('SHOW TABLES'));
     $form->open_fieldset('tables');
     $legend_buttons = new HTML\HTMLLongTag('div');
     $legend_buttons->add_style('float', 'right');
     $legend_buttons->add_style('font-size', '10pt');
     $check_all_button = new HTML\HTMLLongTag('a');
     $check_all_button->set_content('Check All');
     $check_all_button->href = 'javascript:void(0)';
     $check_all_button->onclick = "\$('.tables .checkbox').not(':checked').click()";
     $legend_buttons->add_content($check_all_button);
     $legend_buttons->add_content(' &nbsp; / &nbsp; ');
     $check_all_button = new HTML\HTMLLongTag('a');
     $check_all_button->set_content('Uncheck All');
     $check_all_button->href = 'javascript:void(0)';
     $check_all_button->onclick = "\$('.tables .checkbox').filter(':checked').click()";
     $legend_buttons->add_content($check_all_button);
     $form->add_legend('Tables' . $legend_buttons);
     foreach ($tables as $table) {
         $table_name = '';
         foreach ($table as $str) {
             $table_name = $str;
             break;
         }
         if (!in_array($table_name, self::$_PROTECTED_TABLES)) {
             $table_paths = self::_get_table_paths($table_name);
             $table_entity_name = $table_paths['entity']['name'];
             $table_repository_name = $table_paths['repository']['name'];
             $table_repository_database_name = $table_paths['repository_database']['name'];
             $entities_dir = self::_get_entities_dir();
             $dir = opendir($entities_dir);
             while ($phppath = readdir($dir)) {
                 if ($phppath != '.' && $phppath != '..') {
                     $phppath = $entities_dir . DIRECTORY_SEPARATOR . $phppath;
                     $phpcontents = file_get_contents($phppath);
                     if (preg_match('#(?i)protected\\s+\\$table\\s+\\=\\s+(\'|")(?P<table>.+?)(\'|\\")#', $phpcontents, $match)) {
                         if ($match['table'] == $table_name) {
                             if (preg_match('#(?i)class\\s+(?P<classname>.+?)\\s+#', $phpcontents, $match)) {
                                 $table_entity_name = $match['classname'];
                                 break;
                             }
                         }
                     }
                 }
             }
             closedir($dir);
             $repositories_dir = self::_get_repositories_dir();
             $dir = opendir($repositories_dir);
             while ($phppath = readdir($dir)) {
                 if ($phppath != '.' && $phppath != '..') {
                     $phppath = $repositories_dir . DIRECTORY_SEPARATOR . $phppath;
                     $phpcontents = file_get_contents($phppath);
                     if (preg_match('#(?i)const\\s+TABLE_NAME\\s+\\=\\s+(\'|")(?P<table>.+?)(\'|\\")#', $phpcontents, $match)) {
                         if ($match['table'] == $table_name) {
                             if (preg_match('#(?i)interface\\s+(?P<classname>.+?)\\s+#', $phpcontents, $match)) {
                                 $table_repository_name = $match['classname'];
                                 break;
                             }
                         }
                     }
                 }
             }
             closedir($dir);
             $repositories_database_dir = self::_get_repositories_database_dir();
             $dir = opendir($repositories_database_dir);
             while ($phppath = readdir($dir)) {
                 if ($phppath != '.' && $phppath != '..') {
                     $phppath = $repositories_database_dir . DIRECTORY_SEPARATOR . $phppath;
                     $phpcontents = file_get_contents($phppath);
                     if (preg_match('#(?i)class\\s+(?P<classname>.+?)\\s+extends\\s+.*?\\s+implements\\s+.*?\\\\' . preg_quote($table_repository_name) . '#', $phpcontents, $match)) {
                         $table_repository_database_name = $match['classname'];
                         break;
                     }
                 }
             }
             closedir($dir);
             $form->open_row('table');
             $checkbox = new HTML\HTMLInputCheckboxControl('tables[' . $table_name . ']', $table_name);
             $checkbox->get_label()->add_style('display', 'inline')->add_style('margin', '-3px 0 5px 10px')->add_style('vertical-align', 'top')->add_style('cursor', 'pointer');
             $checkbox->add_style('display', 'inline');
             $checkbox->onclick = "\$(" . JSHelper::cast_str('.table-' . $table_name) . ").attr({'disabled':!\$(this).is(':checked')});";
             $form->open_col_md(3);
             $form->add_content($checkbox);
             $text = new HTML\HTMLInputTextControl('tables[' . $table_name . '][entity]', $table_name, $table_entity_name);
             $text->set_show_label(false);
             $text->add_style('width', '100%');
             $text->add_class('table-' . $table_name);
             $text->disabled = true;
             $form->open_col_md(3);
             $form->add_content($text);
             $text = new HTML\HTMLInputTextControl('tables[' . $table_name . '][repository]', $table_name, $table_repository_name);
             $text->set_show_label(false);
             $text->add_style('width', '100%');
             $text->add_class('table-' . $table_name);
             $text->disabled = true;
             $form->open_col_md(3);
             $form->add_content($text);
             $text = new HTML\HTMLInputTextControl('tables[' . $table_name . '][repository_database]', $table_name, $table_repository_database_name);
             $text->set_show_label(false);
             $text->add_style('width', '100%');
             $text->add_class('table-' . $table_name);
             $text->disabled = true;
             $form->open_col_md(3);
             $form->add_content($text);
             $form->close_row();
         }
     }
     $form->open_fieldset('action');
     $form->add_legend('Action');
     $form->open_row();
     $checkbox = new HTML\HTMLInputRadioControl('action', 'Create Entities & Servicies', 'create');
     $checkbox->get_label()->add_style('display', 'inline')->add_style('margin', '-3px 0 5px 10px')->add_style('vertical-align', 'top')->add_style('cursor', 'pointer');
     $checkbox->add_style('display', 'inline');
     $checkbox->set_checked(true);
     $form->add_content($checkbox);
     $form->open_row();
     $checkbox = new HTML\HTMLInputRadioControl('action', 'Delete Tables', 'delete');
     $checkbox->get_label()->add_style('display', 'inline')->add_style('margin', '-3px 0 5px 10px')->add_style('vertical-align', 'top')->add_style('cursor', 'pointer');
     $checkbox->add_style('display', 'inline');
     $form->add_content($checkbox);
     $form->add_submit_cancel_buttons();
     $form->set_cancel_action('location.href = "' . \URL::route(self::URL_INDEX) . '";');
     return self::_prepare_page_html($block, 'Database Tables', \URL::route(self::URL_INDEX));
 }