PageRenderTime 142ms CodeModel.GetById 60ms app.highlight 14ms RepoModel.GetById 48ms app.codeStats 0ms

/modules/mod_articles_popular/helper.php

https://github.com/joebushi/joomla
PHP | 66 lines | 38 code | 13 blank | 15 comment | 4 complexity | d0aa4ac8a8432aa2da8257112c83f79d MD5 | raw file
 1<?php
 2/**
 3 * @version		$Id$
 4 * @package		Joomla.Site
 5 * @subpackage	mod_articles_popular
 6 * @copyright	Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
 7 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 8 */
 9
10// no direct access
11defined('_JEXEC') or die;
12
13require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
14JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'models');
15
16abstract class modArticlesPopularHelper
17{
18	public static function getList(&$params)
19	{
20		// Get an instance of the generic articles model
21		$model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
22
23		// Set application parameters in model
24		$appParams = JFactory::getApplication()->getParams();
25		$model->setState('params', $appParams);
26
27		// Set the filters based on the module params
28		$model->setState('list.start', 0);
29		$model->setState('list.limit', (int) $params->get('count', 5));
30		$model->setState('filter.published', 1);
31
32		// Access filter
33		$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
34		$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
35		$model->setState('filter.access', $access);
36
37		// Category filter
38		if ($catid = $params->get('catid')) {
39			$model->setState('filter.category_id', $catid);
40		}
41
42		// Ordering
43		$model->setState('list.ordering', 'a.hits');
44		$model->setState('list.direction', 'DESC');
45
46		$items = $model->getItems();
47
48		foreach ($items as &$item) {
49			$item->slug = $item->id.':'.$item->alias;
50			$item->catslug = $item->catid.':'.$item->category_alias;
51
52			if ($access || in_array($item->access, $authorised))
53			{
54				// We know that user has the privilege to view the article
55				$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
56			}
57			else {
58				$item->link = JRoute::_('index.php?option=com_user&view=login');
59			}
60
61			$item->introtext = JHtml::_('content.prepare', $item->introtext);
62		}
63
64		return $items;
65	}
66}