55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Trinity\Bundle\ContentManagerBundle\Model;
|
|
|
|
use Trinity\Bundle\ContentManagerBundle\Model\om\BaseMenuPeer;
|
|
|
|
class MenuPeer extends BaseMenuPeer
|
|
{
|
|
public static function findMenusWithNodes()
|
|
{
|
|
$menus = array();
|
|
|
|
foreach (MenuQuery::create()->orderByRank()->find() as $k => $menu) {
|
|
$menus[] = array(
|
|
'menu' => $menu,
|
|
'nodes' => $menu->getNodes(),
|
|
'nodesByUpdatedAt' => $menu->getNodesByUpdatedAt(),
|
|
);
|
|
}
|
|
|
|
return $menus;
|
|
}
|
|
|
|
public static function filterByNavId($nav_id, array $menus)
|
|
{
|
|
foreach ($menus as $k => $menu) {
|
|
if ($menu['menu']->getNavId() != $nav_id) {
|
|
unset($menus[$k]);
|
|
}
|
|
}
|
|
|
|
return $menus;
|
|
}
|
|
|
|
public static function getMenuWithNodesForType($indent_string = '--')
|
|
{
|
|
$choices = array();
|
|
|
|
foreach (MenuQuery::create()->orderByName()->find() as $k => $menu) {
|
|
$items = array();
|
|
$nodes = NodeQuery::create()->filterByMenuId($menu->getId())->orderByTreeLeft()->find();
|
|
|
|
foreach ($nodes as $node) {
|
|
$items[$node->getId()] = sprintf('%s %s', str_repeat($indent_string, max(0, $node->getLevel() - 1)), $node->getTitle());
|
|
}
|
|
|
|
$choices[$menu->getNav()->getTitle().' - '.$menu->getTitle()] = $items;
|
|
}
|
|
|
|
arsort($choices);
|
|
|
|
return $choices;
|
|
}
|
|
}
|