public function getPages($groupId) { $group = PageGroup::preload($groupId); if ($group->exists) { $pageIds = $group->itemPageIds(false, true); $attributes = PageGroupAttribute::where('group_id', '=', $groupId)->get(); $attributeBlocks = []; foreach ($attributes as $attribute) { $block = Block::preload($attribute->item_block_id); if ($block->exists) { $attributeBlocks[$attribute->item_block_id] = $block; } } $pageRows = ''; if (!empty($pageIds)) { foreach ($pageIds as $pageId) { $pageLang = PageLang::preload($pageId); $showBlocks = []; $canEdit = Auth::action('pages.edit', ['page_id' => $pageId]); $canDelete = Auth::action('pages.delete', ['page_id' => $pageId]); foreach ($attributeBlocks as $attributeBlock) { $pageBlockContent = PageBlock::preloadPageBlockLanguage($pageId, $attributeBlock->id, -1, 'block_id')->content; if (strpos($attributeBlock->type, 'selectmultiple') === 0 && !empty($pageBlockContent)) { // selectmultiple $showBlocks[] = implode(', ', unserialize($pageBlockContent)); } elseif ($attributeBlock->type == 'datetime' && !empty($pageBlockContent)) { // datetime $showBlocks[] = (new Carbon($pageBlockContent))->format(config('coaster::date.format.long')); } else { // text/string/select $showBlocks[] = strip_tags(StringHelper::cutString($pageBlockContent, 50)); } } $pageRows .= View::make('coaster::partials.groups.page_row', array('page_lang' => $pageLang, 'item_name' => $group->item_name, 'showBlocks' => $showBlocks, 'can_edit' => $canEdit, 'can_delete' => $canDelete))->render(); } } $pagesTable = View::make('coaster::partials.groups.page_table', array('rows' => $pageRows, 'item_name' => $group->item_name, 'blocks' => $attributeBlocks))->render(); $this->layoutData['modals'] = View::make('coaster::modals.general.delete_item'); $this->layoutData['content'] = View::make('coaster::pages.groups', array('group' => $group, 'pages' => $pagesTable, 'can_add' => $group->canAddItems(), 'can_edit' => $group->canEditItems())); } }
/** * Filter by container block content (filtered by group container content - pageId) * @param int $pageId * @param bool $checkLive * @param bool $sort * @return array */ public function itemPageIdsFiltered($pageId, $checkLive = false, $sort = false) { $filterType = $checkLive ? 'all' : 'live'; $sortedSuffix = '-sorted'; $sorted = $sort ? $sortedSuffix : ''; self::$groupPagesFiltered[$this->id] = empty(self::$groupPagesFiltered[$this->id]) ? [] : self::$groupPagesFiltered[$this->id]; if (!array_key_exists($filterType . $sorted, self::$groupPagesFiltered[$this->id])) { if ($pageIds = $this->itemPageIds($checkLive, $sort)) { foreach ($this->blockFilters() as $blockFilter) { // get data to filter by $filterByBlock = Block::preload($blockFilter->filter_by_block_id); $filterByContent = PageBlock::preloadPageBlockLanguage($pageId, $blockFilter->filter_by_block_id, -1, 'block_id')->content; if ($filterByBlock->type == 'selectmultiple') { $filterByContentArr = unserialize($filterByContent); $filterByContentArr = is_array($filterByContentArr) ? $filterByContentArr : []; } else { $filterByContentArr = [$filterByContent]; } $filterByContentArr = array_filter($filterByContentArr, function ($filterByContentEl) { return !is_null($filterByContentEl); }); if (!empty($filterByContentArr)) { // get block data for block to filter on $blockType = Block::preload($blockFilter->item_block_id)->getTypeObject(); // run filter with filterBy content $filteredPageIds = []; foreach ($pageIds as $groupPageId) { foreach ($filterByContentArr as $filterByContentEl) { $groupPageBlockContent = PageBlock::preloadPageBlockLanguage($groupPageId, $blockFilter->item_block_id, -1)->content; if ($blockType->filter($groupPageBlockContent, $filterByContentEl, '=')) { $filteredPageIds[] = $groupPageId; break; } } } $pageIds = $filteredPageIds; } } } self::$groupPagesFiltered[$this->id][$filterType . $sorted] = $pageIds; } return self::$groupPagesFiltered[$this->id][$filterType . $sorted]; }