Source for file items.php
Documentation is available at items.php
* @package Joomla.Administrator
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Menu Item List Model for Menus.
* @package Joomla.Administrator
* @param array $config An optional associative array of configuration settings.
if (empty($config['filter_fields']))
$config['filter_fields'] =
array(
'menutype', 'a.menutype',
'published', 'a.published',
'access', 'a.access', 'access_level',
'language', 'a.language',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'client_id', 'a.client_id',
$config['filter_fields'][] =
'association';
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
protected function populateState($ordering =
null, $direction =
null)
$this->setState('filter.parent_id', $parentId);
$this->setState('filter.search', $search);
$this->setState('filter.published', $published);
$this->setState('filter.access', $access);
$this->setState('filter.parent_id', $parentId);
$this->setState('filter.level', $level);
$menuType =
$app->input->getString('menutype', null);
if ($menuType !=
$app->getUserState($this->context .
'.menutype'))
$app->setUserState($this->context .
'.menutype', $menuType);
$app->input->set('limitstart', 0);
$menuType =
$app->getUserState($this->context .
'.menutype');
$this->setState('filter.menutype', $menuType);
$this->setState('filter.language', $language);
// List state information.
* 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.access');
$id .=
':' .
$this->getState('filter.published');
$id .=
':' .
$this->getState('filter.language');
$id .=
':' .
$this->getState('filter.search');
$id .=
':' .
$this->getState('filter.parent_id');
$id .=
':' .
$this->getState('filter.menutype');
* Finds the default menu type.
* In the absence of better information, this is the first menu ordered by title.
* @return string The default menu type
// Create a new query object.
$query =
$db->getQuery(true)
$db->setQuery($query, 0, 1);
$menuType =
$db->loadResult();
* Builds an SQL query to load the list data.
* @return JDatabaseQuery A query object.
// Create a new query object.
$query =
$db->getQuery(true);
// Select all fields from the table.
array('a.id', 'a.menutype', 'a.title', 'a.alias', 'a.note', 'a.path', 'a.link', 'a.type', 'a.parent_id', 'a.level', 'a.published', 'a.component_id', 'a.checked_out', 'a.checked_out_time', 'a.browserNav', 'a.access', 'a.img', 'a.template_style_id', 'a.params', 'a.lft', 'a.rgt', 'a.home', 'a.language', 'a.client_id'),
array(null, null, null, null, null, null, null, null, null, null, 'apublished', null, null, null, null, null, null, null, null, null, null, null, null, null)
' WHEN ' .
$db->quote('component') .
' THEN a.published+2*(e.enabled-1) ' .
' WHEN ' .
$db->quote('url') .
' THEN a.published+2 ' .
' WHEN ' .
$db->quote('alias') .
' THEN a.published+4 ' .
' WHEN ' .
$db->quote('separator') .
' THEN a.published+6 ' .
' WHEN ' .
$db->quote('heading') .
' THEN a.published+8 ' .
$query->from($db->quoteName('#__menu') .
' AS a');
// Join over the language
$query->select('l.title AS language_title, l.image as image')
->join('LEFT', $db->quoteName('#__languages') .
' AS l ON l.lang_code = a.language');
$query->select('u.name AS editor')
->join('LEFT', $db->quoteName('#__users') .
' AS u ON u.id = a.checked_out');
$query->select('c.element AS componentname')
->join('LEFT', $db->quoteName('#__extensions') .
' AS c ON c.extension_id = a.component_id');
// 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 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_menus.item'))
->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')
// Join over the extensions
$query->select('e.name AS name')
->join('LEFT', '#__extensions AS e ON e.extension_id = a.component_id');
// Exclude the root category.
$query->where('a.id > 1')
->where('a.client_id = 0');
// Filter on the 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, alias or id
$query->where('a.id = ' . (int)
substr($search, 3));
elseif (stripos($search, 'link:') ===
0)
if ($search =
substr($search, 5))
$search =
$db->quote('%' .
$db->escape($search, true) .
'%');
$query->where('a.link 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 the items over the parent id if set.
$parentId =
$this->getState('filter.parent_id');
$query->where('p.id = ' . (int)
$parentId);
// Filter the items over the menu id if set.
$menuType =
$this->getState('filter.menutype');
$query->where('a.menutype = ' .
$db->quote($menuType));
// Filter on the 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 .
')');
if ($level =
$this->getState('filter.level'))
$query->where('a.level <= ' . (int)
$level);
// Filter on the language.
if ($language =
$this->getState('filter.language'))
$query->where('a.language = ' .
$db->quote($language));
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.lft')) .
' ' .
$db->escape($this->getState('list.direction', 'ASC')));
Documentation generated on Tue, 19 Nov 2013 15:06:01 +0100 by phpDocumentor 1.4.3