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

70 lines
2.1 KiB
PHP

<?php
namespace Trinity\Bundle\EditorialBlockBundle\Block;
use Symfony\Component\HttpFoundation\File\File;
use Trinity\Bundle\ContentManagerBundle\Model\Block;
use Trinity\Component\File\FileUploadInterface;
use Trinity\Bundle\EditorialBlockBundle\Model\EditorialBlockQuery;
class EditorialBlocksContainerBlock extends Block
{
const DEFAULT_TEMPLATE = 'TrinityEditorialBlockBundle:Block:block_editorial.html.twig';
private $editorial_blocks = array();
public function getTemplate()
{
return $this::DEFAULT_TEMPLATE;
}
public function __construct()
{
parent::__construct();
$this->setClassKey('Trinity\Bundle\EditorialBlockBundle\Block\EditorialBlocksContainerBlock');
if($this->value === null){
$this->setValue('USE_PARENT');
}
}
public function getEditorialBlocks()
{
$ids = array_filter(explode(' ',$this->getValue()));
if(empty($this->editorial_blocks)){
foreach($ids as $id){
if($id=='USE_PARENT') {
$my_node = $this->getPage()->getNodeRelatedByNodeId();
while($my_node->hasParent()) {
$my_node = $my_node->getParent();
if(!$my_node->getPage()) {
continue;
}
if(!$parent_blocks = $my_node->getPage()->getBlock('editorial_blocks')) {
continue;
}
if($parent_blocks->isNew()) {
continue;
}
$parent_editorial_blocks = $parent_blocks->getEditorialBlocks();
$this->editorial_blocks = array_unique(array_merge($this->editorial_blocks,$parent_editorial_blocks));
break;
}
} else {
$this->editorial_blocks[] = EditorialBlockQuery::create()->findPk($id);
}
}
}
return $this->editorial_blocks;
}
}