/** * 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 parental hierarchy * * @param int $parentId * @return string */ protected function getHierarchy($parentId = null) { $parents = []; while (null !== $parentId) { array_unshift($parents, $parentId); $category = Table\Categories::findById($parentId); if (isset($category->id)) { $parentId = $category->parent_id; } } return count($parents) > 0 ? implode('|', $parents) : ''; }
/** * JSON action method * * @param int $id * @param string $type * @return void */ public function json($id, $type = null) { $json = []; if (null !== $type) { $findBy = $type == 'media' ? ['content_id' => null, 'media_id' => $id] : ['content_id' => $id, 'media_id' => null]; $catItems = Table\CategoryItems::findBy($findBy); foreach ($catItems->rows() as $c) { if ($c->order > 0) { $json['category_order_' . $c->category_id] = $c->order; } } } else { $json['parent_uri'] = ''; $content = Table\Categories::findById($id); if (isset($content->id)) { $json['parent_uri'] = $content->uri; } } $this->response->setBody(json_encode($json, JSON_PRETTY_PRINT)); $this->send(200, ['Content-Type' => 'application/json']); }
/** * Traverse tree for updates * * @param array $tree * @param int $id * @param string $title * @param string $uri * @param string $type * @param mixed $roles * @param int $depth * @return void */ public static function traverseTree(&$tree, $id, $title, $uri, $type, $roles = null, $depth = 0) { foreach ($tree as &$branch) { if (isset($branch['id']) && isset($branch['type']) && $branch['id'] == $id && $branch['type'] == $type) { $branch['name'] = $title; $branch['href'] = $uri; if (null !== $roles && is_array($roles) && count($roles) > 0) { $branch['acl'] = ['resource' => 'content-' . $id]; } else { if (isset($branch['acl'])) { unset($branch['acl']); } } } else { $c = $type == 'category' ? \Phire\Categories\Table\Categories::findById($branch['id']) : \Phire\Content\Table\Content::findById($branch['id']); if (isset($c->id)) { $branch['href'] = $c->uri; } } if (isset($branch['children']) && count($branch['children']) > 0) { self::traverseTree($branch['children'], $id, $title, $uri, $type, $roles, $depth + 1); } } }