- md5
- 2146ec2eb8a3b369bd1a2c52c4450463
- sha1
- ea96c3c0f5b211cc04322d07c9e08749f159a741
- sha256
- b5f74de8fc5c827a52d1551ff5af92d9bb1598b617d4233e9b94bfe2a800c452
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?php
/**
* @package Joomla.Administrator
* @subpackage mod_popular
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Module\Popular\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Administrator\Model\ArticlesModel;
use Joomla\Registry\Registry;
/**
* Helper for mod_popular
*
* @since 1.6
*/
abstract class PopularHelper
{
/**
* 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
*/
public static function getList(Registry &$params, ArticlesModel $model)
{
$user = Factory::getUser();
// Set List SELECT
$model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
' a.publish_up, 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->get('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));
$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))
{
$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.
*/
public static function getTitle($params)
{
$who = $params->get('user_id', 0);
$catid = (int) $params->get('catid', null);
$title = '';
if ($catid)
{
$category = Categories::getInstance('Content')->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
);
}
}
No other release has this exact content. See every version of this file.