Beispiel #1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Category
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->uri) {
         // Check for dupe name
         $content = Table\Categories::findBy(['uri' => $this->uri]);
         if (isset($content->id) && $this->id != $content->id) {
             $this->getElement('uri')->addValidator(new Validator\NotEqual($this->uri, 'That URI already exists.'));
         }
     }
     return $this;
 }
 /**
  * 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]);
         }
     }
 }
Beispiel #3
0
 /**
  * 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) : '';
 }
Beispiel #4
0
 /**
  * Init category nav and categories
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function init(AbstractController $controller, Application $application)
 {
     if (!$_POST && $controller->hasView()) {
         $category = new Model\Category();
         $category->show_total = $application->module('phire-categories')['show_total'];
         $category->filters = $application->module('phire-categories')['filters'];
         $category->datetime_formats = $application->module('phire-categories')['datetime_formats'];
         $controller->view()->category_nav = $category->getNav($application->module('phire-categories')['nav_config']);
         if ($application->isRegistered('phire-templates') && $controller->view()->isStream() && (strpos($controller->view()->getTemplate()->getTemplate(), '[{category_') !== false || strpos($controller->view()->getTemplate()->getTemplate(), '[{categories_') !== false)) {
             $catIds = self::parseCategoryIds($controller->view()->getTemplate()->getTemplate());
             $catParentIds = self::parseParentCategoryIds($controller->view()->getTemplate()->getTemplate());
             if (count($catIds) > 0) {
                 foreach ($catIds as $key => $value) {
                     $category->getById($value['id']);
                     $categoryName = 'category_' . $value['id'];
                     if (isset($value['limit']) && $value['limit'] > 0 && $category->hasPages($value['limit'])) {
                         $limit = $value['limit'];
                         $categoryName .= '_' . $limit;
                         $pages = null;
                     } else {
                         if ($category->pagination > 0 && $category->hasPages($category->pagination)) {
                             $limit = $category->pagination;
                             $pages = new \Pop\Paginator\Paginator($category->getCount(), $limit);
                             $pages->useInput(true);
                         } else {
                             $limit = null;
                             $pages = null;
                         }
                     }
                     if (null !== $pages) {
                         $controller->view()->pages = $pages;
                     }
                     $controller->view()->{$categoryName} = $category->getItems($limit, $controller->request()->getQuery('page'));
                 }
             }
             if (count($catParentIds) > 0) {
                 foreach ($catParentIds as $key => $value) {
                     if (isset($value['limit']) && $value['limit'] > 0) {
                         $limit = $value['limit'];
                         $categoryName = 'categories_' . $value['id'] . '_' . $limit;
                     } else {
                         $limit = null;
                         $categoryName = 'categories_' . $value['id'];
                     }
                     $controller->view()->{$categoryName} = $category->getCategoryChildren($value['id'], $limit);
                 }
             }
         } else {
             if (($controller instanceof \Phire\Content\Controller\IndexController || $controller instanceof \Phire\Categories\Controller\IndexController) && $controller->view()->isFile()) {
                 $controller->view()->phire->category = $category;
             }
         }
         if (($controller instanceof \Phire\Content\Controller\ContentController || $controller instanceof \Phire\Media\Controller\IndexController) && $application->router()->getRouteMatch()->getAction()) {
             $categories = [];
             $cats = Table\Categories::findAll();
             foreach ($cats->rows() as $cat) {
                 $categories[$cat->id] = $cat->title;
             }
             $controller->view()->categories = $categories;
         }
     }
 }
 /**
  * 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);
             }
         }
     }
 }
 /**
  * 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']);
 }
 /**
  * Get navigation children
  *
  * @param  \ArrayObject|array $content
  * @param  int                $depth
  * @param  boolean            $cat
  * @return array
  */
 protected function getNavChildren($content, $depth = 0, $cat = false)
 {
     $children = [];
     $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) {
             $branch = ['id' => $c->id, 'type' => $cat ? 'category' : 'content', 'name' => $c->title, 'href' => $c->uri, 'children' => isset($c->status) && $c->status == 1 || !isset($c->status) ? $this->getNavChildren($c, $depth + 1) : []];
             if (isset($c->roles)) {
                 $roles = unserialize($c->roles);
                 if (count($roles) > 0) {
                     $branch['acl'] = ['resource' => 'content-' . $c->id];
                 }
             }
             if (isset($c->status) && $c->status == 1 || !isset($c->status)) {
                 $children[] = $branch;
             }
         }
     }
     return $children;
 }
 /**
  * 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);
         }
     }
 }