Source for file categories.php
Documentation is available at categories.php
* @package Joomla.Administrator
* @subpackage com_categories
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Categories Component Categories Model
* @package Joomla.Administrator
* @subpackage com_categories
* @param array $config An optional associative array of configuration settings.
if (empty($config['filter_fields']))
$config['filter_fields'] =
array(
'published', 'a.published',
'access', 'a.access', 'access_level',
'language', 'a.language',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'created_time', 'a.created_time',
'created_user_id', 'a.created_user_id',
* 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)
$extension =
$app->getUserStateFromRequest('com_categories.categories.filter.extension', 'extension', 'com_content', 'cmd');
$this->setState('filter.extension', $extension);
// Extract the component name
$this->setState('filter.component', $parts[0]);
// Extract the optional section name
$this->setState('filter.section', (count($parts) >
1) ?
$parts[1] :
null);
$this->setState('filter.search', $search);
$this->setState('filter.level', $level);
$this->setState('filter.access', $access);
$this->setState('filter.published', $published);
$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.extension');
$id .=
':' .
$this->getState('filter.published');
$id .=
':' .
$this->getState('filter.language');
// Create a new query object.
$query =
$db->getQuery(true);
// Select the required fields from the table.
'a.id, a.title, a.alias, a.note, a.published, a.access' .
', a.checked_out, a.checked_out_time, a.created_user_id' .
', a.path, a.parent_id, a.level, a.lft, a.rgt' .
$query->from('#__categories 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 users for the author.
$query->select('ua.name AS author_name')
->join('LEFT', '#__users AS ua ON ua.id = a.created_user_id');
// 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_categories.item'))
->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')
if ($extension =
$this->getState('filter.extension'))
$query->where('a.extension = ' .
$db->quote($extension));
if ($level =
$this->getState('filter.level'))
$query->where('a.level <= ' . (int)
$level);
// 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.published = ' . (int)
$published);
elseif ($published ===
'')
$query->where('(a.published IN (0, 1))');
// 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 .
' OR a.note 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($extension .
'.category')
// Add the list ordering clause
$listOrdering =
$this->getState('list.ordering', 'a.lft');
$listDirn =
$db->escape($this->getState('list.direction', 'ASC'));
if ($listOrdering ==
'a.access')
$query->order('a.access ' .
$listDirn .
', a.lft ' .
$listDirn);
$query->order($db->escape($listOrdering) .
' ' .
$listDirn);
//echo nl2br(str_replace('#__','jos_',$query));
* Method to determine if an association exists
* @return boolean True if the association exists
$extension =
$this->getState('filter.extension');
$extension =
explode('.', $extension);
$component =
array_shift($extension);
$cname =
str_replace('com_', '', $component);
if (!$assoc ||
!$component ||
!$cname)
$hname =
$cname .
'HelperAssociation';
$assoc =
class_exists($hname) &&
!empty($hname::$category_association);
Documentation generated on Tue, 19 Nov 2013 14:55:06 +0100 by phpDocumentor 1.4.3