Source for file articles.php
Documentation is available at articles.php
* @package Joomla.Administrator
* @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
* Methods supporting a list of article records.
* @package Joomla.Administrator
* @subpackage com_content
* @param array $config 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',
'created_by_alias', 'a.created_by_alias',
'ordering', 'a.ordering',
'featured', 'a.featured',
'language', 'a.language',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'published', 'a.published',
$config['filter_fields'][] =
'association';
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
protected function populateState($ordering =
null, $direction =
null)
// Adjust the context to support modal layouts.
if ($layout =
$app->input->get('layout'))
$this->setState('filter.search', $search);
$this->setState('filter.access', $access);
$authorId =
$app->getUserStateFromRequest($this->context .
'.filter.author_id', 'filter_author_id');
$this->setState('filter.author_id', $authorId);
$this->setState('filter.published', $published);
$this->setState('filter.category_id', $categoryId);
$this->setState('filter.level', $level);
$this->setState('filter.language', $language);
// List state information.
$forcedLanguage =
$app->input->get('forcedLanguage');
if (!empty($forcedLanguage))
$this->setState('filter.language', $forcedLanguage);
$this->setState('filter.forcedLanguage', $forcedLanguage);
* Method to get a store id based on model configuration state.
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* @param string $id A prefix for the store id.
* @return string A store id.
$id .=
':' .
$this->getState('filter.search');
$id .=
':' .
$this->getState('filter.access');
$id .=
':' .
$this->getState('filter.published');
$id .=
':' .
$this->getState('filter.category_id');
$id .=
':' .
$this->getState('filter.author_id');
$id .=
':' .
$this->getState('filter.language');
* Build an SQL query to load the list data.
// Create a new query object.
$query =
$db->getQuery(true);
// Select the required fields from the table.
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.ordering, a.featured, a.language, a.hits' .
', a.publish_up, a.publish_down'
$query->from('#__content AS a');
// Join over the language
$query->select('l.title AS language_title')
->join('LEFT', $db->quoteName('#__languages') .
' AS l ON l.lang_code = a.language');
// Join over the users for the checked out user.
$query->select('uc.name AS editor')
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
// Join over the asset groups.
$query->select('ag.title AS access_level')
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
// Join over the categories.
$query->select('c.title AS category_title')
->join('LEFT', '#__categories AS c ON c.id = a.catid');
// Join over the users for the author.
$query->select('ua.name AS author_name')
->join('LEFT', '#__users AS ua ON ua.id = a.created_by');
// Join over the associations.
$query->select('COUNT(asso2.id)>1 as association')
->join('LEFT', '#__associations AS asso ON asso.id = a.id AND asso.context=' .
$db->quote('com_content.item'))
->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')
// Filter by access level.
if ($access =
$this->getState('filter.access'))
$query->where('a.access = ' . (int)
$access);
// Implement View Level Access
if (!$user->authorise('core.admin'))
$groups =
implode(',', $user->getAuthorisedViewLevels());
$query->where('a.access IN (' .
$groups .
')');
// Filter by published state
$published =
$this->getState('filter.published');
$query->where('a.state = ' . (int)
$published);
elseif ($published ===
'')
$query->where('(a.state = 0 OR a.state = 1)');
// Filter by a single or group of categories.
$categoryId =
$this->getState('filter.category_id');
$cat_tbl->load($categoryId);
$baselevel = (int)
$cat_tbl->level;
$query->where('c.lft >= ' . (int)
$lft)
->where('c.rgt <= ' . (int)
$rgt);
$categoryId =
implode(',', $categoryId);
$query->where('a.catid IN (' .
$categoryId .
')');
if ($level =
$this->getState('filter.level'))
$query->where('c.level <= ' .
((int)
$level + (int)
$baselevel -
1));
$authorId =
$this->getState('filter.author_id');
$type =
$this->getState('filter.author_id.include', true) ?
'= ' :
'<>';
$query->where('a.created_by ' .
$type . (int)
$authorId);
// Filter by search in title.
$search =
$this->getState('filter.search');
$query->where('a.id = ' . (int)
substr($search, 3));
elseif (stripos($search, 'author:') ===
0)
$search =
$db->quote('%' .
$db->escape(substr($search, 7), true) .
'%');
$query->where('(ua.name LIKE ' .
$search .
' OR ua.username LIKE ' .
$search .
')');
$search =
$db->quote('%' .
$db->escape($search, true) .
'%');
$query->where('(a.title LIKE ' .
$search .
' OR a.alias LIKE ' .
$search .
')');
// Filter on the language.
if ($language =
$this->getState('filter.language'))
$query->where('a.language = ' .
$db->quote($language));
// Filter by a single tag.
$query->where($db->quoteName('tagmap.tag_id') .
' = ' . (int)
$tagId)
'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap')
.
' ON ' .
$db->quoteName('tagmap.content_item_id') .
' = ' .
$db->quoteName('a.id')
.
' AND ' .
$db->quoteName('tagmap.type_alias') .
' = ' .
$db->quote('com_content.article')
// Add the list ordering clause.
$orderCol =
$this->state->get('list.ordering', 'a.title');
$orderDirn =
$this->state->get('list.direction', 'asc');
if ($orderCol ==
'a.ordering' ||
$orderCol ==
'category_title')
$orderCol =
'c.title ' .
$orderDirn .
', a.ordering';
if ($orderCol ==
'language')
if ($orderCol ==
'access_level')
$query->order($db->escape($orderCol .
' ' .
$orderDirn));
* Build a list of authors
// Create a new query object.
$query =
$db->getQuery(true);
$query->select('u.id AS value, u.name AS text')
->join('INNER', '#__content AS c ON c.created_by = u.id')
return $db->loadObjectList();
* Method to get a list of articles.
* Overridden to add a check for access levels.
* @return mixed An array of data items on success, false on failure.
$groups =
$user->getAuthorisedViewLevels();
for ($x =
0, $count =
count($items); $x <
$count; $x++
)
// Check the access level. Remove articles the user shouldn't see
if (!in_array($items[$x]->access, $groups))
Documentation generated on Tue, 19 Nov 2013 14:54:01 +0100 by phpDocumentor 1.4.3