| [ 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 7 // No direct access. 8 defined('_JEXEC') or die; 9 10 jimport('joomla.application.component.modellist'); 11 12 /** 13 * Modules Component Positions Model 14 * 15 * @package Joomla.Administrator 16 * @subpackage com_modules 17 * @since 1.6 18 */ 19 class ModulesModelPositions extends JModelList 20 { 21 /** 22 * Constructor. 23 * 24 * @param array An optional associative array of configuration settings. 25 * @see JController 26 * @since 1.6 27 */ 28 public function __construct($config = array()) 29 { 30 if (empty($config['filter_fields'])) { 31 $config['filter_fields'] = array( 32 'value', 33 'templates', 34 ); 35 } 36 37 parent::__construct($config); 38 } 39 40 /** 41 * Method to auto-populate the model state. 42 * 43 * Note. Calling getState in this method will result in recursion. 44 * 45 * @since 1.6 46 */ 47 protected function populateState($ordering = null, $direction = null) 48 { 49 // Initialise variables. 50 $app = JFactory::getApplication('administrator'); 51 52 // Load the filter state. 53 $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); 54 $this->setState('filter.search', $search); 55 56 $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string'); 57 $this->setState('filter.state', $state); 58 59 $clientId = JRequest::getInt('client_id', 0); 60 $this->setState('filter.client_id', $clientId); 61 62 $template = $this->getUserStateFromRequest($this->context.'.filter.template', 'filter_template', '', 'string'); 63 $this->setState('filter.template', $template); 64 65 $type = $this->getUserStateFromRequest($this->context.'.filter.type', 'filter_type', '', 'string'); 66 $this->setState('filter.type', $type); 67 68 // Load the parameters. 69 $params = JComponentHelper::getParams('com_modules'); 70 $this->setState('params', $params); 71 72 // List state information. 73 parent::populateState('value', 'asc'); 74 } 75 76 /** 77 * Method to get an array of data items. 78 * 79 * @return mixed An array of data items on success, false on failure. 80 * @since 1.6 81 */ 82 public function getItems() 83 { 84 if (!isset($this->items)) 85 { 86 $lang = JFactory::getLanguage(); 87 $search = $this->getState('filter.search'); 88 $state = $this->getState('filter.state'); 89 $clientId = $this->getState('filter.client_id'); 90 $filter_template = $this->getState('filter.template'); 91 $type = $this->getState('filter.type'); 92 $ordering = $this->getState('list.ordering'); 93 $direction = $this->getState('list.direction'); 94 $limitstart = $this->getState('list.start'); 95 $limit = $this->getState('list.limit'); 96 $client = JApplicationHelper::getClientInfo($clientId); 97 98 if ($type!='template') 99 { 100 // Get the database object and a new query object. 101 $query = $this->_db->getQuery(true); 102 $query->select('DISTINCT(position) as value'); 103 $query->from('#__modules'); 104 $query->where($this->_db->quoteName('client_id').' = '.(int) $clientId); 105 if ($search) { 106 $query->where('position LIKE '.$this->_db->Quote('%'.$this->_db->escape($search, true).'%')); 107 } 108 109 $this->_db->setQuery($query); 110 $positions = $this->_db->loadObjectList('value'); 111 // Check for a database error. 112 if ($error = $this->_db->getErrorMsg()) { 113 $this->setError($error); 114 return false; 115 } 116 foreach ($positions as $value=>$position) { 117 $positions[$value] = array(); 118 } 119 } 120 else 121 { 122 $positions=array(); 123 } 124 125 // Load the positions from the installed templates. 126 foreach (ModulesHelper::getTemplates($clientId) as $template) 127 { 128 $path = JPath::clean($client->path.'/templates/'.$template->element.'/templateDetails.xml'); 129 130 if (file_exists($path)) 131 { 132 $xml = simplexml_load_file($path); 133 if (isset($xml->positions[0])) 134 { 135 $lang->load('tpl_'.$template->element.'.sys', $client->path, null, false, false) 136 || $lang->load('tpl_'.$template->element.'.sys', $client->path.'/templates/'.$template->element, null, false, false) 137 || $lang->load('tpl_'.$template->element.'.sys', $client->path, $lang->getDefault(), false, false) 138 || $lang->load('tpl_'.$template->element.'.sys', $client->path.'/templates/'.$template->element, $lang->getDefault(), false, false); 139 foreach ($xml->positions[0] as $position) 140 { 141 $value = (string)$position['value']; 142 $label = (string)$position; 143 if (!$value) { 144 $value = $label; 145 $label = preg_replace('/[^a-zA-Z0-9_\-]/', '_', 'TPL_'.$template->element.'_POSITION_'.$value); 146 $altlabel = preg_replace('/[^a-zA-Z0-9_\-]/', '_', 'COM_MODULES_POSITION_'.$value); 147 if (!$lang->hasKey($label) && $lang->hasKey($altlabel)) { 148 $label = $altlabel; 149 } 150 } 151 if ($type=='user' || ($state!='' && $state!=$template->enabled)) { 152 unset($positions[$value]); 153 } 154 elseif (preg_match(chr(1).$search.chr(1).'i', $value) && ($filter_template=='' || $filter_template==$template->element)) { 155 if (!isset($positions[$value])) { 156 $positions[$value] = array(); 157 } 158 $positions[$value][$template->name]=$label; 159 } 160 } 161 } 162 } 163 } 164 $this->total = count($positions); 165 if ($limitstart >= $this->total) { 166 $limitstart = $limitstart < $limit ? 0 : $limitstart - $limit; 167 $this->setState('list.start', $limitstart); 168 } 169 if ($ordering == 'value') { 170 if ($direction == 'asc') { 171 ksort($positions); 172 } 173 else { 174 krsort($positions); 175 } 176 } 177 else { 178 if ($direction == 'asc') { 179 asort($positions); 180 } 181 else { 182 arsort($positions); 183 } 184 } 185 $this->items = array_slice($positions, $limitstart, $limit ? $limit : null); 186 } 187 return $this->items; 188 } 189 190 /** 191 * Method to get the total number of items. 192 * 193 * @return int The total number of items. 194 * @since 1.6 195 */ 196 public function getTotal() 197 { 198 if (!isset($this->total)) 199 { 200 $this->getItems(); 201 } 202 return $this->total; 203 } 204 }
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 |