[ 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\Registry\Registry; 17 use Joomla\Utilities\ArrayHelper; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Frontpage Component Model 25 * 26 * @since 1.5 27 */ 28 class FeaturedModel extends ArticlesModel 29 { 30 /** 31 * Model context string. 32 * 33 * @var string 34 */ 35 public $_context = 'com_content.frontpage'; 36 37 /** 38 * Method to auto-populate the model state. 39 * 40 * Note. Calling getState in this method will result in recursion. 41 * 42 * @param string $ordering The field to order on. 43 * @param string $direction The direction to order on. 44 * 45 * @return void 46 * 47 * @since 1.6 48 */ 49 protected function populateState($ordering = null, $direction = null) 50 { 51 parent::populateState($ordering, $direction); 52 53 $app = Factory::getApplication(); 54 $input = $app->input; 55 $user = $app->getIdentity(); 56 57 // List state information 58 $limitstart = $input->getUint('limitstart', 0); 59 $this->setState('list.start', $limitstart); 60 61 $params = $this->state->params; 62 63 if ($menu = $app->getMenu()->getActive()) { 64 $menuParams = $menu->getParams(); 65 } else { 66 $menuParams = new Registry(); 67 } 68 69 $mergedParams = clone $menuParams; 70 $mergedParams->merge($params); 71 72 $this->setState('params', $mergedParams); 73 74 $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links'); 75 $this->setState('list.limit', $limit); 76 $this->setState('list.links', $params->get('num_links')); 77 78 $this->setState('filter.frontpage', true); 79 80 if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))) { 81 // Filter on published for those who do not have edit or edit.state rights. 82 $this->setState('filter.published', ContentComponent::CONDITION_PUBLISHED); 83 } else { 84 $this->setState('filter.published', [ContentComponent::CONDITION_UNPUBLISHED, ContentComponent::CONDITION_PUBLISHED]); 85 } 86 87 // Process show_noauth parameter 88 if (!$params->get('show_noauth')) { 89 $this->setState('filter.access', true); 90 } else { 91 $this->setState('filter.access', false); 92 } 93 94 // Check for category selection 95 if ($params->get('featured_categories') && implode(',', $params->get('featured_categories')) == true) { 96 $featuredCategories = $params->get('featured_categories'); 97 $this->setState('filter.frontpage.categories', $featuredCategories); 98 } 99 100 $articleOrderby = $params->get('orderby_sec', 'rdate'); 101 $articleOrderDate = $params->get('order_date'); 102 $categoryOrderby = $params->def('orderby_pri', ''); 103 104 $secondary = QueryHelper::orderbySecondary($articleOrderby, $articleOrderDate, $this->getDatabase()); 105 $primary = QueryHelper::orderbyPrimary($categoryOrderby); 106 107 $this->setState('list.ordering', $primary . $secondary . ', a.created DESC'); 108 $this->setState('list.direction', ''); 109 } 110 111 /** 112 * Method to get a list of articles. 113 * 114 * @return mixed An array of objects on success, false on failure. 115 */ 116 public function getItems() 117 { 118 $params = clone $this->getState('params'); 119 $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links'); 120 121 if ($limit > 0) { 122 $this->setState('list.limit', $limit); 123 124 return parent::getItems(); 125 } 126 127 return array(); 128 } 129 130 /** 131 * Method to get a store id based on model configuration state. 132 * 133 * This is necessary because the model is used by the component and 134 * different modules that might need different sets of data or different 135 * ordering requirements. 136 * 137 * @param string $id A prefix for the store id. 138 * 139 * @return string A store id. 140 */ 141 protected function getStoreId($id = '') 142 { 143 // Compile the store id. 144 $id .= $this->getState('filter.frontpage'); 145 146 return parent::getStoreId($id); 147 } 148 149 /** 150 * Get the list of items. 151 * 152 * @return \Joomla\Database\DatabaseQuery 153 */ 154 protected function getListQuery() 155 { 156 // Create a new query object. 157 $query = parent::getListQuery(); 158 159 // Filter by categories 160 $featuredCategories = $this->getState('filter.frontpage.categories'); 161 162 if (is_array($featuredCategories) && !in_array('', $featuredCategories)) { 163 $query->where('a.catid IN (' . implode(',', ArrayHelper::toInteger($featuredCategories)) . ')'); 164 } 165 166 return $query; 167 } 168 }
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 |