/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. // no direct access
  10. defined('_JEXEC') or die;
  11. require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
  12. JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'models');
  13. abstract class modArticlesPopularHelper
  14. {
  15. public static function getList(&$params)
  16. {
  17. // Get an instance of the generic articles model
  18. $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
  19. // Set application parameters in model
  20. $appParams = JFactory::getApplication()->getParams();
  21. $model->setState('params', $appParams);
  22. // Set the filters based on the module params
  23. $model->setState('list.start', 0);
  24. $model->setState('list.limit', (int) $params->get('count', 5));
  25. $model->setState('filter.published', 1);
  26. // Access filter
  27. $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
  28. $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
  29. $model->setState('filter.access', $access);
  30. // Category filter
  31. if ($catid = $params->get('catid')) {
  32. $model->setState('filter.category_id', $catid);
  33. }
  34. // Ordering
  35. $model->setState('list.ordering', 'a.hits');
  36. $model->setState('list.direction', 'DESC');
  37. $items = $model->getItems();
  38. foreach ($items as &$item) {
  39. $item->slug = $item->id.':'.$item->alias;
  40. $item->catslug = $item->catid.':'.$item->category_alias;
  41. if ($access || in_array($item->access, $authorised))
  42. {
  43. // We know that user has the privilege to view the article
  44. $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
  45. }
  46. else {
  47. $item->link = JRoute::_('index.php?option=com_user&view=login');
  48. }
  49. $item->introtext = JHtml::_('content.prepare', $item->introtext);
  50. }
  51. return $items;
  52. }
  53. }