Source for file category.php
Documentation is available at category.php
* @subpackage com_content
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* This models supports retrieving a category, the articles associated with the category,
* sibling, child and parent categories.
* @subpackage com_content
protected $_context =
'com_content.category';
* The category that applies.
* The list of other newfeed categories.
* @param array An optional associative array of configuration settings.
if (empty($config['filter_fields']))
$config['filter_fields'] =
array(
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'catid', 'a.catid', 'category_title',
'access', 'a.access', 'access_level',
'created_by', 'a.created_by',
'modified', 'a.modified',
'ordering', 'a.ordering',
'featured', 'a.featured',
'language', 'a.language',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
protected function populateState($ordering =
null, $direction =
null)
$pk =
$app->input->getInt('id');
// Load the parameters. Merge Global and Menu Item params into new object
$params =
$app->getParams();
if ($menu =
$app->getMenu()->getActive())
$menuParams->loadString($menu->params);
$mergedParams =
clone $menuParams;
$mergedParams->merge($params);
$this->setState('params', $mergedParams);
// Create a new query object.
$query =
$db->getQuery(true);
if ((!$user->authorise('core.edit.state', 'com_content')) &&
(!$user->authorise('core.edit', 'com_content'))){
// limit to published for people who can't edit or edit.state.
// Filter by start and end dates.
$nullDate =
$db->quote($db->getNullDate());
$query->where('(a.publish_up = ' .
$nullDate .
' OR a.publish_up <= ' .
$nowDate .
')')
->where('(a.publish_down = ' .
$nullDate .
' OR a.publish_down >= ' .
$nowDate .
')');
$this->setState('filter.published', array(0, 1, 2));
// process show_noauth parameter
if (!$params->get('show_noauth'))
$this->setState('filter.access', false);
$this->setState('list.filter', $app->input->getString('filter-search'));
$itemid =
$app->input->get('id', 0, 'int') .
':' .
$app->input->get('Itemid', 0, 'int');
$orderCol =
$app->getUserStateFromRequest('com_content.category.list.' .
$itemid .
'.filter_order', 'filter_order', '', 'string');
$orderCol =
'a.ordering';
$this->setState('list.ordering', $orderCol);
$listOrder =
$app->getUserStateFromRequest('com_content.category.list.' .
$itemid .
'.filter_order_Dir',
'filter_order_Dir', '', 'cmd');
$this->setState('list.direction', $listOrder);
$this->setState('list.start', $app->input->get('limitstart', 0, 'uint'));
// set limit for query. If list, use parameter. If blog, add blog parameters for limit.
if (($app->input->get('layout') ==
'blog') ||
$params->get('layout_type') ==
'blog')
$limit =
$params->get('num_leading_articles') +
$params->get('num_intro_articles') +
$params->get('num_links');
$this->setState('list.links', $params->get('num_links'));
$limit =
$app->getUserStateFromRequest('com_content.category.list.' .
$itemid .
'.limit', 'limit', $params->get('display_num'), 'uint');
// set the depth of the category query based on parameter
$showSubcategories =
$params->get('show_subcategory_content', '0');
$this->setState('filter.max_category_levels', $params->get('show_subcategory_content', '1'));
$this->setState('filter.subcategories', true);
$this->setState('layout', $app->input->get('layout'));
* Get the articles in the category
* @return mixed An array of articles or false if an error occurs.
$model->setState('filter.category_id', $category->id);
$model->setState('filter.published', $this->getState('filter.published'));
$model->setState('filter.access', $this->getState('filter.access'));
$model->setState('filter.language', $this->getState('filter.language'));
$model->setState('list.start', $this->getState('list.start'));
$model->setState('list.limit', $limit);
$model->setState('list.direction', $this->getState('list.direction'));
$model->setState('list.filter', $this->getState('list.filter'));
// filter.subcategories indicates whether to include articles from subcategories in the list or blog
$model->setState('filter.subcategories', $this->getState('filter.subcategories'));
$model->setState('filter.max_category_levels', $this->setState('filter.max_category_levels'));
$model->setState('list.links', $this->getState('list.links'));
$this->_pagination =
$model->getPagination();
* Build the orderby for the query
* @return string $orderby portion of query
$params =
$this->state->params;
$itemid =
$app->input->get('id', 0, 'int') .
':' .
$app->input->get('Itemid', 0, 'int');
$orderCol =
$app->getUserStateFromRequest('com_content.category.list.' .
$itemid .
'.filter_order', 'filter_order', '', 'string');
$orderDirn =
$app->getUserStateFromRequest('com_content.category.list.' .
$itemid .
'.filter_order_Dir', 'filter_order_Dir', '', 'cmd');
if ($orderCol &&
$orderDirn)
$orderby .=
$db->escape($orderCol) .
' ' .
$db->escape($orderDirn) .
', ';
$articleOrderby =
$params->get('orderby_sec', 'rdate');
$articleOrderDate =
$params->get('order_date');
$categoryOrderby =
$params->def('orderby_pri', '');
$orderby .=
$primary .
' ' .
$secondary .
' a.created ';
if (empty($this->_pagination))
return $this->_pagination;
* Method to get category data for the current category
* @param integer An optional ID
if ( isset
( $this->state->params ) )
$params =
$this->state->params;
$options['countItems'] =
$params->get('show_cat_num_articles', 1) ||
!$params->get('show_empty_categories_cat', 0);
$options['countItems'] =
0;
$this->_item =
$categories->get($this->getState('category.id', 'root'));
// Compute selected asset permissions.
$asset =
'com_content.category.'.
$this->_item->id;
// Check general create permission.
if ($user->authorise('core.create', $asset))
$this->_item->getParams()->set('access-create', true);
// TODO: Why aren't we lazy loading the children and siblings?
if ($this->_item->getParent())
$this->_rightsibling =
$this->_item->getSibling();
$this->_leftsibling =
$this->_item->getSibling(false);
* Get the parent category.
* @param integer An optional category id. If not supplied, the model state 'category.id' will be used.
* @return mixed An array of categories or false if an error occurs.
* Get the left sibling (adjacent) categories.
* @return mixed An array of categories or false if an error occurs.
return $this->_leftsibling;
* Get the right sibling (adjacent) categories.
* @return mixed An array of categories or false if an error occurs.
return $this->_rightsibling;
* Get the child categories.
* @param integer An optional category id. If not supplied, the model state 'category.id' will be used.
* @return mixed An array of categories or false if an error occurs.
$params =
$this->getState()->get('params');
if ($params->get('orderby_pri') ==
'alpha' ||
$params->get('orderby_pri') ==
'ralpha')
jimport('joomla.utilities.arrayhelper');
* Increment the hit counter for the category.
* @param int $pk Optional primary key of the category to increment.
* @return boolean True if successful; false otherwise and internal error set.
public function hit($pk =
0)
$hitcount =
$input->getInt('hitcount', 1);
$pk =
(!empty($pk)) ?
$pk : (int)
$this->getState('category.id');
Documentation generated on Tue, 19 Nov 2013 14:55:26 +0100 by phpDocumentor 1.4.3