/**
  * Renders all of the children of item.
  *
  * This calls ->renderChild() on each menu item, which instructs each
  * menu item to render themselves as an <li> tag (with nested ul if it
  * has children).
  *
  * @param integer $depth The depth each child should render
  * @return string
  */
 protected function _renderChildren(ioMenuItem $item, $depth = null)
 {
     $html = '';
     foreach ($item->getChildren() as $child) {
         $html .= $this->_renderItem($child, $depth);
     }
     return $html;
 }
Esempio n. 2
0
$arr = $menu->toArray();
$t->is($arr['i18n_labels'], array('es' => 'administración', 'en' => 'administration'), '->toArray() exports an i18n_labels array');
$newMenu = ioMenuItem::createFromArray($arr);
$arr = $newMenu->toArray();
$t->is($arr['i18n_labels'], array('es' => 'administración', 'en' => 'administration'), '->fromArray() correctly imports the i18n_labels');
$menu = new ioMenuItem('root');
$arr = $menu->toArray();
$t->is(isset($arr['i18n_labels']), false, 'If no i18n labels are set, the key is hidden entirely from ->toarray().');
$t->info('10 - Test item reordering.');
$menu = new ioMenuItem('root');
$menu->addChild('c1');
$menu->addChild('c2');
$menu->addChild('c3');
$menu->addChild('c4');
$menu['c3']->moveToFirstPosition();
$arr = array_keys($menu->getChildren());
$t->is($arr, array('c3', 'c1', 'c2', 'c4'), 'c3 moved to first position');
$menu['c2']->moveToLastPosition();
$arr = array_keys($menu->getChildren());
$t->is($arr, array('c3', 'c1', 'c4', 'c2'), 'c2 moved to last position');
$menu['c1']->moveToPosition(2);
$arr = array_keys($menu->getChildren());
$t->is($arr, array('c3', 'c4', 'c1', 'c2'), 'c1 moved to 3rd position');
$menu->reorderChildren(array('c4', 'c3', 'c2', 'c1'));
$arr = array_keys($menu->getChildren());
$t->is($arr, array('c4', 'c3', 'c2', 'c1'), 'reorder children');
$t->is($menu->render(), '<ul class="menu"><li class="first">c4</li><li>c3</li><li>c2</li><li class="last">c1</li></ul>', 'proper rendering after reorder');
// create the tree and make the variables available
extract(create_test_tree($t, 'ioMenuItemTest'));
$t->info('10 - Test copy');
check_test_tree($t, $menu);
Esempio n. 3
0
 /**
  * Recursively finds current item.
  *
  * @param ioMenuItem $item Item to start from
  * @return ioMenuItem current item or null
  */
 protected function findCurrentItem(ioMenuItem $item)
 {
     if ($item->matchCurrentLocation($this)) {
         return $item;
     }
     foreach ($item->getChildren() as $child) {
         $current = $this->findCurrentItem($child);
         if ($current) {
             return $current;
         }
     }
     return null;
 }