/**
  * Index action method
  *
  * @return void
  */
 public function index()
 {
     $uri = substr($this->request->getRequestUri(), 9);
     if ($uri != '/') {
         if (substr($uri, -1) == '/') {
             $uri = substr($uri, 0, -1);
         }
         $category = new Model\Category();
         $category->getByUri($uri);
         if (isset($category->id)) {
             $category->filters = $category->filter ? $this->application->module('phire-categories')['filters'] : [];
             $category->show_total = $this->application->module('phire-categories')['show_total'];
             $category->datetime_formats = $this->application->module('phire-categories')['datetime_formats'];
             if ($category->pagination > 0 && $category->hasPages($category->pagination)) {
                 $limit = $category->pagination;
                 $pages = new Paginator($category->getCount(), $limit);
                 $pages->useInput(true);
             } else {
                 $limit = null;
                 $pages = null;
             }
             $this->prepareView('categories-public/category.phtml');
             $this->template = 'category.phtml';
             $this->view->title = 'Category : ' . $category->title;
             $this->view->category_id = $category->id;
             $this->view->category_title = $category->title;
             $this->view->category_slug = $category->slug;
             $this->view->category_nav = $category->getNav($this->application->module('phire-categories')['nav_config']);
             $this->view->pages = $pages;
             $this->view->category_breadcrumb = $category->getBreadcrumb($category->id, $this->application->module('phire-categories')['separator']);
             $this->view->items = $category->getItems($limit, $this->request->getQuery('page'));
             $this->send();
         } else {
             $this->error();
         }
     } else {
         $this->redirect(BASE_PATH == '' ? '/' : BASE_PATH);
     }
 }
Example #2
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;
         }
     }
 }