Beispiel #1
0
 private function createCrud(adapter\AbstractToken $token)
 {
     foreach (C::config('files') ?: array() as $key => $value) {
         $path = isset($value['path']) ? C::fixslashes($value['path']) : '';
         $content = '';
         $file = $token->replaceToken($value['name']);
         $e = C::ext($file);
         $path || !isset($this->path[$e]) || ($path = $this->path[$e]);
         if (isset($value['template'])) {
             $e = C::ext($value['template']);
             $path || !isset($this->path[$e]) || ($path = $this->path[$e]);
             $content = file_get_contents($this->dir . $value['template']);
         }
         !$path || ($path = $token->replaceToken($path));
         if (isset($value['method'])) {
             $args = array($content);
             $content = method_exists($token, $value['method']) ? call_user_func_array(array($token, $value['method']), $args) : C::call($value['option']['method'], $args);
         } elseif (isset($value['replaceOriginal'])) {
             $content = file_get_contents($this->tar . $path . $value['name']);
         } elseif (isset($value['copyConfig'])) {
             $content = '';
             foreach (C::config($key) as $key2 => $value2) {
                 $content .= $key2 . ' = ' . $value2 . C::eol();
             }
             $content = trim($content);
         }
         $path = $this->tar . $path . $file;
         $content = $token->replaceToken($content);
         if (isset($value['createAtTheEnd'])) {
             $sectionName = $key;
             !isset($value['sectionName']) || ($sectionName = $value['sectionName']);
             !isset($value['sectionUppercase']) || ($sectionName = strtoupper($key));
             $option = array('file' => $path, 'sectionName' => $sectionName, 'method' => $value['createAtTheEnd'], 'replaceOriginal' => isset($value['replaceOriginal']));
             if (isset($value['template']) && !isset($value['noConcat'])) {
                 if (isset($this->final[$key])) {
                     $this->final[$key]['content'] .= C::eol(2) . $content;
                 } else {
                     $this->final[$key] = array('content' => $content) + $option;
                 }
             } else {
                 $this->final[$key] = array('content' => $content) + $option;
             }
         } else {
             $this->write($path, $token->replaceToken($content)) || C::error('Unable to write ' . $path);
         }
     }
 }
Beispiel #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;
 }