/** * Render pages for group view * * @param string $name * @param string $table * @param array $conds * @return mixed */ public function renderPages($name, $table = null, array $conds = []) { if (is_numeric($name)) { $this->getById($name); } else { $this->getByName($name); } if (isset($this->data['models'][0]) && isset($this->data['models'][0]['model'])) { $model = $this->data['models'][0]['model']; if (null !== $this->data['models'][0]['type_field'] && null !== $this->data['models'][0]['type_value']) { $params = [str_replace('type_id', 'typeId', $this->data['models'][0]['type_field']) => $this->data['models'][0]['type_value']]; if (null !== $table) { $objects = \Phire\Fields\Model\FieldValue::getModelObjectsFromTable($table, $model, $params, [], $conds); } else { $objects = \Phire\Fields\Model\FieldValue::getModelObjects($model, $params); } if (count($objects) > $this->data['pagination']) { $limit = $this->data['pagination']; $pages = new \Pop\Paginator\Paginator(count($objects), $limit); $pages->useInput(true); return $pages; } else { return null; } } else { return null; } } else { return null; } }
/** * 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); } }