コード例 #1
0
ファイル: MknyModelconfig.php プロジェクト: mkny/cinimod
 /**
  * Monta o template do configurador de model (var)
  * 
  * @return  array Dados do config
  */
 private function _getModelConfig($table)
 {
     $stubModelConfig = $this->files->get(__DIR__ . '/stubs/model_config_fields.stub');
     // Pega as colunas da tabela do banco
     $AppLogic = new Logic\AppLogic();
     $columns = $AppLogic->buildColumnsWithKeys($table);
     $field_types = $AppLogic->_getFieldTypes();
     $stubs = [];
     foreach ($columns as $indice => $row) {
         // Copia a stub mae
         $stub_child = trim(substr(trim($stubModelConfig), 5)) . "\n\n";
         // Setta as configuracoes
         $arrConfig = array('var_name' => $row->name, 'var_type' => $indice === 0 ? 'primaryKey' : $row->type, 'var_type_laravel' => $indice === 0 ? 'primaryKey' : $field_types[$row->type], 'go_to_grid' => 'true', 'go_to_form_add' => $indice === 0 ? 'false' : 'true', 'go_to_form_edit' => $indice === 0 ? 'false' : 'true', 'is_required' => $row->is_null == 'NO' ? 'true' : 'false', 'var_relationship' => 'false', 'var_values' => 'false', 'num_ordem' => $indice);
         // Trampa nos values pre-definidos
         if (isset($row->def_constraint) && !empty($row->def_constraint)) {
             // var_dump($col->def_constraint);exit;
             $check = $AppLogic->_getCheck($row->def_constraint);
             $arrConfig['var_type_laravel'] = 'select';
             $arrConfig['var_values'] = "['" . implode("','", $check) . "']";
         }
         // Trampa na relacao
         if (isset($this->var_config_relations[$row->name])) {
             $arrConfig['var_type_laravel'] = 'select';
             // variabilizar o relationship
             $arrConfig['var_relationship'] = "\n\t[\n\t\t" . "'model' => '\\App\\Models\\" . $this->var_config_relations[$row->name]['relation_class_name'] . "',\n\t\t" . "'field_key' => '{$this->var_config_relations[$row->name]['relation_field_id']}',\n\t\t" . "'field_fkey' => '{$this->var_config_relations[$row->name]['relation_field_fkey']}',\n\t\t" . "'field_show' => '{$this->var_config_relations[$row->name]['relation_field_name']}',\n\t\t" . "'where' => false,\n\t\t" . "]\n\t";
         }
         // Trampa fim
         // Traduz a stub
         Logic\UtilLogic::translateStub($arrConfig, $stub_child);
         $stubs[] = $stub_child;
     }
     return implode("\n\n", $stubs);
 }
コード例 #2
0
ファイル: MknyModel.php プロジェクト: mkny/cinimod
 /**
  * Funcao para buscar e montar o sistema de relacionamentos do Eloquent
  * 
  * @param string $table Nome da tabela que sera gerada
  * @return string Funcao gerada
  */
 public function _getRelations($table)
 {
     $this->var_config_relations = [];
     $stubModelConfig = $this->files->get(__DIR__ . '/stubs/model_function_relation.stub');
     // Pega os relacionamentos no banco
     $AppLogic = new Logic\AppLogic();
     $relations = $AppLogic->buildRelationships($table);
     // dd($relations);
     $field_types = $AppLogic->_getFieldTypes();
     if ($relations) {
         $stubs = [];
         foreach ($relations as $rel) {
             // Copia a stub mae
             $stub_child = trim(substr(trim($stubModelConfig), 5)) . "\n\n";
             // Tentativa fim
             // Trampo pra pegar a primeira coluna para o possivel nome do campo
             $columns = $AppLogic->buildColumns($rel->table_primary, $rel->schema_primary);
             $field_name = $columns[0]->name;
             foreach ($columns as $column) {
                 if ($field_types[$column->type] == 'string') {
                     $field_name = $column->name;
                     break;
                 }
             }
             // Setta as configuracoes
             $arrConfig = array('relation_class_name' => $AppLogic->controllerName($rel->table_primary), 'relation_field_id' => $rel->table_foreign_field, 'relation_field_fkey' => $rel->table_primary_field, 'relation_field_name' => $field_name);
             // Tentativa de automatizar o processo, na criacao da var_config
             $this->var_config_relations[$rel->table_foreign_field] = $arrConfig;
             // Traduz a stub
             Logic\UtilLogic::translateStub($arrConfig, $stub_child);
             $stubs[] = $stub_child;
         }
         return implode("\n\n", $stubs);
     } else {
         return '';
     }
 }
コード例 #3
0
ファイル: MknyRequest.php プロジェクト: mkny/cinimod
 /**
  * Replace the fillable for the given stub.
  *
  * @param  string  $stub
  * @return $this
  */
 protected function setClassVariables()
 {
     $tb = $this->getNameInput();
     if (strstr($tb, '/') !== false) {
         $tbx = explode('/', $this->getNameInput());
         $tb = $tbx[1];
     }
     $table = $this->argument('table') ?: str_plural(strtolower($tb));
     // Pega as colunas da tabela do banco
     $AppLogic = new Logic\AppLogic();
     $columns = $AppLogic->buildColumnsWithKeys($table);
     // echo '<pre>';
     // print_r($columns);
     // exit;
     // Pega os field_types (translation)
     $field_types = $AppLogic->_getFieldTypes();
     $strRules = '';
     foreach ($columns as $key => $col) {
         // Debug Estado!
         // echo '<pre>';
         // print_r($col);
         // exit;
         // Pula a primary key
         if ($key == 0) {
             continue;
         }
         // Armazena as regras para o campo
         $arrRule = [];
         // Check constraint
         if (isset($col->def_constraint) && !empty($col->def_constraint)) {
             // var_dump($col->def_constraint);exit;
             $check = $AppLogic->_getCheck($col->def_constraint);
             $col->type = 'char';
             $arrRule[] = 'in:' . implode(',', $check);
         }
         // Unique field
         if (isset($col->uniq_field) && $col->uniq_field) {
             $arrRule[] = 'unique:' . $col->uniq_field;
         }
         // Informa o tipo de dado
         $col->field_type = $field_types[$col->type];
         // Verifica o tamanho maximo do campo
         if ($col->length) {
             $arrRule[] = "max:{$col->length}";
         }
         // Verifica se o campo nao aceita nulo e se e date com valor default
         if ($col->is_null == 'NO') {
             if ($col->field_type == 'date' && trim($col->default_value) != '') {
             } else {
                 $arrRule[] = 'required';
             }
         }
         // echo '<pre>';
         // print_r($arrRule);
         // exit;
         // Adiciona o tipo na validacao
         $arrRule[] = $col->field_type;
         // Inverte pra ficar bonito :)
         $arrRule = array_reverse($arrRule);
         // Monta pro Request, o formato de validacao
         $strRules .= "\n\t\t'{$col->name}' => '" . implode('|', $arrRule) . "',";
     }
     // Setta validation_block
     $this->setTranslation('validation_block', substr($strRules, 0, -1) . "\n\t\t");
 }