/** * @param $blockId * @param $pageId * @return static|null */ public static function getBlockOnPage($blockId, $pageId) { if ($page = Page::find($pageId)) { $blocksByCat = Template::template_blocks(config('coaster::frontend.theme'), $page->template); } else { $blocksByCat = Theme::theme_blocks(config('coaster::frontend.theme')); } foreach ($blocksByCat as $blocks) { foreach ($blocks as $block) { if ($block->id == $blockId) { return static::find($blockId); } } } return null; }
public function getIndex() { // load theme global blocks $blocks = array(); $theme = Theme::find(config('coaster::frontend.theme')); if (!empty($theme)) { $blocks = Theme::theme_blocks($theme->id); } // load tab contents from categories & blocks (with default block contents) $default_blocks = PageBlockDefault::preloadArray(); list($tab_headers, $tab_contents) = Block::getTabs($blocks, $default_blocks); $tab_headers = array_filter($tab_headers); ksort($tab_headers); $tab_data = ['headers' => View::make('coaster::partials.tabs.header', ['tabs' => $tab_headers])->render(), 'contents' => View::make('coaster::partials.tabs.content', ['tabs' => $tab_contents, 'item' => 'Site-wide Content', 'new_page' => false, 'publishing' => false, 'can_publish' => true])->render()]; $this->layoutData['title'] = 'Site-wide Content'; $this->layoutData['content'] = View::make('coaster::pages.blocks', ['tab' => $tab_data]); }
public static function template_blocks($theme, $template) { $blocks = Theme::theme_blocks($theme, $template); $selected_template = self::find($template); if (!empty($selected_template)) { $template_blocks = $selected_template->blocks()->get(); foreach ($template_blocks as $template_block) { if (!isset($blocks[$template_block->category_id])) { $blocks[$template_block->category_id] = array(); } $blocks[$template_block->category_id][$template_block->id] = $template_block; } } // order theme/template blocks properly foreach ($blocks as $cat_id => $block_cat) { uasort($blocks[$cat_id], array('self', 'order_blocks')); } return $blocks; }