Beispiel #1
0
 /**
  * Get all category values for the form object
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function parseCategories(AbstractController $controller, Application $application)
 {
     if ($controller->hasView() && ($controller instanceof \Phire\Categories\Controller\IndexController || $controller instanceof \Phire\Content\Controller\IndexController)) {
         $body = $controller->response()->getBody();
         $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'];
         $catIds = self::parseCategoryIds($body);
         $catParentIds = self::parseParentCategoryIds($body);
         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'];
                     $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);
             }
         }
         $controller->view()->setTemplate($body);
         $body = $controller->view()->render();
         $controller->response()->setBody($body);
     }
 }
Beispiel #2
0
 /**
  * Get category items
  *
  * @param  mixed $id
  * @param  int   $limit
  * @return array
  */
 public function getCategoryChildren($id, $limit = null)
 {
     if (!is_numeric($id)) {
         $category = Table\Categories::findBy(['title' => $id]);
         if (isset($category->id)) {
             $id = $category->id;
         }
     }
     $options = ['order' => 'order ASC'];
     if (null !== $limit) {
         $options['limit'] = (int) $limit;
     }
     $children = Table\Categories::findBy(['parent_id' => $id], $options);
     $items = [];
     if ($children->hasRows()) {
         foreach ($children->rows() as $child) {
             $c = new Category();
             $c->show_total = $this->show_total;
             $c->filters = $this->filters;
             $c->getById($child->id);
             $childItem = $c->getItems(1);
             $filtered = [];
             if (isset($childItem[0])) {
                 foreach ($childItem[0] as $key => $value) {
                     $filtered['item_' . $key] = $value;
                 }
             }
             $items[] = new \ArrayObject(array_merge(['category_id' => $child->id, 'category_title' => $child->title, 'category_uri' => '/category' . $child->uri, 'category_total' => Table\CategoryItems::findBy(['category_id' => $child->id])->count()], $filtered), \ArrayObject::ARRAY_AS_PROPS);
         }
     }
     return $items;
 }
 /**
  * View action method
  *
  * @param  int $id
  * @return void
  */
 public function viewContent($id)
 {
     $category = new Model\Category();
     $category->getById($id);
     if (!isset($category->id)) {
         $this->redirect(BASE_PATH . APP_URI . '/categories');
     }
     $category->filters = $this->application->module('phire-categories')['filters'];
     $category->show_total = $this->application->module('phire-categories')['show_total'];
     $this->prepareView('categories/view.phtml');
     $this->view->title = 'Categories : ' . $category->title;
     $this->view->cid = $category->id;
     $this->view->items = $category->getCategoryViewItems($id);
     $this->send();
 }