/** * Add a child. * * @param Snep_Menu $child */ public function addChild(Snep_Menu $child) { $item = $this->getChildById($child->getId()); if ($item) { $item->setSubmenu(array_merge($item->getSubmenu(), $child->getSubmenu())); } else { $this->children[] = $child; } }
/** * Parses recursively the resources xml into Snep_Acl * * @param SimpleXMLElement $resources */ protected function loadResources(SimpleXMLElement $resources, $parent = null, $menu_parent = null) { $acl = Snep_Acl::getInstance(); $menu = Snep_Menu::getMasterInstance(); $baseUrl = Snep_Config::getConfig()->system->path->web; $menu_parent = $menu_parent === null ? $parent : $menu_parent; foreach ($resources as $element) { $id = (string) $element->attributes()->id; if ($id === null) { throw new Exception("Resource object must contain id attribute."); } if ($element->getName() == "resource") { $resname = $parent . "_" . $id; $acl->addResource($resname, $parent); if ($element->attributes()->order == "allow") { $acl->allow(null, $resname); } } else { $resname = $parent; } if ($element->attributes()->label !== null) { $menu_id = $menu_parent . "_" . $id; $menu_object = new Snep_Menu($menu_id); $menu_object->setLabel((string) $element->attributes()->label); $menu_object->setUri($baseUrl . "/index.php/" . str_replace("_", "/", $resname)); $menu_parent_obj = $menu->getChildById($menu_parent); if ($menu_parent_obj === null) { $menu_parent_obj = $menu; } $menu_parent_obj->addChild($menu_object); } else { $menu_id = $menu_parent; } if (count($element) > 0) { $this->loadResources($element, $resname, $menu_id); } } }