deblan.tv/vendor/trinity/src/Trinity/Bundle/ContentManagerBundle/Page/PageManager.php
2015-09-14 14:53:34 +02:00

114 lines
2.7 KiB
PHP

<?php
namespace Trinity\Bundle\ContentManagerBundle\Page;
use Trinity\Bundle\ContentManagerBundle\Model\Nav;
use Trinity\Bundle\ContentManagerBundle\Navigation\NavigationInterface;
use \Trinity\Bundle\ContentManagerBundle\Model\Node;
use \Trinity\Bundle\ContentManagerBundle\Block\BlockManager;
use \Trinity\Bundle\ContentManagerBundle\Model\SeoPageInterface;
use \Trinity\Bundle\ContentManagerBundle\Exception\NodeNotFoundException;
use \Trinity\Bundle\ContentManagerBundle\Exception\PageNotFoundException;
class PageManager implements PageManagerInterface
{
protected $navigation;
protected $blockManager;
public $current_page = null;
public $current_node = null;
public $menus = null;
public function __construct(BlockManager $blockManager)
{
$this->blockManager = $blockManager;
}
public function getCurrentPage()
{
return $this->current_page;
}
public function changeCurrentPage()
{
if (!$this->current_node) {
throw new NodeNotFoundException('Check the decorator_strategy configuration otherwise create a new node to support this path.');
}
$page = $this->current_node->getPage();
if ($this->current_node->isHybrid() && !$page) {
return;
}
if (!$page) {
throw new PageNotFoundException(sprintf('You must create a page for the node named : "%s"',$this->current_node->getTitle()));
}
$this->setCurrentPage($page);
$this->loadBlocks();
}
public function setNavigation(NavigationInterface $nav)
{
$this->navigation = $nav;
}
public function setCurrentPage(SeoPageInterface $page)
{
$this->current_page = $page;
}
public function setCurrentNode(Node $node)
{
$this->current_node = $node;
}
public function getPage()
{
return $this->current_page;
}
/**
* @return null | Node
*/
public function getCurrentNode()
{
return $this->current_node;
}
public function getMenu($menu_name)
{
if (null === $this->menus) {
$this->loadMenus();
}
return $this->menus[$menu_name];
}
public function hasMenu($menu_name)
{
if (null === $this->menus) {
$this->loadMenus();
}
return array_key_exists($menu_name, $this->menus);
}
public function loadBlocks()
{
$this->blockManager->loadPageBlocks($this->current_page);
}
public function loadMenus()
{
$menus = $this->navigation->getMenus();
foreach ($menus as $menu) {
$menu->loadVisibleNodes();
$this->menus[$menu->getName()] = $menu;
}
}
}