/** * Update the navigation objects * * @param AbstractController $controller * @param Application $application * @return void */ public static function updateNavigation(AbstractController $controller, Application $application) { if ($_POST && $application->isRegistered('phire-content') && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Phire\Content\Form\Content) { $navItems = Table\NavigationItems::findBy(['type' => 'content']); foreach ($navItems->rows() as $item) { if (null !== $item->item_id) { $i = \Phire\Content\Table\Content::findById($item->item_id); if (isset($i->id)) { $n = Table\NavigationItems::findById($item->id); if (isset($n->id)) { $n->name = $i->title; $n->href = $i->uri; $n->save(); } } } } } else { if ($_POST && $application->isRegistered('phire-categories') && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Phire\Categories\Form\Category) { $navItems = Table\NavigationItems::findBy(['type' => 'category']); foreach ($navItems->rows() as $item) { if (null !== $item->item_id) { $i = \Phire\Categories\Table\Categories::findById($item->item_id); if (isset($i->id)) { $n = Table\NavigationItems::findById($item->id); if (isset($n->id)) { $n->name = $i->title; $n->href = '/category' . $i->uri; $n->save(); } } } } } } if ($_POST && isset($_POST['process_content']) && count($_POST['process_content']) > 0 && isset($_POST['content_process_action']) && $_POST['content_process_action'] == -3) { foreach ($_POST['process_content'] as $id) { $navItems = new Table\NavigationItems(); $navItems->delete(['type' => 'content', 'item_id' => $id]); } } if ($_POST && isset($_POST['rm_categories']) && count($_POST['rm_categories']) > 0) { foreach ($_POST['rm_categories'] as $id) { $navItems = new Table\NavigationItems(); $navItems->delete(['type' => 'category', 'item_id' => $id]); } } }
/** * Get navigation tree branch children * * @param int $id * @return array */ public function getBranchChildren($id, $parentId) { $branchChildren = []; $children = Table\NavigationItems::findBy(['navigation_id' => $id, 'parent_id' => $parentId], ['order' => 'order ASC']); foreach ($children->rows() as $child) { $branch = ['id' => $child->id, 'item_id' => $child->item_id, 'type' => $child->type, 'name' => $child->name, 'href' => $child->href, 'order' => $child->order, 'attributes' => null !== $child->attributes ? unserialize($child->attributes) : [], 'children' => $this->getBranchChildren($id, $child->id)]; $branchChildren[] = $branch; } return $branchChildren; }