[ 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_privacy 6 * 7 * @copyright (C) 2018 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\Privacy\Administrator\Model; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\MVC\Model\ListModel; 16 use Joomla\Database\DatabaseQuery; 17 use Joomla\Database\ParameterType; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Requests management model class. 25 * 26 * @since 3.9.0 27 */ 28 class RequestsModel extends ListModel 29 { 30 /** 31 * Constructor. 32 * 33 * @param array $config An optional associative array of configuration settings. 34 * 35 * @since 3.9.0 36 */ 37 public function __construct($config = []) 38 { 39 if (empty($config['filter_fields'])) { 40 $config['filter_fields'] = [ 41 'id', 'a.id', 42 'email', 'a.email', 43 'requested_at', 'a.requested_at', 44 'request_type', 'a.request_type', 45 'status', 'a.status', 46 ]; 47 } 48 49 parent::__construct($config); 50 } 51 52 /** 53 * Method to get a DatabaseQuery object for retrieving the data set from a database. 54 * 55 * @return DatabaseQuery 56 * 57 * @since 3.9.0 58 */ 59 protected function getListQuery() 60 { 61 // Create a new query object. 62 $db = $this->getDatabase(); 63 $query = $db->getQuery(true); 64 65 // Select the required fields from the table. 66 $query->select($this->getState('list.select', 'a.*')); 67 $query->from($db->quoteName('#__privacy_requests', 'a')); 68 69 // Filter by status 70 $status = $this->getState('filter.status'); 71 72 if (is_numeric($status)) { 73 $status = (int) $status; 74 $query->where($db->quoteName('a.status') . ' = :status') 75 ->bind(':status', $status, ParameterType::INTEGER); 76 } 77 78 // Filter by request type 79 $requestType = $this->getState('filter.request_type', ''); 80 81 if ($requestType) { 82 $query->where($db->quoteName('a.request_type') . ' = :requesttype') 83 ->bind(':requesttype', $requestType); 84 } 85 86 // Filter by search in email 87 $search = $this->getState('filter.search'); 88 89 if (!empty($search)) { 90 if (stripos($search, 'id:') === 0) { 91 $ids = (int) substr($search, 3); 92 $query->where($db->quoteName('a.id') . ' = :id') 93 ->bind(':id', $ids, ParameterType::INTEGER); 94 } else { 95 $search = '%' . $search . '%'; 96 $query->where('(' . $db->quoteName('a.email') . ' LIKE :search)') 97 ->bind(':search', $search); 98 } 99 } 100 101 // Handle the list ordering. 102 $ordering = $this->getState('list.ordering'); 103 $direction = $this->getState('list.direction'); 104 105 if (!empty($ordering)) { 106 $query->order($db->escape($ordering) . ' ' . $db->escape($direction)); 107 } 108 109 return $query; 110 } 111 112 /** 113 * Method to get a store id based on model configuration state. 114 * 115 * This is necessary because the model is used by the component and 116 * different modules that might need different sets of data or different 117 * ordering requirements. 118 * 119 * @param string $id A prefix for the store id. 120 * 121 * @return string 122 * 123 * @since 3.9.0 124 */ 125 protected function getStoreId($id = '') 126 { 127 // Compile the store id. 128 $id .= ':' . $this->getState('filter.search'); 129 $id .= ':' . $this->getState('filter.status'); 130 $id .= ':' . $this->getState('filter.request_type'); 131 132 return parent::getStoreId($id); 133 } 134 135 /** 136 * Method to auto-populate the model state. 137 * 138 * Note. Calling getState in this method will result in recursion. 139 * 140 * @param string $ordering An optional ordering field. 141 * @param string $direction An optional direction (asc|desc). 142 * 143 * @return void 144 * 145 * @since 3.9.0 146 */ 147 protected function populateState($ordering = 'a.id', $direction = 'desc') 148 { 149 // Load the filter state. 150 $this->setState( 151 'filter.search', 152 $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search') 153 ); 154 155 $this->setState( 156 'filter.status', 157 $this->getUserStateFromRequest($this->context . '.filter.status', 'filter_status', '', 'int') 158 ); 159 160 $this->setState( 161 'filter.request_type', 162 $this->getUserStateFromRequest($this->context . '.filter.request_type', 'filter_request_type', '', 'string') 163 ); 164 165 // Load the parameters. 166 $this->setState('params', ComponentHelper::getParams('com_privacy')); 167 168 // List state information. 169 parent::populateState($ordering, $direction); 170 } 171 172 /** 173 * Method to return number privacy requests older than X days. 174 * 175 * @return integer 176 * 177 * @since 3.9.0 178 */ 179 public function getNumberUrgentRequests() 180 { 181 // Load the parameters. 182 $params = ComponentHelper::getComponent('com_privacy')->getParams(); 183 $notify = (int) $params->get('notify', 14); 184 $now = Factory::getDate()->toSql(); 185 $period = '-' . $notify; 186 187 $db = $this->getDatabase(); 188 $query = $db->getQuery(true) 189 ->select('COUNT(*)'); 190 $query->from($db->quoteName('#__privacy_requests')); 191 $query->where($db->quoteName('status') . ' = 1 '); 192 $query->where($query->dateAdd($db->quote($now), $period, 'DAY') . ' > ' . $db->quoteName('requested_at')); 193 $db->setQuery($query); 194 195 return (int) $db->loadResult(); 196 } 197 }
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 |