/** * 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]); } } }
/** * Create navigation children * * @param int $parentId * @param int $navId * @param mixed $content * @param int $depth * @param boolean $cat * @return void */ protected function createNavChildren($parentId, $navId, $content, $depth = 0, $cat = false) { $child = $cat ? \Phire\Categories\Table\Categories::findBy(['parent_id' => $content->id], ['order' => 'order ASC']) : \Phire\Content\Table\Content::findBy(['parent_id' => $content->id], ['order' => 'order ASC']); if ($child->hasRows()) { foreach ($child->rows() as $c) { if (isset($c->status) && $c->status == 1 || !isset($c->status)) { $item = new Table\NavigationItems(['navigation_id' => $navId, 'parent_id' => $parentId, 'item_id' => $c->id, 'type' => $cat ? 'category' : 'content', 'name' => $c->title, 'href' => $cat ? '/category' . $c->uri : $c->uri, 'order' => 0]); $item->save(); $this->createNavChildren($item->id, $navId, $c, $depth + 1, $cat); } } } }