| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Administrator 4 * @subpackage com_users 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('_JEXEC') or die; 11 12 jimport('joomla.application.component.modellist'); 13 14 /** 15 * User notes model class. 16 * 17 * @package Joomla.Administrator 18 * @subpackage com_users 19 * @since 2.5 20 */ 21 class UsersModelNotes extends JModelList 22 { 23 /** 24 * Class constructor. 25 * 26 * @param array $config An optional associative array of configuration settings. 27 * 28 * @since 2.5 29 */ 30 public function __construct($config = array()) 31 { 32 // Set the list ordering fields. 33 if (empty($config['filter_fields'])) 34 { 35 $config['filter_fields'] = array( 36 'id', 37 'a.id', 38 'user_id', 39 'a.user_id', 40 'u.name', 41 'subject', 42 'a.subject', 43 'catid', 44 'a.catid', 45 'state', 'a.state', 46 'c.title', 47 'review_time', 48 'a.review_time', 49 'publish_up', 'a.publish_up', 50 'publish_down', 'a.publish_down', 51 ); 52 } 53 54 parent::__construct($config); 55 } 56 57 /** 58 * Build an SQL query to load the list data. 59 * 60 * @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set. 61 * 62 * @since 2.5 63 */ 64 protected function getListQuery() 65 { 66 // Initialise variables. 67 $db = $this->getDbo(); 68 $query = $db->getQuery(true); 69 $section = $this->getState('filter.category_id'); 70 71 // Select the required fields from the table. 72 $query->select( 73 $this->getState('list.select', 74 'a.id, a.subject, a.checked_out, a.checked_out_time,' . 75 'a.catid, a.created_time, a.review_time,' . 76 'a.state, a.publish_up, a.publish_down' 77 ) 78 ); 79 $query->from('#__user_notes AS a'); 80 81 // Join over the category 82 $query->select('c.title AS category_title, c.params AS category_params'); 83 $query->leftJoin('#__categories AS c ON c.id = a.catid'); 84 85 // Join over the users for the note user. 86 $query->select('u.name AS user_name'); 87 $query->leftJoin('#__users AS u ON u.id = a.user_id'); 88 89 // Join over the users for the checked out user. 90 $query->select('uc.name AS editor'); 91 $query->leftJoin('#__users AS uc ON uc.id = a.checked_out'); 92 93 // Filter by search in title 94 $search = $this->getState('filter.search'); 95 if (!empty($search)) 96 { 97 if (stripos($search, 'id:') === 0) 98 { 99 $query->where('a.id = ' . (int) substr($search, 3)); 100 } 101 elseif (stripos($search, 'uid:') === 0) 102 { 103 $query->where('a.user_id = ' . (int) substr($search, 4)); 104 } 105 else 106 { 107 $search = $db->Quote('%' . $db->escape($search, true) . '%'); 108 $query->where('(a.subject LIKE ' . $search . ')', 'OR'); 109 $query->where('(u.name LIKE ' . $search . ')', 'OR'); 110 $query->where('(u.username LIKE ' . $search . ')', 'OR'); 111 } 112 } 113 114 // Filter by published state 115 $published = $this->getState('filter.state'); 116 if (is_numeric($published)) { 117 $query->where('a.state = '.(int) $published); 118 } elseif ($published === '') { 119 $query->where('(a.state IN (0, 1))'); 120 } 121 122 // Filter by a single or group of categories. 123 $categoryId = (int) $this->getState('filter.category_id'); 124 if ($categoryId) 125 { 126 if (is_scalar($section)) 127 { 128 $query->where('a.catid = ' . $categoryId); 129 } 130 } 131 132 // Filter by a single user. 133 $userId = (int) $this->getState('filter.user_id'); 134 if ($userId) 135 { 136 // Add the body and where filter. 137 $query->select('a.body'); 138 $query->where('a.user_id = ' . $userId); 139 } 140 141 // Add the list ordering clause. 142 $orderCol = $this->state->get('list.ordering'); 143 $orderDirn = $this->state->get('list.direction'); 144 $query->order($db->escape($orderCol . ' ' . $orderDirn)); 145 146 return $query; 147 } 148 149 /** 150 * Method to get a store id based on model configuration state. 151 * 152 * This is necessary because the model is used by the component and 153 * different modules that might need different sets of data or different 154 * ordering requirements. 155 * 156 * @param string $id A prefix for the store id. 157 * 158 * @return string A store id. 159 * 160 * @since 2.5 161 */ 162 protected function getStoreId($id = '') 163 { 164 // Compile the store id. 165 $id .= ':' . $this->getState('filter.search'); 166 $id .= ':' . $this->getState('filter.state'); 167 $id .= ':' . $this->getState('filter.category_id'); 168 169 return parent::getStoreId($id); 170 } 171 172 /** 173 * Gets a user object if the user filter is set. 174 * 175 * @return JUser The JUser object 176 * 177 * @since 2.5 178 */ 179 public function getUser() 180 { 181 $user = new JUser; 182 183 // Filter by search in title 184 $search = JFactory::getApplication()->input->get('u_id', 0, 'int'); 185 if ($search != 0) 186 { 187 $user->load((int) $search); 188 } 189 190 return $user; 191 } 192 193 /** 194 * Method to auto-populate the model state. 195 * 196 * Note. Calling getState in this method will result in recursion. 197 * 198 * @return void 199 * 200 * @since 1.6 201 */ 202 protected function populateState($ordering = null, $direction = null) 203 { 204 // Initialise variables. 205 $app = JFactory::getApplication(); 206 $input = $app->input; 207 208 // Adjust the context to support modal layouts. 209 if ($layout = $input->get('layout')) 210 { 211 $this->context .= '.' . $layout; 212 } 213 214 $value = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); 215 $this->setState('filter.search', $value); 216 217 $published = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_published', '', 'string'); 218 $this->setState('filter.state', $published); 219 220 $section = $app->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id'); 221 $this->setState('filter.category_id', $section); 222 223 $userId = $input->get('u_id', 0, 'int'); 224 $this->setState('filter.user_id', $userId); 225 226 parent::populateState('a.review_time', 'DESC'); 227 } 228 }
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 |