/** * 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 instanceof \Phire\Content\Form\Content) { $title = $controller->view()->form->title; $uri = $controller->view()->form->uri; $id = $controller->view()->id; $roles = isset($_POST['roles']) ? $_POST['roles'] : null; $navigation = Table\Navigation::findAll(); foreach ($navigation->rows() as $nav) { $tree = null !== $nav->tree ? unserialize($nav->tree) : []; if (count($tree) > 0) { self::traverseTree($tree, $id, $title, $uri, 'content', $roles); $revisedNav = Table\Navigation::findById($nav->id); if (isset($revisedNav->id)) { $revisedNav->tree = serialize($tree); $revisedNav->save(); } } } } else { if ($_POST && $application->isRegistered('phire-categories') && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form instanceof \Phire\Categories\Form\Category) { $title = $controller->view()->form->title; $uri = '/category' . $controller->view()->form->uri; $id = $controller->view()->id; $navigation = Table\Navigation::findAll(); foreach ($navigation->rows() as $nav) { $tree = null !== $nav->tree ? unserialize($nav->tree) : []; if (count($tree) > 0) { self::traverseTree($tree, $id, $title, $uri, 'category'); $revisedNav = Table\Navigation::findById($nav->id); if (isset($revisedNav->id)) { $revisedNav->tree = serialize($tree); $revisedNav->save(); } } } } } }
/** * Remove a navigation * * @param array $fields * @return void */ public function remove(array $fields) { if (isset($fields['rm_navigation'])) { foreach ($fields['rm_navigation'] as $id) { $navigation = Table\Navigation::findById((int) $id); if (isset($navigation->id)) { $navigation->delete(); } } } }