public function createInitBlock($block_name) { try { Block::initBlocks($block_name); } catch (Exception $exception) { return ['status' => 'Что-то пошло не так. ' . $exception->getMessage()]; } return ['status' => 'OK']; }
public function saveBlock() { if (Request::has('entity')) { $dataobj = Request::all(); if ($dataobj['entity'] == 'block') { try { $block = Block::firstOrCreate(['name' => $dataobj['block']]); $result = $block->saveBlock($dataobj); return ['status' => $result]; } catch (Exception $exception) { return ['status' => 'Что-то пошло не так. ' . $exception->getMessage()]; } } else { return ['status' => 'Имя сохраняемой сущности не равно block (' . $dataobj['entity'] . ').']; } } else { return ['status' => 'Не хватает параметров для сохранения.']; } }
public static function getBlocksDisplayArray($addshow = false, $block_name = '') { if ($block_name != '') { $blocks = Block::where('name', '=', $block_name)->with(['stringfields' => function ($query) { $query->where('group_id', '=', 0); }, 'textfields' => function ($query) { $query->where('group_id', '=', 0); }, 'numbs' => function ($query) { $query->where('group_id', '=', 0); }, 'bools' => function ($query) { $query->where('group_id', '=', 0); }, 'pdatetimes' => function ($query) { $query->where('group_id', '=', 0); }, 'images' => function ($query) { $query->where('group_id', '=', 0); }])->get(); } else { $blocks = Block::with(['stringfields' => function ($query) { $query->where('group_id', '=', 0); }, 'textfields' => function ($query) { $query->where('group_id', '=', 0); }, 'numbs' => function ($query) { $query->where('group_id', '=', 0); }, 'bools' => function ($query) { $query->where('group_id', '=', 0); }, 'pdatetimes' => function ($query) { $query->where('group_id', '=', 0); }, 'images' => function ($query) { $query->where('group_id', '=', 0); }])->get(); } $dataArr = []; foreach ($blocks as $block) { $dataArr[$block->name] = ['title' => $block->title, 'stringfields' => [], 'textfields' => [], 'images' => [], 'bools' => [], 'pdatetimes' => [], 'numbs' => []]; $block_strfs =& $dataArr[$block->name]['stringfields']; foreach ($block->stringfields as $stringfield) { $block_strfs[$stringfield->name] = $stringfield->value; } $block_textfs =& $dataArr[$block->name]['textfields']; foreach ($block->textfields as $textfield) { $block_textfs[$textfield->name] = $textfield->value; } $block_images =& $dataArr[$block->name]['images']; foreach ($block->images as $image) { $block_images[$image->name] = ['alt' => $image->alt, 'primary_link' => $image->primary_link, 'secondary_link' => $image->secondary_link, 'icon_link' => $image->icon_link, 'preview_link' => $image->preview_link]; } $block_bools =& $dataArr[$block->name]['bools']; foreach ($block->bools as $boolitem) { $block_bools[$boolitem->name] = $boolitem->value; } $block_pdatetimes =& $dataArr[$block->name]['pdatetimes']; foreach ($block->pdatetimes as $dtitem) { $block_pdatetimes[$dtitem->name] = $dtitem->value; } $block_numbs =& $dataArr[$block->name]['numbs']; foreach ($block->numbs as $numb) { $block_numbs[$numb->name] = $numb->value; } $dataArr[$block->name]['group'] = $block->getGroupItemsArray($addshow); } return $dataArr; }