- md5
- e91db30b4e7f7c1a5457e7351217253a
- sha1
- 6d4805f7dbd252b9efe0b29283aa021c351d7204
- sha256
- 695d0fad86840a825fb6a227ab3b6e743d152029dc4ee4b0149b8ceaac063aa7
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
<?php
/**
* @package Joomla.Administrator
* @subpackage mod_popular
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Module\Popular\Administrator\Helper;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Administrator\Model\ArticlesModel;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Helper for mod_popular
*
* @since 1.6
*/
class PopularHelper
{
/**
* @var CMSApplicationInterface
*
* @since 6.0.0
*/
protected $app;
/**
* @var Registry
*
* @since 6.0.0
*/
protected $params;
/**
* Helper class constructor
*
* @param array $config Parameters we are using
*
* @since 6.0.0
*/
public function __construct($config)
{
$this->app = $config['app'];
$this->params = $config['params'];
}
/**
* Get a list of the most popular articles.
*
* @param Registry $params The module parameters.
* @param ArticlesModel $model The model.
*
* @return mixed An array of articles, or false on error.
*
* @throws \Exception
*
* @since 6.0.0
*/
public function getArticles(Registry $params, ArticlesModel $model): mixed
{
$user = $this->app->getIdentity();
// Set List SELECT
$model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
' a.created, a.modified, a.publish_up, a.created_by, a.hits');
// Set Ordering filter
$model->setState('list.ordering', 'a.hits');
$model->setState('list.direction', 'DESC');
// Set Category Filter
$categoryId = $params->get('catid', null);
if (is_numeric($categoryId)) {
$model->setState('filter.category_id', $categoryId);
}
// Set User Filter.
$userId = $user->id;
switch ($params->get('user_id', '0')) {
case 'by_me':
$model->setState('filter.author_id', $userId);
break;
case 'not_me':
$model->setState('filter.author_id', $userId);
$model->setState('filter.author_id.include', false);
break;
}
// Set the Start and Limit
$model->setState('list.start', 0);
$model->setState('list.limit', $params->get('count', 5));
// Set date filtering using ArticlesModel's built-in filter
$dateFiltering = $params->get('date_filtering', 'off');
if ($dateFiltering !== 'off') {
$model->setState('filter.date_filtering', $dateFiltering);
$model->setState('filter.date_field', $params->get('date_field', 'a.created'));
if ($dateFiltering === 'range') {
$model->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00'));
$model->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59'));
} elseif ($dateFiltering === 'relative') {
$model->setState('filter.relative_date', (int) $params->get('relative_date', 30));
}
}
$items = $model->getItems();
if ($error = $model->getError()) {
throw new \Exception($error, 500);
}
// Set the links
foreach ($items as &$item) {
$item->link = '';
if (
$user->authorise('core.edit', 'com_content.article.' . $item->id)
|| ($user->authorise('core.edit.own', 'com_content.article.' . $item->id) && ($userId === $item->created_by))
) {
$item->link = Route::_('index.php?option=com_content&task=article.edit&id=' . $item->id);
}
}
return $items;
}
/**
* Get the alternate title for the module
*
* @param Registry $params The module parameters.
*
* @return string The alternate title for the module.
*
* @since 6.0.0
*/
public function getModuleTitle(Registry $params): string
{
$who = $params->get('user_id', 0);
$catid = (int) $params->get('catid', null);
$title = '';
if ($catid) {
$category = $this->app->bootComponent('com_content')->getCategory()->get($catid);
$title = Text::_('MOD_POPULAR_UNEXISTING');
if ($category) {
$title = $category->title;
}
}
return Text::plural(
'MOD_POPULAR_TITLE' . ($catid ? '_CATEGORY' : '') . ($who != '0' ? "_$who" : ''),
(int) $params->get('count', 5),
$title
);
}
}
The same content is in 29 releases, Joomla 6.1.0-alpha3 to 6.2.1-rc1. See them all, or every version of this file.