[ 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 mod_articles_popular 6 * 7 * @copyright (C) 2009 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\Module\ArticlesPopular\Site\Helper; 12 13 use Joomla\CMS\Access\Access; 14 use Joomla\CMS\Component\ComponentHelper; 15 use Joomla\CMS\Factory; 16 use Joomla\CMS\Router\Route; 17 use Joomla\Component\Content\Administrator\Extension\ContentComponent; 18 use Joomla\Component\Content\Site\Helper\RouteHelper; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Helper for mod_articles_popular 26 * 27 * @since 1.6 28 */ 29 abstract class ArticlesPopularHelper 30 { 31 /** 32 * Get a list of popular articles from the articles model 33 * 34 * @param \Joomla\Registry\Registry &$params object holding the models parameters 35 * 36 * @return mixed 37 */ 38 public static function getList(&$params) 39 { 40 $app = Factory::getApplication(); 41 42 // Get an instance of the generic articles model 43 $model = $app->bootComponent('com_content') 44 ->getMVCFactory()->createModel('Articles', 'Site', ['ignore_request' => true]); 45 46 // Set application parameters in model 47 $appParams = $app->getParams(); 48 $model->setState('params', $appParams); 49 50 $model->setState('list.start', 0); 51 $model->setState('filter.published', ContentComponent::CONDITION_PUBLISHED); 52 53 // Set the filters based on the module params 54 $model->setState('list.limit', (int) $params->get('count', 5)); 55 $model->setState('filter.featured', $params->get('show_front', 1) == 1 ? 'show' : 'hide'); 56 57 // This module does not use tags data 58 $model->setState('load_tags', false); 59 60 // Access filter 61 $access = !ComponentHelper::getParams('com_content')->get('show_noauth'); 62 $authorised = Access::getAuthorisedViewLevels(Factory::getUser()->get('id')); 63 $model->setState('filter.access', $access); 64 65 // Category filter 66 $model->setState('filter.category_id', $params->get('catid', [])); 67 68 // Date filter 69 $date_filtering = $params->get('date_filtering', 'off'); 70 71 if ($date_filtering !== 'off') { 72 $model->setState('filter.date_filtering', $date_filtering); 73 $model->setState('filter.date_field', $params->get('date_field', 'a.created')); 74 $model->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00')); 75 $model->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59')); 76 $model->setState('filter.relative_date', $params->get('relative_date', 30)); 77 } 78 79 // Filter by language 80 $model->setState('filter.language', $app->getLanguageFilter()); 81 82 // Ordering 83 $model->setState('list.ordering', 'a.hits'); 84 $model->setState('list.direction', 'DESC'); 85 86 $items = $model->getItems(); 87 88 foreach ($items as &$item) { 89 $item->slug = $item->id . ':' . $item->alias; 90 91 if ($access || \in_array($item->access, $authorised)) { 92 // We know that user has the privilege to view the article 93 $item->link = Route::_(RouteHelper::getArticleRoute($item->slug, $item->catid, $item->language)); 94 } else { 95 $item->link = Route::_('index.php?option=com_users&view=login'); 96 } 97 } 98 99 return $items; 100 } 101 }
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 |