/**
  * Retrieves a menu identified by the given name.
  *
  * The name should correspond to a name on a root doctrine node 
  *
  * @param  string $name The name of the root node to retrieve
  * @return ioMenuItem|null
  */
 public function getMenu($name, $class = 'ioDoctrineMenuItem')
 {
     $cacheKey = md5($name);
     if ($data = $this->getCache($cacheKey)) {
         $data = unserialize($data);
         return ioMenuItem::createFromArray($data);
     }
     $menu = Doctrine_Core::getTable($class)->fetchMenu($name);
     if ($menu) {
         $this->setCache($cacheKey, serialize($menu->toArray()));
     }
     return $menu;
 }
Esempio n. 2
0
$menu->setLabel('administración', 'es');
$t->is($menu->useI18n(), true, '->useI18n() returns true after an i18n label is set.');
$t->is($menu->getLabel('es'), 'administración', '->getLabel(es) correctly returns the spanish label I just set.');
$t->is($menu->getLabel(), 'admin', '->getLabel() still returns "admin", which is the name since no en label is set.');
$menu->setLabel('admin default');
$t->is($menu->getLabel(), 'admin default', '->getLabel() returns "admin default", the default label');
$menu->setLabel('administration', 'en');
$t->is($menu->getLabel(), 'administration', '->getLabel() returns "administration", the "en" culture label');
sfConfig::set('sf_default_culture', 'es');
$t->is($menu->getLabel('fake'), 'administración', '->getLabel() retrieves the sf_default_culture label if the given culture does not have a label.');
$menu->setCulture('es');
$t->is($menu->getLabel(), 'administración', '->getLabel() returns the label of the culture on the label');
$t->info('  9.3 - Test toArray() and fromArray()');
$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();
 /**
  * Creates an ioMenuItem tree where this object is the root
  *
  * @return ioMenuItem
  */
 public function createMenu()
 {
     $hier = $this->_getMenuHierarchy();
     $data = self::_convertHierarchyToMenuArray($hier);
     return ioMenuItem::createFromArray($data);
 }