Example #1
0
 public function __construct(Table $table)
 {
     $this->table = $table;
     foreach ($this->default as $key => $value) {
         if (method_exists($this, $method = 'token' . C::camelhead($key))) {
             $this->{$method}();
         }
     }
     foreach (C::config('fixed') as $key => $value) {
         $this->default[$key] = $value;
     }
     foreach (C::config('path') as $key => $value) {
         $path = 'path_' . $key;
         $this->{$path} = C::fixslashes($value);
     }
     $this->run();
 }
Example #2
0
 public function __construct(Table $table)
 {
     parent::__construct($table);
     $eol = C::eol();
     $t = array(2 => C::tab(2, 4), 3 => C::tab(3, 4), 4 => C::tab(4, 4), 22 => C::tab(2, 2), 32 => C::tab(3, 2), 42 => C::tab(4, 2));
     $column_header = $column_select = $pk = $schema = $rel = $fields_form = $namespace_list = $option_list = $date_field = '';
     foreach ($table->column as $key => $column) {
         $column_select .= '{table}.' . $column->Field . ',' . $eol;
         $column_header .= $t[42] . '<th>{{ @fields.' . $column->Field . ' }}</th>' . $eol;
         $fields_form .= $this->form($column) . $eol;
         $schema .= str_replace(array('field', 'label', 'EOL', 'T4', 'T3'), array($column->Field, $column->label, $eol, $t[4], $t[3]), "'field'=>array(EOLT4'label',EOLT4" . $this->filter($column) . "," . 'EOLT4' . $column->defaultContent . "EOLT4),EOLT3");
         if ($column->isReferenced) {
             $namespace_list .= 'use {#model_namespace#}\\' . C::camelhead($column->referencedTable) . ';' . $eol;
             $option_list .= $eol . $t[2] . '$moe->set(\'' . C::camelcase($column->referencedTable) . '\', ' . C::camelhead($column->referencedTable) . '::instance()->optionList());';
         }
         !$column->isDate || ($date_field .= $t[3] . '$' . $column->Field . ' = $moe->get(\'POST.' . $column->Field . '\');' . $eol . $t[3] . 'krsort($' . $column->Field . ');' . $eol . $t[3] . '$moe->set(\'POST.' . $column->Field . '\', implode(\'-\', $' . $column->Field . '));' . $eol);
         !$column->isPrimaryKey() || ($pk .= "'{$column->Field}', ");
     }
     if ($table->relation) {
         $this->use_relation = $eol . $t[3] . '->useRelation(\'all\')';
         $db = C::get('db');
         foreach ($table->relation as $rel) {
             foreach ($db->table[$rel['table']]->column as $column) {
                 $tname = $db->table[$rel['table']]->name;
                 $column_select .= $tname . '.' . $column->Field . ' as ' . $tname . '_' . $column->Field . ',' . $eol;
                 $column_header .= $t[42] . '<th>' . $column->label . '</th>' . $eol;
             }
         }
         $db = null;
         unset($db);
     }
     $this->controller = 'Crud' . $table->model;
     $this->model = $table->model;
     $this->table_name = $table->name;
     $this->label = $table->label;
     $this->column_header = trim($column_header);
     $this->namespace_list = ltrim($namespace_list);
     $this->option_list = rtrim($option_list);
     $this->fields_form = ltrim($fields_form);
     $this->date_field = ltrim($date_field);
     $this->column_select = trim($column_select, ',' . $eol);
     $this->schema = rtrim($schema);
     $this->pk = trim($pk, ' ,');
     $this->primary_key = reset($table->primary_key);
     foreach ($table->relation as $fil1 => $tab) {
         $this->rel .= str_replace(array('{tab}', '{fil1}', '{fil2}', '{EOL}', '{S3}'), array($tab['table'], $fil1, $tab['field'], $eol, $t[3]), "'{tab}'=>'join {join} on {join}.{fil2} = {table}.{fil1}',{EOL}{S3}");
     }
     $this->rel = trim($this->rel);
     foreach (C::config('namespaces') ?: array() as $key => $value) {
         $key2 = $key . '_quoted';
         $this->{$key} = $this->replaceToken($value);
         $this->{$key2} = addslashes($this->{$key});
     }
     $cff = array();
     foreach (C::config('files') ?: array() as $key => $value) {
         C::ext($value['name']) !== 'ini' || array_push($cff, C::name($this->replaceToken($value['name'])));
     }
     ksort($cff);
     $this->config_files = "'" . implode("'," . C::eol() . C::tab(1, 4) . "'", $cff) . "'";
     $this->table = $table;
 }