deblan.tv/vendor/trinity/src/Trinity/Bundle/ContentManagerBundle/Block/BlockManager.php
2015-03-02 21:57:49 +01:00

67 lines
1.7 KiB
PHP

<?php
namespace Trinity\Bundle\ContentManagerBundle\Block;
use \Trinity\Bundle\ContentManagerBundle\Model\Node;
use \Trinity\Bundle\ContentManagerBundle\Exception\BlockNotFoundException;
use \Trinity\Bundle\ContentManagerBundle\Model\SeoPageInterface;
class BlockManager
{
protected $blocks;
public function retrieve($block_name)
{
if (!isset($this->blocks) || !is_array($this->blocks)) {
$this->blocks = array();
}
if (!array_key_exists($block_name, $this->blocks)) {
throw new BlockNotFoundException(sprintf('No %s block defined for the current page.', $block_name));
}
return $this->blocks[$block_name];
}
public function recursiveRetrieve($block_name,Node $node)
{
$nodes = $node->getReverseAncestors();
foreach ($nodes as $node) {
$block = $node->getBlockWithName($block_name);
if (!$block) {
continue;
}
//TODO: voir si il faut faire une interface pour les blocs éditoriaux
/*if ($block->getValue() == NULL) {
continue;
}*/
if ($block) {
return $block;
}
}
//TODO: Peut etre à enlever si plantage
throw new BlockNotFoundException(sprintf('No %s block defined for the current tree.', $block_name));
}
public function retrieveAll()
{
return $this->blocks;
}
public function loadPageBlocks(SeoPageInterface $page)
{
$blocks = $page->getBlocks();
foreach ($blocks as $block) {
$this->blocks[$block->getName()] = $block;
}
return $this->blocks;
}
}