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.'; } }
public function saveBlock($dataobj) { $sitestruct = config('sitestruct'); if (array_key_exists($this->name, $sitestruct)) { $blockstruct = $sitestruct[$this->name]; if (array_key_exists('title', $dataobj)) { $this->title = $dataobj['title']; } foreach (['stringfields', 'textfields', 'numbs', 'images', 'bools'] as $typename) { if (array_key_exists($typename, $dataobj) && array_key_exists($typename, $blockstruct)) { $data_fs = $dataobj[$typename]; foreach ($blockstruct[$typename] as $fieldname) { if (array_key_exists($fieldname, $data_fs)) { if ($typename == 'stringfields') { $field = Stringfield::firstOrNew(['block_name' => $this->name, 'name' => $fieldname]); $field->value = $data_fs[$fieldname]; $field->save(); } else { if ($typename == 'textfields') { $field = Textfield::firstOrNew(['block_name' => $this->name, 'name' => $fieldname]); $field->value = $data_fs[$fieldname]; $field->save(); } else { if ($typename == 'numbs') { $field = Numb::firstOrNew(['block_name' => $this->name, 'name' => $fieldname]); $field->value = $data_fs[$fieldname]; $field->save(); } else { if ($typename == 'bools') { $field = Bool::firstOrNew(['block_name' => $this->name, 'name' => $fieldname]); $field->value = $data_fs[$fieldname] == "true" ? true : false; $field->save(); } else { if ($typename == 'images') { $field = Imageitem::firstOrNew(['block_name' => $this->name, 'name' => $fieldname]); 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']; } $field->save(); } } } } } } } } } $this->save(); return 'OK'; } else { return 'Key ' . $this->name . ' not found.'; } }