Beispiel #1
0
 /**
  * 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 '';
     }
 }
Beispiel #2
0
 /**
  * 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];
     }
     // Plurazica, caso nao exista a tabela
     $table = $this->argument('table') ?: str_plural(strtolower($tb));
     // Pega as colunas da tabela do banco
     $AppLogic = new Logic\AppLogic();
     $columns = $AppLogic->buildColumns($table);
     $fields = [];
     foreach ($columns as $col) {
         $field = $col->name;
         $field_camel = camel_case($col->name, '_', ' ');
         $field_format = array('grid' => $field_camel, 'form' => $field_camel, 'form_tip' => $field_camel);
         $fields[] = "\n\t// {$field}\n\t'{$field}' => " . var_export($field_format, true) . ",\n";
         // $fields[] = "\n\t// {$field}\n\t'{$field}_grid' => '{$field_camel}',\n\t'{$field}_form' => '{$field_camel}',\n\t'{$field}_form_tip' => '{$field_camel}',\n";
     }
     // $this->setTranslation('controller', $tb);
     $this->setTranslation('variables_data', "\n\t" . substr(trim(implode("\n", $fields)), 0, -1) . "\n\t");
 }
Beispiel #3
0
 /**
  * Funcao para buscar e montar o sistema de relacionamentos do Eloquent
  * 
  * @param string $table Nome da tabela que sera gerada
  * @return void
  */
 private function _getRelations($table)
 {
     $this->var_config_relations = [];
     // 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) {
             // 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;
         }
     }
 }