[ 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_content 6 * 7 * @copyright (C) 2006 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\Content\Site\Model; 12 13 use Joomla\CMS\Factory; 14 use Joomla\Component\Content\Administrator\Extension\ContentComponent; 15 use Joomla\Component\Content\Site\Helper\QueryHelper; 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 * Content Component Archive Model 24 * 25 * @since 1.5 26 */ 27 class ArchiveModel extends ArticlesModel 28 { 29 /** 30 * Model context string. 31 * 32 * @var string 33 */ 34 public $_context = 'com_content.archive'; 35 36 /** 37 * Method to auto-populate the model state. 38 * 39 * Note. Calling getState in this method will result in recursion. 40 * 41 * @param string $ordering The field to order on. 42 * @param string $direction The direction to order on. 43 * 44 * @return void 45 * 46 * @since 1.6 47 */ 48 protected function populateState($ordering = null, $direction = null) 49 { 50 parent::populateState(); 51 52 $app = Factory::getApplication(); 53 54 // Add archive properties 55 $params = $this->state->get('params'); 56 57 // Filter on archived articles 58 $this->setState('filter.published', ContentComponent::CONDITION_ARCHIVED); 59 60 // Filter on month, year 61 $this->setState('filter.month', $app->input->getInt('month')); 62 $this->setState('filter.year', $app->input->getInt('year')); 63 64 // Optional filter text 65 $this->setState('list.filter', $app->input->getString('filter-search')); 66 67 // Get list limit 68 $itemid = $app->input->get('Itemid', 0, 'int'); 69 $limit = $app->getUserStateFromRequest('com_content.archive.list' . $itemid . '.limit', 'limit', $params->get('display_num', 20), 'uint'); 70 $this->setState('list.limit', $limit); 71 72 // Set the archive ordering 73 $articleOrderby = $params->get('orderby_sec', 'rdate'); 74 $articleOrderDate = $params->get('order_date'); 75 76 // No category ordering 77 $secondary = QueryHelper::orderbySecondary($articleOrderby, $articleOrderDate, $this->getDatabase()); 78 79 $this->setState('list.ordering', $secondary . ', a.created DESC'); 80 $this->setState('list.direction', ''); 81 } 82 83 /** 84 * Get the master query for retrieving a list of articles subject to the model state. 85 * 86 * @return \Joomla\Database\DatabaseQuery 87 * 88 * @since 1.6 89 */ 90 protected function getListQuery() 91 { 92 $params = $this->state->params; 93 $app = Factory::getApplication(); 94 $catids = $app->input->get('catid', array(), 'array'); 95 $catids = array_values(array_diff($catids, array(''))); 96 97 $articleOrderDate = $params->get('order_date'); 98 99 // Create a new query object. 100 $db = $this->getDatabase(); 101 $query = parent::getListQuery(); 102 103 // Add routing for archive 104 $query->select( 105 [ 106 $this->getSlugColumn($query, 'a.id', 'a.alias') . ' AS ' . $db->quoteName('slug'), 107 $this->getSlugColumn($query, 'c.id', 'c.alias') . ' AS ' . $db->quoteName('catslug'), 108 ] 109 ); 110 111 // Filter on month, year 112 // First, get the date field 113 $queryDate = QueryHelper::getQueryDate($articleOrderDate, $this->getDatabase()); 114 115 if ($month = (int) $this->getState('filter.month')) { 116 $query->where($query->month($queryDate) . ' = :month') 117 ->bind(':month', $month, ParameterType::INTEGER); 118 } 119 120 if ($year = (int) $this->getState('filter.year')) { 121 $query->where($query->year($queryDate) . ' = :year') 122 ->bind(':year', $year, ParameterType::INTEGER); 123 } 124 125 if (count($catids) > 0) { 126 $query->whereIn($db->quoteName('c.id'), $catids); 127 } 128 129 return $query; 130 } 131 132 /** 133 * Method to get the archived article list 134 * 135 * @access public 136 * @return array 137 */ 138 public function getData() 139 { 140 $app = Factory::getApplication(); 141 142 // Lets load the content if it doesn't already exist 143 if (empty($this->_data)) { 144 // Get the page/component configuration 145 $params = $app->getParams(); 146 147 // Get the pagination request variables 148 $limit = $app->input->get('limit', $params->get('display_num', 20), 'uint'); 149 $limitstart = $app->input->get('limitstart', 0, 'uint'); 150 151 $query = $this->_buildQuery(); 152 153 $this->_data = $this->_getList($query, $limitstart, $limit); 154 } 155 156 return $this->_data; 157 } 158 159 /** 160 * Gets the archived articles years 161 * 162 * @return array 163 * 164 * @since 3.6.0 165 */ 166 public function getYears() 167 { 168 $db = $this->getDatabase(); 169 $nowDate = Factory::getDate()->toSql(); 170 $query = $db->getQuery(true); 171 $years = $query->year($db->quoteName('c.created')); 172 173 $query->select('DISTINCT ' . $years) 174 ->from($db->quoteName('#__content', 'c')) 175 ->where($db->quoteName('c.state') . ' = ' . ContentComponent::CONDITION_ARCHIVED) 176 ->extendWhere( 177 'AND', 178 [ 179 $db->quoteName('c.publish_up') . ' IS NULL', 180 $db->quoteName('c.publish_up') . ' <= :publishUp', 181 ], 182 'OR' 183 ) 184 ->extendWhere( 185 'AND', 186 [ 187 $db->quoteName('c.publish_down') . ' IS NULL', 188 $db->quoteName('c.publish_down') . ' >= :publishDown', 189 ], 190 'OR' 191 ) 192 ->bind(':publishUp', $nowDate) 193 ->bind(':publishDown', $nowDate) 194 ->order('1 ASC'); 195 196 $db->setQuery($query); 197 198 return $db->loadColumn(); 199 } 200 201 /** 202 * Generate column expression for slug or catslug. 203 * 204 * @param \Joomla\Database\DatabaseQuery $query Current query instance. 205 * @param string $id Column id name. 206 * @param string $alias Column alias name. 207 * 208 * @return string 209 * 210 * @since 4.0.0 211 */ 212 private function getSlugColumn($query, $id, $alias) 213 { 214 $db = $this->getDatabase(); 215 216 return 'CASE WHEN ' 217 . $query->charLength($db->quoteName($alias), '!=', '0') 218 . ' THEN ' 219 . $query->concatenate([$query->castAsChar($db->quoteName($id)), $db->quoteName($alias)], ':') 220 . ' ELSE ' 221 . $query->castAsChar($id) . ' END'; 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 |