Ejemplo n.º 1
0
 /**
  * Create tree
  * 
  * @param   DinMenuItem $item
  * @param   string      $nesting    Nesting key name [optional]
  * @return  array   Tree in array representation
  */
 protected function createTree($item, $nesting = 'items')
 {
     $lang = sfContext::getInstance()->getUser()->getCulture();
     $items = array();
     $node = $item->getNode();
     if ($node->hasChildren()) {
         foreach ($node->getChildren() as $children) {
             if ($children['is_public']) {
                 $items[] = $this->createTree($children, $nesting);
             }
         }
     }
     if ($item['level'] == 0) {
         return $items;
     }
     $out = $item->toArray();
     unset($out['Menu'], $out['menu_id'], $out['root_id'], $out['lft'], $out['rgt']);
     if (!isset($out['Translation'][$lang]) && isset($out['Translation']['en'])) {
         $out['Translation'][$lang] = $out['Translation']['en'];
     }
     unset($out['Translation'][$lang]['id'], $out['Translation'][$lang]['lang']);
     $out = array_merge($out, $out['Translation'][$lang]);
     unset($out['Translation'], $out['description'], $out['is_public']);
     $out[$nesting] = $items;
     return $out;
 }