- md5
- 0024c4a8bd7a0be9758d9c18f3e21cbd
- sha1
- d825d4a34d8ce5dbc4ef9b95aee23bab58d82140
- sha256
- a7aeab97dd58a29467e0e1fbb05350748166599de11a83129a7a51369b0c26a2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
<?php
/**
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* @package Joomla.Administrator
* @subpackage com_menus
*/
// no direct access
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
* Menu List Model for Menus.
*
* @package Joomla.Administrator
* @subpackage com_menus
* @since 1.6
*/
class MenusModelMenus extends JModelList
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
*
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'title', 'a.title',
'menutype', 'a.menutype',
);
}
parent::__construct($config);
}
/**
* Overrides the getItems method to attach additional metrics to the list.
*
* @return mixed An array of data items on success, false on failure.
*
* @since 1.6.1
*/
public function getItems()
{
// Get a storage key.
$store = $this->getStoreId('getItems');
// Try to load the data from internal storage.
if (!empty($this->cache[$store]))
{
return $this->cache[$store];
}
// Load the list items.
$items = parent::getItems();
// If emtpy or an error, just return.
if (empty($items))
{
return array();
}
// Getting the following metric by joins is WAY TOO SLOW.
// Faster to do three queries for very large menu trees.
// Get the menu types of menus in the list.
$db = $this->getDbo();
$menuTypes = JArrayHelper::getColumn($items, 'menutype');
// Quote the strings.
$menuTypes = implode(
',',
array_map(array($db, 'quote'), $menuTypes)
);
// Get the published menu counts.
$query = $db->getQuery(true)
->select('m.menutype, COUNT(DISTINCT m.id) AS count_published')
->from('#__menu AS m')
->where('m.published = 1')
->where('m.menutype IN ('.$menuTypes.')')
->group('m.menutype')
;
$db->setQuery($query);
$countPublished = $db->loadAssocList('menutype', 'count_published');
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
// Get the unpublished menu counts.
$query->clear('where')
->where('m.published = 0')
->where('m.menutype IN ('.$menuTypes.')');
$db->setQuery($query);
$countUnpublished = $db->loadAssocList('menutype', 'count_published');
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
// Get the trashed menu counts.
$query->clear('where')
->where('m.published = -2')
->where('m.menutype IN ('.$menuTypes.')');
$db->setQuery($query);
$countTrashed = $db->loadAssocList('menutype', 'count_published');
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
// Inject the values back into the array.
foreach ($items as $item)
{
$item->count_published = isset($countPublished[$item->menutype]) ? $countPublished[$item->menutype] : 0;
$item->count_unpublished = isset($countUnpublished[$item->menutype]) ? $countUnpublished[$item->menutype] : 0;
$item->count_trashed = isset($countTrashed[$item->menutype]) ? $countTrashed[$item->menutype] : 0;
}
// Add the items to the internal cache.
$this->cache[$store] = $items;
return $this->cache[$store];
}
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*
* @since 1.6
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select all fields from the table.
$query->select($this->getState('list.select', 'a.*'));
$query->from($db->quoteName('#__menu_types').' AS a');
$query->group('a.id, a.menutype, a.title, a.description');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.id')).' '.$db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
/**
* 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).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication('administrator');
// List state information.
parent::populateState('a.id', 'asc');
}
/**
* Gets the extension id of the core mod_menu module.
*
* @return integer
*
* @since 2.5
*/
public function getModMenuId()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('e.extension_id')
->from('#__extensions AS e')
->where('e.type = ' . $db->quote('module'))
->where('e.element = ' . $db->quote('mod_menu'))
->where('e.client_id = 0');
$db->setQuery($query);
return $db->loadResult();
}
/**
* Gets a list of all mod_mainmenu modules and collates them by menutype
*
* @return array
*/
public function &getModules()
{
$model = JModelLegacy::getInstance('Menu', 'MenusModel', array('ignore_request' => true));
$result = &$model->getModules();
return $result;
}
}
The same content is in 11 releases, Joomla 2.5.18 to 2.5.28. See them all, or every version of this file.