| [ 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 defined('_JEXEC') or die; 8 9 jimport('joomla.application.component.modellist'); 10 11 /** 12 * Methods supporting a list of user access level records. 13 * 14 * @package Joomla.Administrator 15 * @subpackage com_users 16 * @since 1.6 17 */ 18 class UsersModelLevels extends JModelList 19 { 20 /** 21 * Constructor. 22 * 23 * @param array An optional associative array of configuration settings. 24 * @see JController 25 * @since 1.6 26 */ 27 public function __construct($config = array()) 28 { 29 if (empty($config['filter_fields'])) { 30 $config['filter_fields'] = array( 31 'id', 'a.id', 32 'title', 'a.title', 33 'ordering', 'a.ordering', 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 // Load the parameters. 57 $params = JComponentHelper::getParams('com_users'); 58 $this->setState('params', $params); 59 60 // List state information. 61 parent::populateState('a.title', 'asc'); 62 } 63 64 /** 65 * Method to get a store id based on model configuration state. 66 * 67 * This is necessary because the model is used by the component and 68 * different modules that might need different sets of data or different 69 * ordering requirements. 70 * 71 * @param string $id A prefix for the store id. 72 * 73 * @return string A store id. 74 */ 75 protected function getStoreId($id = '') 76 { 77 // Compile the store id. 78 $id .= ':'.$this->getState('filter.search'); 79 80 return parent::getStoreId($id); 81 } 82 83 /** 84 * Build an SQL query to load the list data. 85 * 86 * @return JDatabaseQuery 87 */ 88 protected function getListQuery() 89 { 90 // Create a new query object. 91 $db = $this->getDbo(); 92 $query = $db->getQuery(true); 93 94 // Select the required fields from the table. 95 $query->select( 96 $this->getState( 97 'list.select', 98 'a.*' 99 ) 100 ); 101 $query->from($db->quoteName('#__viewlevels').' AS a'); 102 103 // Add the level in the tree. 104 $query->group('a.id, a.title, a.ordering, a.rules'); 105 106 // Filter the items over the search string if set. 107 $search = $this->getState('filter.search'); 108 if (!empty($search)) { 109 if (stripos($search, 'id:') === 0) { 110 $query->where('a.id = '.(int) substr($search, 3)); 111 } else { 112 $search = $db->Quote('%'.$db->escape($search, true).'%'); 113 $query->where('a.title LIKE '.$search); 114 } 115 } 116 117 $query->group('a.id'); 118 119 // Add the list ordering clause. 120 $query->order($db->escape($this->getState('list.ordering', 'a.lft')).' '.$db->escape($this->getState('list.direction', 'ASC'))); 121 122 //echo nl2br(str_replace('#__','jos_',$query)); 123 return $query; 124 } 125 126 /** 127 * Method to adjust the ordering of a row. 128 * 129 * @param int The ID of the primary key to move. 130 * @param integer Increment, usually +1 or -1 131 * @return boolean False on failure or error, true otherwise. 132 */ 133 public function reorder($pk, $direction = 0) 134 { 135 // Sanitize the id and adjustment. 136 $pk = (!empty($pk)) ? $pk : (int) $this->getState('level.id'); 137 $user = JFactory::getUser(); 138 139 // Get an instance of the record's table. 140 $table = JTable::getInstance('viewlevel'); 141 142 // Load the row. 143 if (!$table->load($pk)) { 144 $this->setError($table->getError()); 145 return false; 146 } 147 148 // Access checks. 149 $allow = $user->authorise('core.edit.state', 'com_users'); 150 151 if (!$allow) 152 { 153 $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); 154 return false; 155 } 156 157 // Move the row. 158 // TODO: Where clause to restrict category. 159 $table->move($pk); 160 161 return true; 162 } 163 164 /** 165 * Saves the manually set order of records. 166 * 167 * @param array An array of primary key ids. 168 * @param int +/-1 169 */ 170 function saveorder($pks, $order) 171 { 172 // Initialise variables. 173 $table = JTable::getInstance('viewlevel'); 174 $user = JFactory::getUser(); 175 $conditions = array(); 176 177 if (empty($pks)) { 178 return JError::raiseWarning(500, JText::_('COM_USERS_ERROR_LEVELS_NOLEVELS_SELECTED')); 179 } 180 181 // update ordering values 182 foreach ($pks as $i => $pk) 183 { 184 $table->load((int) $pk); 185 186 // Access checks. 187 $allow = $user->authorise('core.edit.state', 'com_users'); 188 189 if (!$allow) 190 { 191 // Prune items that you can't change. 192 unset($pks[$i]); 193 JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); 194 } 195 elseif ($table->ordering != $order[$i]) 196 { 197 $table->ordering = $order[$i]; 198 if (!$table->store()) 199 { 200 $this->setError($table->getError()); 201 return false; 202 } 203 } 204 } 205 206 // Execute reorder for each category. 207 foreach ($conditions as $cond) 208 { 209 $table->load($cond[0]); 210 $table->reorder($cond[1]); 211 } 212 213 return true; 214 } 215 }
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 |