Example #1
0
 public function saveGroupItem($dataobj)
 {
     if (array_key_exists('show', $dataobj)) {
         $this->show = $dataobj['show'] == "true" ? true : false;
     }
     if (array_key_exists('sorter', $dataobj)) {
         $this->sorter = $dataobj['sorter'];
     }
     $sitestruct = config('sitestruct');
     if (array_key_exists($this->block_name, $sitestruct)) {
         $groupstruct = config('sitestruct')[$this->block_name]['group'];
         foreach (['stringfields', 'textfields', 'numbs', 'images', 'bools'] as $typename) {
             if (array_key_exists($typename, $dataobj) && array_key_exists($typename, $groupstruct)) {
                 $data_fs = $dataobj[$typename];
                 foreach ($groupstruct[$typename] as $fieldname) {
                     if (array_key_exists($fieldname, $data_fs)) {
                         if ($typename == 'stringfields') {
                             $field = Stringfield::firstOrNew(['block_name' => $this->block_name, 'name' => $fieldname, 'group_id' => $dataobj['id']]);
                             $field->value = $data_fs[$fieldname];
                             $this->stringfields()->save($field);
                         } else {
                             if ($typename == 'textfields') {
                                 $field = Textfield::firstOrNew(['block_name' => $this->block_name, 'name' => $fieldname, 'group_id' => $dataobj['id']]);
                                 $field->value = $data_fs[$fieldname];
                                 $this->textfields()->save($field);
                             } else {
                                 if ($typename == 'numbs') {
                                     $field = Numb::firstOrNew(['block_name' => $this->block_name, 'name' => $fieldname, 'group_id' => $dataobj['id']]);
                                     $field->value = $data_fs[$fieldname];
                                     $this->numbs()->save($field);
                                 } else {
                                     if ($typename == 'bools') {
                                         $field = Bool::firstOrNew(['block_name' => $this->block_name, 'name' => $fieldname, 'group_id' => $dataobj['id']]);
                                         $field->value = $data_fs[$fieldname] == "true" ? true : false;
                                         $this->bools()->save($field);
                                     } else {
                                         if ($typename == 'images') {
                                             $field = Imageitem::firstOrNew(['block_name' => $this->block_name, 'name' => $fieldname, 'group_id' => $dataobj['id']]);
                                             if (array_key_exists('alt', $data_fs[$fieldname])) {
                                                 $field->alt = $data_fs[$fieldname]['alt'];
                                             }
                                             if (array_key_exists('primary_link', $data_fs[$fieldname])) {
                                                 $field->primary_link = $data_fs[$fieldname]['primary_link'];
                                             }
                                             if (array_key_exists('secondary_link', $data_fs[$fieldname])) {
                                                 $field->secondary_link = $data_fs[$fieldname]['secondary_link'];
                                             }
                                             if (array_key_exists('icon_link', $data_fs[$fieldname])) {
                                                 $field->icon_link = $data_fs[$fieldname]['icon_link'];
                                             }
                                             if (array_key_exists('preview_link', $data_fs[$fieldname])) {
                                                 $field->preview_link = $data_fs[$fieldname]['preview_link'];
                                             }
                                             $this->images()->save($field);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $this->save();
         return 'OK';
     } else {
         return 'Block key ' . $this->block_name . ' not found.';
     }
 }
Example #2
0
 public static function initBlocks()
 {
     $sitestruct = config('sitestruct');
     foreach ($sitestruct as $blockname => $blockstruct) {
         $newBlock = static::find($blockname);
         if (!$newBlock) {
             $newBlock = new static();
             $newBlock->name = $blockname;
             if (array_key_exists('title', $blockstruct)) {
                 $newBlock->title = $blockstruct['title'];
             }
             if (array_key_exists('stringfields', $blockstruct)) {
                 foreach ($blockstruct['stringfields'] as $fieldname) {
                     $stringfield = Stringfield::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('textfields', $blockstruct)) {
                 foreach ($blockstruct['textfields'] as $fieldname) {
                     $textfield = Textfield::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('numbs', $blockstruct)) {
                 foreach ($blockstruct['numbs'] as $fieldname) {
                     $numb = Numb::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('bools', $blockstruct)) {
                 foreach ($blockstruct['bools'] as $fieldname) {
                     $boolitem = Bool::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             if (array_key_exists('images', $blockstruct)) {
                 foreach ($blockstruct['images'] as $fieldname) {
                     $image = Imageitem::firstOrCreate(['block_name' => $blockname, 'name' => $fieldname]);
                 }
             }
             $newBlock->save();
         }
     }
     return 'OK';
 }