Esempio n. 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.';
     }
 }
Esempio n. 2
0
 public function createGroupItem()
 {
     $dataArr = ['sorter' => 99, 'show' => true, 'stringfields' => [], 'textfields' => [], 'numbs' => [], 'bools' => [], 'images' => []];
     $blockname = $this->name;
     $groupstruct = config('sitestruct')[$this->name]['group'];
     $newGroupItem = new \App\Group();
     $newGroupItem->block_name = $blockname;
     $newGroupItem->save();
     $dataArr['id'] = $newGroupItem->id;
     if (array_key_exists('stringfields', $groupstruct)) {
         foreach ($groupstruct['stringfields'] as $fieldname) {
             $stringfield = Stringfield::create(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]);
             $newGroupItem->stringfields()->save($stringfield);
             $dataArr['stringfields'][$fieldname] = '';
         }
     }
     if (array_key_exists('textfields', $groupstruct)) {
         foreach ($groupstruct['textfields'] as $fieldname) {
             $textfield = Textfield::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]);
             $newGroupItem->textfields()->save($textfield);
             $dataArr['textfields'][$fieldname] = '';
         }
     }
     if (array_key_exists('numbs', $groupstruct)) {
         foreach ($groupstruct['numbs'] as $fieldname) {
             $numb = Numb::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]);
             $newGroupItem->numbs()->save($numb);
             $dataArr['numbs'][$fieldname] = '';
         }
     }
     if (array_key_exists('bools', $groupstruct)) {
         foreach ($groupstruct['bools'] as $fieldname) {
             $boolitem = Bool::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]);
             $newGroupItem->bools()->save($boolitem);
             $dataArr['bools'][$fieldname] = '';
         }
     }
     if (array_key_exists('images', $groupstruct)) {
         foreach ($groupstruct['images'] as $fieldname) {
             $image = Imageitem::firstOrNew(['block_name' => $blockname, 'name' => $fieldname, 'group_id' => $newGroupItem->id]);
             $newGroupItem->images()->save($image);
             $dataArr['images'][$fieldname] = ['alt' => '', 'primary_link' => '', 'secondary_link' => '', 'icon_link' => '', 'preview_link' => ''];
         }
     }
     $newGroupItem->save();
     return $dataArr;
 }