[ 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_latest 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\Latest\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_latest 26 * 27 * @since 1.5 28 */ 29 abstract class LatestHelper 30 { 31 /** 32 * Get a list of 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 public static function getList(Registry &$params, ArticlesModel $model) 40 { 41 $user = Factory::getUser(); 42 43 // Set List SELECT 44 $model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' . 45 ' a.access, a.created, a.created_by, a.created_by_alias, a.featured, a.state, a.publish_up, a.publish_down'); 46 47 // Set Ordering filter 48 switch ($params->get('ordering', 'c_dsc')) { 49 case 'm_dsc': 50 $model->setState('list.ordering', 'a.modified DESC, a.created'); 51 $model->setState('list.direction', 'DESC'); 52 break; 53 54 case 'c_dsc': 55 default: 56 $model->setState('list.ordering', 'a.created'); 57 $model->setState('list.direction', 'DESC'); 58 break; 59 } 60 61 // Set Category Filter 62 $categoryId = $params->get('catid', null); 63 64 if (is_numeric($categoryId)) { 65 $model->setState('filter.category_id', $categoryId); 66 } 67 68 // Set User Filter. 69 $userId = $user->get('id'); 70 71 switch ($params->get('user_id', '0')) { 72 case 'by_me': 73 $model->setState('filter.author_id', $userId); 74 break; 75 76 case 'not_me': 77 $model->setState('filter.author_id', $userId); 78 $model->setState('filter.author_id.include', false); 79 break; 80 } 81 82 // Set the Start and Limit 83 $model->setState('list.start', 0); 84 $model->setState('list.limit', $params->get('count', 5)); 85 86 $items = $model->getItems(); 87 88 if ($error = $model->getError()) { 89 throw new \Exception($error, 500); 90 } 91 92 // Set the links 93 foreach ($items as &$item) { 94 $item->link = ''; 95 96 if ( 97 $user->authorise('core.edit', 'com_content.article.' . $item->id) 98 || ($user->authorise('core.edit.own', 'com_content.article.' . $item->id) && ($userId === $item->created_by)) 99 ) { 100 $item->link = Route::_('index.php?option=com_content&task=article.edit&id=' . $item->id); 101 } 102 } 103 104 return $items; 105 } 106 107 /** 108 * Get the alternate title for the module. 109 * 110 * @param \Joomla\Registry\Registry $params The module parameters. 111 * 112 * @return string The alternate title for the module. 113 */ 114 public static function getTitle($params) 115 { 116 $who = $params->get('user_id', 0); 117 $catid = (int) $params->get('catid', null); 118 $type = $params->get('ordering') === 'c_dsc' ? '_CREATED' : '_MODIFIED'; 119 $title = ''; 120 121 if ($catid) { 122 $category = Categories::getInstance('Content')->get($catid); 123 $title = Text::_('MOD_POPULAR_UNEXISTING'); 124 125 if ($category) { 126 $title = $category->title; 127 } 128 } 129 130 return Text::plural( 131 'MOD_LATEST_TITLE' . $type . ($catid ? '_CATEGORY' : '') . ($who != '0' ? "_$who" : ''), 132 (int) $params->get('count', 5), 133 $title 134 ); 135 } 136 }
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 |