public function fromArray(array $array, $deep = true)
 {
     if (isset($array['children'])) {
         $children = $array['children'];
         foreach ($children as $child) {
             $new = new csNavigationItem();
             $new->fromArray($child);
             $this->addChild($new);
         }
         unset($array['children']);
     }
     parent::fromArray($array, $deep);
 }
 /**
  * For adding dynamic elements to a branch of a tree.
  * Use in the setup() method.
  *
  * @param string $parentName - Name of the navigation item to add to
  * @param string $item - mixed, either the string name of the new item, or the route object
  * @param string $route (optional) - the route if $item is the string name
  * @return void
  * @author Brent Shaffer
  */
 public function appendItem($parentName, $item, $route = null)
 {
     $parent = $this->matchItemByName($parentName);
     if (!$parent) {
         return false;
     }
     if (!$item instanceof csNavigationItem) {
         $item = new csNavigationItem($item, $route);
     }
     if (!$item->getLevel()) {
         $item->level = $parent->getLevel() + 1;
     }
     $parent->addChild($item);
     return $parent;
 }
Ejemplo n.º 3
0
 /**
  * Create a navigation tree from the navigation.yml file
  *
  * @param string $arr 
  * @param string $level 
  * @param string $root 
  * @return void
  * @author Brent Shaffer
  */
 static function getNavigationBranchFromYaml($root, $arr, $commit = false, $level = 1)
 {
     $tree = new Doctrine_Collection('csNavigationItem');
     foreach ($arr as $key => $value) {
         $root->refresh();
         if (is_array($value)) {
             $cleaned = self::cleanItemAttributes($value);
             $item = new csNavigationItem();
             $item->name = $key;
             $item->level = $level;
             $item->fromArray($cleaned['attributes']);
             if ($commit) {
                 $item->save();
                 $item->getNode()->insertAsLastChildOf($root);
             }
             if ($cleaned['children']) {
                 $item = self::getNavigationBranchFromYaml($item, $cleaned['children'], $commit, $level + 1);
             }
         } else {
             $item = new csNavigationItem();
             $item->name = $key;
             $item->route = $value;
             $item->level = $level;
             if ($commit) {
                 $root->getNode()->addChild($item);
             }
         }
         $root->addItem($item);
     }
     return $root;
 }