Exemple #1
0
 /**
  * Generate View files from template
  * @param  Packettide\Sire\Sire $sire
  */
 public function run($sire)
 {
     $path = app_path() . '/views/' . $sire->name->plural() . '/';
     $names = array('create.blade.php', 'edit.blade.php', 'index.blade.php');
     $headings = array_map(function ($el) {
         return array("heading" => $el['label'], 'hide' => $el['fieldType'] == 'None');
     }, $sire->fields);
     $tempFields = $sire->fields;
     $fields = array();
     foreach ($tempFields as $key => $value) {
         $value['realField'] = isset($value['relatedModel']) && isset($value['fieldTypeOptions']);
         $value['realField'] = $value['realField'] ? 'implode(array_pluck(\\Illuminate\\Support\\Collection::make($' . $sire->name . '->' . $key . '), "' . $value['fieldTypeOptions']['title'] . '"), ", ")' : false;
         $value['hide'] = $value['fieldType'] == 'None';
         array_push($fields, $value);
     }
     $fields = $sire->assocToNumeric($fields);
     $toTemplate = array("headings" => $sire->assocToNumeric($headings), "fields" => $fields);
     foreach ($names as $name) {
         // Make sure view $path exists
         if (!is_dir($path)) {
             mkdir($path);
         }
         $sire->templater->template($this->viewTemplates[$name], $toTemplate, $path . $name);
     }
     // Set $layoutPath for view layouts and make sure it exists
     $layoutPath = app_path() . '/views/layouts/';
     if (!is_dir($layoutPath)) {
         mkdir($layoutPath);
     }
     $sire->templater->template($this->viewTemplates['layout.blade.php'], $toTemplate, $layoutPath . $sire->viewTheme . '.blade.php');
 }
Exemple #2
0
 /**
  * Generate Model file from template
  * @param  Packettide\Sire\Sire $sire
  */
 public function run($sire)
 {
     $fields = $sire->fields;
     $tempRelationships = $sire->fields;
     $relationships = array();
     foreach ($tempRelationships as $key => $value) {
         if (isset($value['relationshipType']) && isset($value['relatedModel'])) {
             $temp = array();
             $temp['_name'] = \Str::camel($value['_name']);
             $temp['type'] = $value['relationshipType'];
             $temp['model'] = $value['relatedModel'];
             array_push($relationships, $temp);
         }
     }
     $fields = array_map(function ($el) {
         if (isset($el['fieldTypeOptions'])) {
             $el['breeAttrs'] = array_map(function ($v, $k) {
                 if (!($v === true || $v === false)) {
                     $v = "'{$v}'";
                 }
                 return sprintf("'%s' => %s", $k, $v);
             }, $el['fieldTypeOptions'], array_keys($el['fieldTypeOptions']));
         }
         $el['breeAttrs'] = isset($el['breeAttrs']) ? $el['breeAttrs'] : array();
         if (isset($el['relatedModel'])) {
             array_push($el['breeAttrs'], "'related' => '{$el['relatedModel']}'");
         }
         $el['breeAttrs'] = implode(", ", $el['breeAttrs']);
         return $el;
     }, $fields);
     $fields = $sire->assocToNumeric($fields);
     $path = app_path() . '/models/';
     $toTemplate = array("rules" => $sire->getRules(), "relationships" => $relationships, "breeFields" => $fields);
     foreach ($this->templates as $name => $template) {
         if (!$this->safe[$sire->name->upper() . '.php'] || !is_file($path . $name)) {
             $sire->templater->template($template, $toTemplate, $path . $name);
         }
     }
 }
 /**
  * Generate Migration file from template
  * @param  Packettide\Sire\Sire $sire
  */
 public function run($sire)
 {
     $tempFields = $sire->assocToNumeric($sire->fields);
     $fields = array();
     $path = app_path() . '/database/migrations/';
     foreach ($tempFields as $field) {
         $temp = $field;
         if (isset($temp['relationshipType']) && $temp['relationshipType'] === 'belongsTo') {
             $temp['sqlType'] = 'integer';
             $temp['_name'] = $temp['_name'] . '_id';
             array_push($fields, $temp);
         } else {
             if (!isset($temp['relationshipType'])) {
                 array_push($fields, $temp);
             }
         }
     }
     $this->reset($sire);
     $name = date('Y_m_d_His') . '_create_' . $sire->name->plural() . '_table.php';
     $toTemplate = array("tableName" => $sire->name->plural(), "fields" => $fields);
     $sire->templater->template($this->migrationTemplate, $toTemplate, $path . $name);
 }