[ 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_templates 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\Templates\Administrator\Model; 12 13 use Joomla\CMS\Application\ApplicationHelper; 14 use Joomla\CMS\Component\ComponentHelper; 15 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 16 use Joomla\CMS\MVC\Model\ListModel; 17 use Joomla\Component\Templates\Administrator\Helper\TemplatesHelper; 18 use Joomla\Database\ParameterType; 19 use Joomla\String\StringHelper; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * Methods supporting a list of template extension records. 27 * 28 * @since 1.6 29 */ 30 class TemplatesModel extends ListModel 31 { 32 /** 33 * Constructor. 34 * 35 * @param array $config An optional associative array of configuration settings. 36 * @param MVCFactoryInterface $factory The factory. 37 * 38 * @see \Joomla\CMS\MVC\Model\BaseDatabaseModel 39 * @since 3.2 40 */ 41 public function __construct($config = array(), MVCFactoryInterface $factory = null) 42 { 43 if (empty($config['filter_fields'])) { 44 $config['filter_fields'] = array( 45 'id', 'a.id', 46 'name', 'a.name', 47 'folder', 'a.folder', 48 'element', 'a.element', 49 'checked_out', 'a.checked_out', 50 'checked_out_time', 'a.checked_out_time', 51 'state', 'a.state', 52 'enabled', 'a.enabled', 53 'ordering', 'a.ordering', 54 ); 55 } 56 57 parent::__construct($config, $factory); 58 } 59 60 /** 61 * Override parent getItems to add extra XML metadata. 62 * 63 * @return array 64 * 65 * @since 1.6 66 */ 67 public function getItems() 68 { 69 $items = parent::getItems(); 70 71 foreach ($items as &$item) { 72 $client = ApplicationHelper::getClientInfo($item->client_id); 73 $item->xmldata = TemplatesHelper::parseXMLTemplateFile($client->path, $item->element); 74 $num = $this->updated($item->extension_id); 75 76 if ($num) { 77 $item->updated = $num; 78 } 79 } 80 81 return $items; 82 } 83 84 /** 85 * Check if template extension have any updated override. 86 * 87 * @param integer $exid Extension id of template. 88 * 89 * @return boolean False if records not found/else integer. 90 * 91 * @since 4.0.0 92 */ 93 public function updated($exid) 94 { 95 $db = $this->getDatabase(); 96 97 // Select the required fields from the table 98 $query = $db->getQuery(true) 99 ->select($db->quoteName('template')) 100 ->from($db->quoteName('#__template_overrides')) 101 ->where($db->quoteName('extension_id') . ' = :extensionid') 102 ->where($db->quoteName('state') . ' = 0') 103 ->bind(':extensionid', $exid, ParameterType::INTEGER); 104 105 // Reset the query. 106 $db->setQuery($query); 107 108 // Load the results as a list of stdClass objects. 109 $num = count($db->loadObjectList()); 110 111 if ($num > 0) { 112 return $num; 113 } 114 115 return false; 116 } 117 118 /** 119 * Build an SQL query to load the list data. 120 * 121 * @return \Joomla\Database\DatabaseQuery 122 * 123 * @since 1.6 124 */ 125 protected function getListQuery() 126 { 127 // Create a new query object. 128 $db = $this->getDatabase(); 129 $query = $db->getQuery(true); 130 131 // Select the required fields from the table. 132 $query->select( 133 $this->getState( 134 'list.select', 135 'a.extension_id, a.name, a.element, a.client_id' 136 ) 137 ); 138 $clientId = (int) $this->getState('client_id'); 139 $query->from($db->quoteName('#__extensions', 'a')) 140 ->where($db->quoteName('a.client_id') . ' = :clientid') 141 ->where($db->quoteName('a.enabled') . ' = 1') 142 ->where($db->quoteName('a.type') . ' = ' . $db->quote('template')) 143 ->bind(':clientid', $clientId, ParameterType::INTEGER); 144 145 // Filter by search in title. 146 if ($search = $this->getState('filter.search')) { 147 if (stripos($search, 'id:') === 0) { 148 $ids = (int) substr($search, 3); 149 $query->where($db->quoteName('a.id') . ' = :id'); 150 $query->bind(':id', $ids, ParameterType::INTEGER); 151 } else { 152 $search = '%' . StringHelper::strtolower($search) . '%'; 153 $query->extendWhere( 154 'AND', 155 [ 156 'LOWER(' . $db->quoteName('a.element') . ') LIKE :element', 157 'LOWER(' . $db->quoteName('a.name') . ') LIKE :name', 158 ], 159 'OR' 160 ) 161 ->bind(':element', $search) 162 ->bind(':name', $search); 163 } 164 } 165 166 // Add the list ordering clause. 167 $query->order($db->escape($this->getState('list.ordering', 'a.element')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); 168 169 return $query; 170 } 171 172 /** 173 * Method to get a store id based on model configuration state. 174 * 175 * This is necessary because the model is used by the component and 176 * different modules that might need different sets of data or different 177 * ordering requirements. 178 * 179 * @param string $id A prefix for the store id. 180 * 181 * @return string A store id. 182 * 183 * @since 1.6 184 */ 185 protected function getStoreId($id = '') 186 { 187 // Compile the store id. 188 $id .= ':' . $this->getState('client_id'); 189 $id .= ':' . $this->getState('filter.search'); 190 191 return parent::getStoreId($id); 192 } 193 194 /** 195 * Method to auto-populate the model state. 196 * 197 * Note. Calling getState in this method will result in recursion. 198 * 199 * @param string $ordering An optional ordering field. 200 * @param string $direction An optional direction (asc|desc). 201 * 202 * @return void 203 * 204 * @since 1.6 205 */ 206 protected function populateState($ordering = 'a.element', $direction = 'asc') 207 { 208 // Load the filter state. 209 $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); 210 211 // Special case for the client id. 212 $clientId = (int) $this->getUserStateFromRequest($this->context . '.client_id', 'client_id', 0, 'int'); 213 $clientId = (!in_array($clientId, array (0, 1))) ? 0 : $clientId; 214 $this->setState('client_id', $clientId); 215 216 // Load the parameters. 217 $params = ComponentHelper::getParams('com_templates'); 218 $this->setState('params', $params); 219 220 // List state information. 221 parent::populateState($ordering, $direction); 222 } 223 }
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 |