[ 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 mod_popular 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\Module\Popular\Administrator\Helper; 12 13 use Joomla\CMS\Categories\Categories; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Router\Route; 17 use Joomla\Component\Content\Administrator\Model\ArticlesModel; 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 * Helper for mod_popular 26 * 27 * @since 1.6 28 */ 29 abstract class PopularHelper 30 { 31 /** 32 * Get a list of the most popular articles. 33 * 34 * @param Registry &$params The module parameters. 35 * @param ArticlesModel $model The model. 36 * 37 * @return mixed An array of articles, or false on error. 38 * 39 * @throws \Exception 40 */ 41 public static function getList(Registry &$params, ArticlesModel $model) 42 { 43 $user = Factory::getUser(); 44 45 // Set List SELECT 46 $model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' . 47 ' a.publish_up, a.hits'); 48 49 // Set Ordering filter 50 $model->setState('list.ordering', 'a.hits'); 51 $model->setState('list.direction', 'DESC'); 52 53 // Set Category Filter 54 $categoryId = $params->get('catid', null); 55 56 if (is_numeric($categoryId)) { 57 $model->setState('filter.category_id', $categoryId); 58 } 59 60 // Set User Filter. 61 $userId = $user->get('id'); 62 63 switch ($params->get('user_id', '0')) { 64 case 'by_me': 65 $model->setState('filter.author_id', $userId); 66 break; 67 68 case 'not_me': 69 $model->setState('filter.author_id', $userId); 70 $model->setState('filter.author_id.include', false); 71 break; 72 } 73 74 // Set the Start and Limit 75 $model->setState('list.start', 0); 76 $model->setState('list.limit', $params->get('count', 5)); 77 78 $items = $model->getItems(); 79 80 if ($error = $model->getError()) { 81 throw new \Exception($error, 500); 82 } 83 84 // Set the links 85 foreach ($items as &$item) { 86 $item->link = ''; 87 88 if ( 89 $user->authorise('core.edit', 'com_content.article.' . $item->id) 90 || ($user->authorise('core.edit.own', 'com_content.article.' . $item->id) && ($userId === $item->created_by)) 91 ) { 92 $item->link = Route::_('index.php?option=com_content&task=article.edit&id=' . $item->id); 93 } 94 } 95 96 return $items; 97 } 98 99 /** 100 * Get the alternate title for the module 101 * 102 * @param Registry $params The module parameters. 103 * 104 * @return string The alternate title for the module. 105 */ 106 public static function getTitle($params) 107 { 108 $who = $params->get('user_id', 0); 109 $catid = (int) $params->get('catid', null); 110 $title = ''; 111 112 if ($catid) { 113 $category = Categories::getInstance('Content')->get($catid); 114 $title = Text::_('MOD_POPULAR_UNEXISTING'); 115 116 if ($category) { 117 $title = $category->title; 118 } 119 } 120 121 return Text::plural( 122 'MOD_POPULAR_TITLE' . ($catid ? '_CATEGORY' : '') . ($who != '0' ? "_$who" : ''), 123 (int) $params->get('count', 5), 124 $title 125 ); 126 } 127 }
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 |