/**
* Method with common display elements used in category list displays
*
* @return void
*
* @since 3.2
*/
public function commonCategoryDisplay()
{
$app = Factory::getApplication();
$user = Factory::getUser();
$params = $app->getParams();
// Get some data from the models
$model = $this->getModel();
$paramsModel = $model->getState('params');
$paramsModel->set('check_access_rights', 0);
$model->setState('params', $paramsModel);
$state = $this->get('State');
$category = $this->get('Category');
$children = $this->get('Children');
$parent = $this->get('Parent');
if ($category == false) {
throw new \InvalidArgumentException(Text::_('JGLOBAL_CATEGORY_NOT_FOUND'), 404);
}
if ($parent == false) {
throw new \InvalidArgumentException(Text::_('JGLOBAL_CATEGORY_NOT_FOUND'), 404);
}
// Check whether category access level allows access.
$groups = $user->getAuthorisedViewLevels();
if (!\in_array($category->access, $groups)) {
throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
}
$items = $this->get('Items');
$pagination = $this->get('Pagination');
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// Setup the category parameters.
$cparams = $category->getParams();
$category->params = clone $params;
$category->params->merge($cparams);
$children = array($category->id => $children);
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
if ($this->runPlugins) {
PluginHelper::importPlugin('content');
foreach ($items as $itemElement) {
$itemElement = (object) $itemElement;
$itemElement->event = new \stdClass();
// For some plugins.
!empty($itemElement->description) ? $itemElement->text = $itemElement->description : ($itemElement->text = '');
Factory::getApplication()->triggerEvent('onContentPrepare', [$this->extension . '.category', &$itemElement, &$itemElement->params, 0]);
$results = Factory::getApplication()->triggerEvent('onContentAfterTitle', [$this->extension . '.category', &$itemElement, &$itemElement->core_params, 0]);
$itemElement->event->afterDisplayTitle = trim(implode("\n", $results));
$results = Factory::getApplication()->triggerEvent('onContentBeforeDisplay', [$this->extension . '.category', &$itemElement, &$itemElement->core_params, 0]);
$itemElement->event->beforeDisplayContent = trim(implode("\n", $results));
$results = Factory::getApplication()->triggerEvent('onContentAfterDisplay', [$this->extension . '.category', &$itemElement, &$itemElement->core_params, 0]);
$itemElement->event->afterDisplayContent = trim(implode("\n", $results));
if ($itemElement->text) {
$itemElement->description = $itemElement->text;
}
}
}
$maxLevel = $params->get('maxLevel', -1) < 0 ? PHP_INT_MAX : $params->get('maxLevel', PHP_INT_MAX);
$this->maxLevel =& $maxLevel;
$this->state =& $state;
$this->items =& $items;
$this->category =& $category;
$this->children =& $children;
$this->params =& $params;
$this->parent =& $parent;
$this->pagination =& $pagination;
$this->user =& $user;
// Check for layout override only if this is not the active menu item
// If it is the active menu item, then the view and category id will match
$active = $app->getMenu()->getActive();
if ($active && $active->component == $this->extension && isset($active->query['view'], $active->query['id']) && $active->query['view'] === 'category' && $active->query['id'] == $this->category->id) {
if (isset($active->query['layout'])) {
$this->setLayout($active->query['layout']);
}
$this->menuItemMatchCategory = true;
} elseif ($layout = $category->params->get('category_layout')) {
$this->setLayout($layout);
}
$this->category->tags = new TagsHelper();
$this->category->tags->getItemTags($this->extension . '.category', $this->category->id);
}