| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 * 6 * @package Joomla.Administrator 7 * @subpackage com_menus 8 */ 9 10 // no direct access 11 defined('_JEXEC') or die; 12 13 jimport('joomla.application.component.modellist'); 14 15 /** 16 * Menu List Model for Menus. 17 * 18 * @package Joomla.Administrator 19 * @subpackage com_menus 20 * @since 1.6 21 */ 22 class MenusModelMenus extends JModelList 23 { 24 /** 25 * Constructor. 26 * 27 * @param array An optional associative array of configuration settings. 28 * 29 * @see JController 30 * @since 1.6 31 */ 32 public function __construct($config = array()) 33 { 34 if (empty($config['filter_fields'])) 35 { 36 $config['filter_fields'] = array( 37 'id', 'a.id', 38 'title', 'a.title', 39 'menutype', 'a.menutype', 40 ); 41 } 42 43 parent::__construct($config); 44 } 45 46 /** 47 * Overrides the getItems method to attach additional metrics to the list. 48 * 49 * @return mixed An array of data items on success, false on failure. 50 * 51 * @since 1.6.1 52 */ 53 public function getItems() 54 { 55 // Get a storage key. 56 $store = $this->getStoreId('getItems'); 57 58 // Try to load the data from internal storage. 59 if (!empty($this->cache[$store])) 60 { 61 return $this->cache[$store]; 62 } 63 64 // Load the list items. 65 $items = parent::getItems(); 66 67 // If emtpy or an error, just return. 68 if (empty($items)) 69 { 70 return array(); 71 } 72 73 // Getting the following metric by joins is WAY TOO SLOW. 74 // Faster to do three queries for very large menu trees. 75 76 // Get the menu types of menus in the list. 77 $db = $this->getDbo(); 78 $menuTypes = JArrayHelper::getColumn($items, 'menutype'); 79 80 // Quote the strings. 81 $menuTypes = implode( 82 ',', 83 array_map(array($db, 'quote'), $menuTypes) 84 ); 85 86 // Get the published menu counts. 87 $query = $db->getQuery(true) 88 ->select('m.menutype, COUNT(DISTINCT m.id) AS count_published') 89 ->from('#__menu AS m') 90 ->where('m.published = 1') 91 ->where('m.menutype IN ('.$menuTypes.')') 92 ->group('m.menutype') 93 ; 94 $db->setQuery($query); 95 $countPublished = $db->loadAssocList('menutype', 'count_published'); 96 97 if ($db->getErrorNum()) 98 { 99 $this->setError($db->getErrorMsg()); 100 return false; 101 } 102 103 // Get the unpublished menu counts. 104 $query->clear('where') 105 ->where('m.published = 0') 106 ->where('m.menutype IN ('.$menuTypes.')'); 107 $db->setQuery($query); 108 $countUnpublished = $db->loadAssocList('menutype', 'count_published'); 109 110 if ($db->getErrorNum()) 111 { 112 $this->setError($db->getErrorMsg()); 113 return false; 114 } 115 116 // Get the trashed menu counts. 117 $query->clear('where') 118 ->where('m.published = -2') 119 ->where('m.menutype IN ('.$menuTypes.')'); 120 $db->setQuery($query); 121 $countTrashed = $db->loadAssocList('menutype', 'count_published'); 122 123 if ($db->getErrorNum()) 124 { 125 $this->setError($db->getErrorMsg()); 126 return false; 127 } 128 129 // Inject the values back into the array. 130 foreach ($items as $item) 131 { 132 $item->count_published = isset($countPublished[$item->menutype]) ? $countPublished[$item->menutype] : 0; 133 $item->count_unpublished = isset($countUnpublished[$item->menutype]) ? $countUnpublished[$item->menutype] : 0; 134 $item->count_trashed = isset($countTrashed[$item->menutype]) ? $countTrashed[$item->menutype] : 0; 135 } 136 137 // Add the items to the internal cache. 138 $this->cache[$store] = $items; 139 140 return $this->cache[$store]; 141 } 142 143 /** 144 * Method to build an SQL query to load the list data. 145 * 146 * @return string An SQL query 147 * 148 * @since 1.6 149 */ 150 protected function getListQuery() 151 { 152 // Create a new query object. 153 $db = $this->getDbo(); 154 $query = $db->getQuery(true); 155 156 // Select all fields from the table. 157 $query->select($this->getState('list.select', 'a.*')); 158 $query->from($db->quoteName('#__menu_types').' AS a'); 159 160 161 $query->group('a.id, a.menutype, a.title, a.description'); 162 163 // Add the list ordering clause. 164 $query->order($db->escape($this->getState('list.ordering', 'a.id')).' '.$db->escape($this->getState('list.direction', 'ASC'))); 165 166 return $query; 167 } 168 169 /** 170 * Method to auto-populate the model state. 171 * 172 * Note. Calling getState in this method will result in recursion. 173 * 174 * @param string $ordering An optional ordering field. 175 * @param string $direction An optional direction (asc|desc). 176 * 177 * @return void 178 * 179 * @since 1.6 180 */ 181 protected function populateState($ordering = null, $direction = null) 182 { 183 // Initialise variables. 184 $app = JFactory::getApplication('administrator'); 185 186 // List state information. 187 parent::populateState('a.id', 'asc'); 188 } 189 190 /** 191 * Gets the extension id of the core mod_menu module. 192 * 193 * @return integer 194 * 195 * @since 2.5 196 */ 197 public function getModMenuId() 198 { 199 $db = $this->getDbo(); 200 $query = $db->getQuery(true); 201 202 $query->select('e.extension_id') 203 ->from('#__extensions AS e') 204 ->where('e.type = ' . $db->quote('module')) 205 ->where('e.element = ' . $db->quote('mod_menu')) 206 ->where('e.client_id = 0'); 207 $db->setQuery($query); 208 209 return $db->loadResult(); 210 } 211 212 /** 213 * Gets a list of all mod_mainmenu modules and collates them by menutype 214 * 215 * @return array 216 */ 217 public function &getModules() 218 { 219 $model = JModel::getInstance('Menu', 'MenusModel', array('ignore_request' => true)); 220 $result = &$model->getModules(); 221 222 return $result; 223 } 224 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |