/** * Metodo para eliminar un MenuItem a partir de su Id * adem�s, borra los elementos dependientes * @param int $idMenuItem */ private function deleteRecursiveById($idMenuItem) { $menuItemCatalog = $this->getCatalog("MenuItemCatalog"); $childs = Query\MenuItemQuery::create()->whereAdd(Bean\MenuItem::ID_PARENT, $idMenuItem)->find(); $childs->each(function (Bean\MenuItem $menuItem) use($menuItemCatalog) { $menuItemCatalog->deleteById($menuItem->getIdMenuItem()); }); $menuItemCatalog->deleteById($idMenuItem); }
/** * Obtiene los items * @param int $idParent * @param Array $prepend (Un arreglo para agregar antes del resultado ) * @return Array */ private function getMenuItemsByIdParent($idParent, $prepend = array()) { $return = $prepend; $items = MenuItemQuery::create()->whereAdd(MenuItem::ID_PARENT, $idParent, is_null($idParent) ? MenuItemQuery::IS_NULL : MenuItemQuery::EQUAL)->addAscendingOrderBy(MenuItem::ORDER)->find(); while ($items->valid()) { $item = $items->read(); $controller = $this->getControllerURI($item->getIdAction()); $action = $this->getActionURI($item->getIdAction()); $tmp = array('order' => $item->getOrder(), 'label' => $item->getName(), 'controller' => $controller, 'action' => $action, 'idMenuItem' => $item->getIdMenuItem(), 'pages' => $this->getMenuItemsByIdParent($item->getIdMenuItem())); if ($action && $controller) { $tmp['resource'] = $controller . '/' . $action; } $return[] = $tmp; } return $return; }