[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_banners 6 * 7 * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Banners\Administrator\Model; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\MVC\Model\ListModel; 15 use Joomla\CMS\Table\Table; 16 use Joomla\Database\ParameterType; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Methods supporting a list of banner records. 24 * 25 * @since 1.6 26 */ 27 class BannersModel extends ListModel 28 { 29 /** 30 * Constructor. 31 * 32 * @param array $config An optional associative array of configuration settings. 33 * 34 * @since 1.6 35 */ 36 public function __construct($config = array()) 37 { 38 if (empty($config['filter_fields'])) { 39 $config['filter_fields'] = array( 40 'id', 'a.id', 41 'cid', 'a.cid', 'client_name', 42 'name', 'a.name', 43 'alias', 'a.alias', 44 'state', 'a.state', 45 'ordering', 'a.ordering', 46 'language', 'a.language', 47 'catid', 'a.catid', 'category_title', 48 'checked_out', 'a.checked_out', 49 'checked_out_time', 'a.checked_out_time', 50 'created', 'a.created', 51 'impmade', 'a.impmade', 52 'imptotal', 'a.imptotal', 53 'clicks', 'a.clicks', 54 'publish_up', 'a.publish_up', 55 'publish_down', 'a.publish_down', 56 'sticky', 'a.sticky', 57 'client_id', 58 'category_id', 59 'published', 60 'level', 'c.level', 61 ); 62 } 63 64 parent::__construct($config); 65 } 66 67 /** 68 * Method to get the maximum ordering value for each category. 69 * 70 * @return array 71 * 72 * @since 1.6 73 */ 74 public function &getCategoryOrders() 75 { 76 if (!isset($this->cache['categoryorders'])) { 77 $db = $this->getDatabase(); 78 $query = $db->getQuery(true) 79 ->select( 80 [ 81 'MAX(' . $db->quoteName('ordering') . ') AS ' . $db->quoteName('max'), 82 $db->quoteName('catid'), 83 ] 84 ) 85 ->from($db->quoteName('#__banners')) 86 ->group($db->quoteName('catid')); 87 $db->setQuery($query); 88 $this->cache['categoryorders'] = $db->loadAssocList('catid', 0); 89 } 90 91 return $this->cache['categoryorders']; 92 } 93 94 /** 95 * Build an SQL query to load the list data. 96 * 97 * @return \Joomla\Database\DatabaseQuery 98 * 99 * @since 1.6 100 */ 101 protected function getListQuery() 102 { 103 $db = $this->getDatabase(); 104 $query = $db->getQuery(true); 105 106 // Select the required fields from the table. 107 $query->select( 108 $this->getState( 109 'list.select', 110 [ 111 $db->quoteName('a.id'), 112 $db->quoteName('a.name'), 113 $db->quoteName('a.alias'), 114 $db->quoteName('a.checked_out'), 115 $db->quoteName('a.checked_out_time'), 116 $db->quoteName('a.catid'), 117 $db->quoteName('a.clicks'), 118 $db->quoteName('a.metakey'), 119 $db->quoteName('a.sticky'), 120 $db->quoteName('a.impmade'), 121 $db->quoteName('a.imptotal'), 122 $db->quoteName('a.state'), 123 $db->quoteName('a.ordering'), 124 $db->quoteName('a.purchase_type'), 125 $db->quoteName('a.language'), 126 $db->quoteName('a.publish_up'), 127 $db->quoteName('a.publish_down'), 128 ] 129 ) 130 ) 131 ->select( 132 [ 133 $db->quoteName('l.title', 'language_title'), 134 $db->quoteName('l.image', 'language_image'), 135 $db->quoteName('uc.name', 'editor'), 136 $db->quoteName('c.title', 'category_title'), 137 $db->quoteName('cl.name', 'client_name'), 138 $db->quoteName('cl.purchase_type', 'client_purchase_type'), 139 ] 140 ) 141 ->from($db->quoteName('#__banners', 'a')) 142 ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language')) 143 ->join('LEFT', $db->quoteName('#__users', 'uc'), $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out')) 144 ->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid')) 145 ->join('LEFT', $db->quoteName('#__banner_clients', 'cl'), $db->quoteName('cl.id') . ' = ' . $db->quoteName('a.cid')); 146 147 // Filter by published state 148 $published = (string) $this->getState('filter.published'); 149 150 if (is_numeric($published)) { 151 $published = (int) $published; 152 $query->where($db->quoteName('a.state') . ' = :published') 153 ->bind(':published', $published, ParameterType::INTEGER); 154 } elseif ($published === '') { 155 $query->where($db->quoteName('a.state') . ' IN (0, 1)'); 156 } 157 158 // Filter by category. 159 $categoryId = $this->getState('filter.category_id'); 160 161 if (is_numeric($categoryId)) { 162 $categoryId = (int) $categoryId; 163 $query->where($db->quoteName('a.catid') . ' = :categoryId') 164 ->bind(':categoryId', $categoryId, ParameterType::INTEGER); 165 } 166 167 // Filter by client. 168 $clientId = $this->getState('filter.client_id'); 169 170 if (is_numeric($clientId)) { 171 $clientId = (int) $clientId; 172 $query->where($db->quoteName('a.cid') . ' = :clientId') 173 ->bind(':clientId', $clientId, ParameterType::INTEGER); 174 } 175 176 // Filter by search in title 177 if ($search = $this->getState('filter.search')) { 178 if (stripos($search, 'id:') === 0) { 179 $search = (int) substr($search, 3); 180 $query->where($db->quoteName('a.id') . ' = :search') 181 ->bind(':search', $search, ParameterType::INTEGER); 182 } else { 183 $search = '%' . str_replace(' ', '%', trim($search)) . '%'; 184 $query->where('(' . $db->quoteName('a.name') . ' LIKE :search1 OR ' . $db->quoteName('a.alias') . ' LIKE :search2)') 185 ->bind([':search1', ':search2'], $search); 186 } 187 } 188 189 // Filter on the language. 190 if ($language = $this->getState('filter.language')) { 191 $query->where($db->quoteName('a.language') . ' = :language') 192 ->bind(':language', $language); 193 } 194 195 // Filter on the level. 196 if ($level = (int) $this->getState('filter.level')) { 197 $query->where($db->quoteName('c.level') . ' <= :level') 198 ->bind(':level', $level, ParameterType::INTEGER); 199 } 200 201 // Add the list ordering clause. 202 $orderCol = $this->state->get('list.ordering', 'a.name'); 203 $orderDirn = $this->state->get('list.direction', 'ASC'); 204 205 if ($orderCol === 'a.ordering' || $orderCol === 'category_title') { 206 $ordering = [ 207 $db->quoteName('c.title') . ' ' . $db->escape($orderDirn), 208 $db->quoteName('a.ordering') . ' ' . $db->escape($orderDirn), 209 ]; 210 } else { 211 if ($orderCol === 'client_name') { 212 $orderCol = 'cl.name'; 213 } 214 215 $ordering = $db->escape($orderCol) . ' ' . $db->escape($orderDirn); 216 } 217 218 $query->order($ordering); 219 220 return $query; 221 } 222 223 /** 224 * Method to get a store id based on model configuration state. 225 * 226 * This is necessary because the model is used by the component and 227 * different modules that might need different sets of data or different 228 * ordering requirements. 229 * 230 * @param string $id A prefix for the store id. 231 * 232 * @return string A store id. 233 * 234 * @since 1.6 235 */ 236 protected function getStoreId($id = '') 237 { 238 // Compile the store id. 239 $id .= ':' . $this->getState('filter.search'); 240 $id .= ':' . $this->getState('filter.published'); 241 $id .= ':' . $this->getState('filter.category_id'); 242 $id .= ':' . $this->getState('filter.client_id'); 243 $id .= ':' . $this->getState('filter.language'); 244 $id .= ':' . $this->getState('filter.level'); 245 246 return parent::getStoreId($id); 247 } 248 249 /** 250 * Returns a reference to the a Table object, always creating it. 251 * 252 * @param string $type The table type to instantiate 253 * @param string $prefix A prefix for the table class name. Optional. 254 * @param array $config Configuration array for model. Optional. 255 * 256 * @return Table A Table object 257 * 258 * @since 1.6 259 */ 260 public function getTable($type = 'Banner', $prefix = 'Administrator', $config = array()) 261 { 262 return parent::getTable($type, $prefix, $config); 263 } 264 265 /** 266 * Method to auto-populate the model state. 267 * 268 * Note. Calling getState in this method will result in recursion. 269 * 270 * @param string $ordering An optional ordering field. 271 * @param string $direction An optional direction (asc|desc). 272 * 273 * @return void 274 * 275 * @since 1.6 276 */ 277 protected function populateState($ordering = 'a.name', $direction = 'asc') 278 { 279 // Load the parameters. 280 $this->setState('params', ComponentHelper::getParams('com_banners')); 281 282 // List state information. 283 parent::populateState($ordering, $direction); 284 } 285 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |