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

96 lines
2.3 KiB
PHP

<?php
namespace Trinity\Bundle\ContentManagerBundle\Model;
use Trinity\Bundle\ContentManagerBundle\Model\om\BaseMenu;
class Menu extends BaseMenu
{
protected $visible_nodes = array();
protected $nodes = array();
protected $nodes_by_updated_at = array();
public function __toString()
{
return $this->getTitle();
}
public function getLoadedNodes()
{
return $this->visible_nodes;
}
public function loadVisibleNodes()
{
if (!empty($this->visible_nodes)) {
return $this;
}
$nodes = NodeQuery::create()
->filterByMenuId($this->id)
->orderByTreeLeft()
->find();
foreach ($nodes as $node) {
if (!$node->isVisible()) {
continue;
}
if (!$node->getPage() || ($node->getNodeAlias() && !$node->getNodeAlias()->getPage())) {
continue;
}
$this->visible_nodes[$node->getUrl()] = $node;
}
return $this;
}
public function getNodes($criteria = null, PropelPDO $con = null)
{
if (!empty($this->nodes)) {
return $this->nodes;
}
$this->nodes = NodeQuery::create(null, $criteria)
->filterByMenuId($this->getId())
->orderByTreeLeft()
->find($con);
return $this->nodes;
}
public function getNodesByUpdatedAt($criteria = null, PropelPDO $con = null)
{
if (!empty($this->nodes_by_updated_at)) {
return $this->nodes_by_updated_at;
}
$this->nodes_by_updated_at = NodeQuery::create(null, $criteria)
->filterByMenuId($this->getId())
->orderByUpdatedAt(\Criteria::DESC)
->limit(\Trinity\Bundle\AdminBundle\Controller\BaseAdminController::HISTORY_LIMIT)
->find($con);
return $this->nodes_by_updated_at;
}
public function createRootNode()
{
if(count($this->getNodes())){
return false;
}
$node = new Node();
$node->setNavId($this->getNavId())
->setMenuId($this->getId())
->setTitle('First item')
->insertAsLastChildOf($this->getNav()->getRootNode())
->save();
return true;
}
}