PageRenderTime 21ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/modules/mod_popular/helper.php

https://bitbucket.org/eternaware/joomus
PHP | 113 lines | 64 code | 15 blank | 34 comment | 9 complexity | 22271968a74e562aebc61f85845cdba7 MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Administrator
  4 * @subpackage  mod_popular
  5 *
  6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7 * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8 */
  9
 10defined('_JEXEC') or die;
 11
 12JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_content/models', 'ContentModel');
 13
 14/**
 15 * Helper for mod_popular
 16 *
 17 * @package     Joomla.Administrator
 18 * @subpackage  mod_popular
 19 * @since       1.6
 20 */
 21abstract class modPopularHelper
 22{
 23	/**
 24	 * Get a list of the most popular articles
 25	 *
 26	 * @param	JObject		The module parameters.
 27	 *
 28	 * @return	array
 29	 */
 30	public static function getList($params)
 31	{
 32		$user = JFactory::getuser();
 33
 34		// Get an instance of the generic articles model
 35		$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
 36
 37		// Set List SELECT
 38		$model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
 39				' a.created, a.hits');
 40
 41		// Set Ordering filter
 42		$model->setState('list.ordering', 'a.hits');
 43		$model->setState('list.direction', 'DESC');
 44
 45		// Set Category Filter
 46		$categoryId = $params->get('catid');
 47		if (is_numeric($categoryId)){
 48			$model->setState('filter.category_id', $categoryId);
 49		}
 50
 51		// Set User Filter.
 52		$userId = $user->get('id');
 53		switch ($params->get('user_id')) {
 54			case 'by_me':
 55				$model->setState('filter.author_id', $userId);
 56				break;
 57
 58			case 'not_me':
 59				$model->setState('filter.author_id', $userId);
 60				$model->setState('filter.author_id.include', false);
 61				break;
 62		}
 63
 64		// Set the Start and Limit
 65		$model->setState('list.start', 0);
 66		$model->setState('list.limit', $params->get('count', 5));
 67
 68		$items = $model->getItems();
 69
 70		if ($error = $model->getError()) {
 71			JError::raiseError(500, $error);
 72			return false;
 73		}
 74
 75		// Set the links
 76		foreach ($items as &$item) {
 77			if ($user->authorise('core.edit', 'com_content.article.'.$item->id)){
 78				$item->link = JRoute::_('index.php?option=com_content&task=article.edit&id='.$item->id);
 79			} else {
 80				$item->link = '';
 81			}
 82		}
 83
 84		return $items;
 85	}
 86
 87	/**
 88	 * Get the alternate title for the module
 89	 *
 90	 * @param	JObject	The module parameters.
 91	 * @return	string	The alternate title for the module.
 92	 */
 93	public static function getTitle($params)
 94	{
 95		$who = $params->get('user_id');
 96		$catid = (int) $params->get('catid');
 97		if ($catid)
 98		{
 99			$category = JCategories::getInstance('Content')->get($catid);
100			if ($category) {
101				$title = $category->title;
102			}
103			else {
104				$title = JText::_('MOD_POPULAR_UNEXISTING');
105			}
106		}
107		else
108		{
109			$title = '';
110		}
111		return JText::plural('MOD_POPULAR_TITLE' . ($catid ? "_CATEGORY" : '') . ($who != '0' ? "_$who" : ''), (int) $params->get('count'), $title);
112	}
113}