/** * Update an existing tag * * @param array $fields * @return void */ public function update(array $fields) { $tag = Table\Tags::findById((int) $fields['id']); if (isset($tag->id)) { $tag->title = $fields['title']; $tag->slug = Slug::filter($fields['title']); $tag->save(); $this->data = array_merge($this->data, $tag->getColumns()); } }
/** * Set the navigation objects * * @param AbstractController $controller * @param Application $application * @return void */ public static function getNavigation(AbstractController $controller, Application $application) { if ($application->isRegistered('phire-categories') && $controller instanceof \Phire\Categories\Controller\IndexController || $application->isRegistered('phire-content') && $controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView()) { $navigation = Table\Navigation::findAll(); foreach ($navigation->rows() as $nav) { $tree = (new Model\Navigation())->getTree($nav->id); $slug = Slug::filter($nav->title); $name = str_replace('-', '_', $slug); $topId = empty($nav->top_id) ? $slug : $nav->top_id; $config = []; if (!empty($nav->on_class)) { $config['on'] = $nav->on_class; } if (!empty($nav->off_class)) { $config['off'] = $nav->off_class; } $config['top'] = ['id' => $topId]; if (!empty($nav->top_node)) { $config['top']['node'] = $nav->top_node; } if (!empty($nav->top_class)) { $config['top']['class'] = $nav->top_class; } if (!empty($nav->top_attributes)) { $attribs = explode('" ', $nav->top_attributes); $attribAry = []; foreach ($attribs as $att) { $val = explode('="', $att); $attribAry[trim($val[0])] = trim($val[1]); } $config['top']['attributes'] = $attribAry; } if (!empty($nav->parent_node)) { if (!isset($config['parent'])) { $config['parent'] = []; } $config['parent']['node'] = $nav->parent_node; } if (!empty($nav->parent_id)) { if (!isset($config['parent'])) { $config['parent'] = []; } $config['parent']['id'] = $nav->parent_id; } if (!empty($nav->parent_class)) { if (!isset($config['parent'])) { $config['parent'] = []; } $config['parent']['class'] = $nav->parent_class; } if (!empty($nav->parent_attributes)) { if (!isset($config['parent'])) { $config['parent'] = []; } $attribs = explode('" ', $nav->parent_attributes); $attribAry = []; foreach ($attribs as $att) { $val = explode('="', $att); $attribAry[trim($val[0])] = trim($val[1]); } $config['parent']['attributes'] = $attribAry; } if (!empty($nav->child_node)) { if (!isset($config['child'])) { $config['child'] = []; } $config['child']['node'] = $nav->child_node; } if (!empty($nav->child_id)) { if (!isset($config['child'])) { $config['child'] = []; } $config['child']['id'] = $nav->child_id; } if (!empty($nav->child_class)) { if (!isset($config['child'])) { $config['child'] = []; } $config['child']['class'] = $nav->child_class; } if (!empty($nav->child_attributes)) { if (!isset($config['child'])) { $config['child'] = []; } $attribs = explode('" ', $nav->child_attributes); $attribAry = []; foreach ($attribs as $att) { $val = explode('="', $att); $attribAry[trim($val[0])] = trim($val[1]); } $config['child']['attributes'] = $attribAry; } if (!empty($nav->indent)) { $config['indent'] = str_repeat(' ', (int) $nav->indent); } if ($application->isRegistered('phire-content')) { $sess = $application->services()->get('session'); $roleId = isset($sess->user) && isset($sess->user->role_id) ? $sess->user->role_id : null; self::checkTreeStatus($tree, $roleId); } $navObject = new Nav($tree, $config); $controller->view()->set($name, $navObject); } } }
/** * Save tag relationships * * @param AbstractController $controller * @param Application $application * @return void */ public static function save(AbstractController $controller, Application $application) { $contentId = null; if ($_POST && $controller->hasView() && null !== $controller->view()->id && null !== $controller->view()->form && $controller->view()->form !== false && $controller->view()->form instanceof \Pop\Form\Form) { $tags = $controller->view()->form->content_tags; $contentId = $controller->view()->id; if (null !== $contentId) { $c2t = new Table\TagItems(); $c2t->delete(['content_id' => $contentId]); } if (!empty($tags)) { $tags = explode(',', $tags); foreach ($tags as $tag) { $tag = trim($tag); $t = Table\Tags::findBy(['title' => $tag]); if (!isset($t->id)) { $t = new Table\Tags(['title' => $tag, 'slug' => Slug::filter($tag)]); $t->save(); } $c2t = new Table\TagItems(['content_id' => $contentId, 'tag_id' => $t->id]); $c2t->save(); } } } }