[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_contact 6 * 7 * @copyright (C) 2010 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\Contact\Site\Model; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Multilanguage; 16 use Joomla\CMS\MVC\Model\ListModel; 17 use Joomla\Database\ParameterType; 18 use Joomla\Registry\Registry; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Featured contact model class. 26 * 27 * @since 1.6.0 28 */ 29 class FeaturedModel extends ListModel 30 { 31 /** 32 * Constructor. 33 * 34 * @param array $config An optional associative array of configuration settings. 35 * 36 * @since 1.6 37 */ 38 public function __construct($config = array()) 39 { 40 if (empty($config['filter_fields'])) { 41 $config['filter_fields'] = array( 42 'id', 'a.id', 43 'name', 'a.name', 44 'con_position', 'a.con_position', 45 'suburb', 'a.suburb', 46 'state', 'a.state', 47 'country', 'a.country', 48 'ordering', 'a.ordering', 49 ); 50 } 51 52 parent::__construct($config); 53 } 54 55 /** 56 * Method to get a list of items. 57 * 58 * @return mixed An array of objects on success, false on failure. 59 */ 60 public function getItems() 61 { 62 // Invoke the parent getItems method to get the main list 63 $items = parent::getItems(); 64 65 // Convert the params field into an object, saving original in _params 66 for ($i = 0, $n = count($items); $i < $n; $i++) { 67 $item = &$items[$i]; 68 69 if (!isset($this->_params)) { 70 $item->params = new Registry($item->params); 71 } 72 } 73 74 return $items; 75 } 76 77 /** 78 * Method to build an SQL query to load the list data. 79 * 80 * @return string An SQL query 81 * 82 * @since 1.6 83 */ 84 protected function getListQuery() 85 { 86 $user = Factory::getUser(); 87 $groups = $user->getAuthorisedViewLevels(); 88 89 // Create a new query object. 90 $db = $this->getDatabase(); 91 $query = $db->getQuery(true); 92 93 // Select required fields from the categories. 94 $query->select($this->getState('list.select', 'a.*')) 95 ->from($db->quoteName('#__contact_details', 'a')) 96 ->where($db->quoteName('a.featured') . ' = 1') 97 ->whereIn($db->quoteName('a.access'), $groups) 98 ->innerJoin($db->quoteName('#__categories', 'c') . ' ON c.id = a.catid') 99 ->whereIn($db->quoteName('c.access'), $groups); 100 101 // Filter by category. 102 if ($categoryId = $this->getState('category.id')) { 103 $query->where($db->quoteName('a.catid') . ' = :catid'); 104 $query->bind(':catid', $categoryId, ParameterType::INTEGER); 105 } 106 107 $query->select('c.published as cat_published, c.published AS parents_published') 108 ->where('c.published = 1'); 109 110 // Filter by state 111 $state = $this->getState('filter.published'); 112 113 if (is_numeric($state)) { 114 $query->where($db->quoteName('a.published') . ' = :published'); 115 $query->bind(':published', $state, ParameterType::INTEGER); 116 117 // Filter by start and end dates. 118 $nowDate = Factory::getDate()->toSql(); 119 120 $query->where('(' . $db->quoteName('a.publish_up') . 121 ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publish_up)') 122 ->where('(' . $db->quoteName('a.publish_down') . 123 ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publish_down)') 124 ->bind(':publish_up', $nowDate) 125 ->bind(':publish_down', $nowDate); 126 } 127 128 // Filter by search in title 129 $search = $this->getState('list.filter'); 130 131 // Filter by search in title 132 if (!empty($search)) { 133 $search = '%' . trim($search) . '%'; 134 $query->where($db->quoteName('a.name') . ' LIKE :name '); 135 $query->bind(':name', $search); 136 } 137 138 // Filter by language 139 if ($this->getState('filter.language')) { 140 $query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING); 141 } 142 143 // Add the list ordering clause. 144 $query->order($db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))); 145 146 return $query; 147 } 148 149 /** 150 * Method to auto-populate the model state. 151 * 152 * Note. Calling getState in this method will result in recursion. 153 * 154 * @param string $ordering An optional ordering field. 155 * @param string $direction An optional direction (asc|desc). 156 * 157 * @return void 158 * 159 * @since 1.6 160 */ 161 protected function populateState($ordering = null, $direction = null) 162 { 163 $app = Factory::getApplication(); 164 $params = ComponentHelper::getParams('com_contact'); 165 166 // List state information 167 $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint'); 168 $this->setState('list.limit', $limit); 169 170 $limitstart = $app->input->get('limitstart', 0, 'uint'); 171 $this->setState('list.start', $limitstart); 172 173 // Optional filter text 174 $this->setState('list.filter', $app->input->getString('filter-search')); 175 176 $orderCol = $app->input->get('filter_order', 'ordering'); 177 178 if (!in_array($orderCol, $this->filter_fields)) { 179 $orderCol = 'ordering'; 180 } 181 182 $this->setState('list.ordering', $orderCol); 183 184 $listOrder = $app->input->get('filter_order_Dir', 'ASC'); 185 186 if (!in_array(strtoupper($listOrder), array('ASC', 'DESC', ''))) { 187 $listOrder = 'ASC'; 188 } 189 190 $this->setState('list.direction', $listOrder); 191 192 $user = Factory::getUser(); 193 194 if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))) { 195 // Limit to published for people who can't edit or edit.state. 196 $this->setState('filter.published', 1); 197 198 // Filter by start and end dates. 199 $this->setState('filter.publish_date', true); 200 } 201 202 $this->setState('filter.language', Multilanguage::isEnabled()); 203 204 // Load the parameters. 205 $this->setState('params', $params); 206 } 207 }
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 |