/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

  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. defined('_JEXEC') or die;
  10. JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_content/models', 'ContentModel');
  11. /**
  12. * Helper for mod_popular
  13. *
  14. * @package Joomla.Administrator
  15. * @subpackage mod_popular
  16. * @since 1.6
  17. */
  18. abstract class modPopularHelper
  19. {
  20. /**
  21. * Get a list of the most popular articles
  22. *
  23. * @param JObject The module parameters.
  24. *
  25. * @return array
  26. */
  27. public static function getList($params)
  28. {
  29. $user = JFactory::getuser();
  30. // Get an instance of the generic articles model
  31. $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
  32. // Set List SELECT
  33. $model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
  34. ' a.created, a.hits');
  35. // Set Ordering filter
  36. $model->setState('list.ordering', 'a.hits');
  37. $model->setState('list.direction', 'DESC');
  38. // Set Category Filter
  39. $categoryId = $params->get('catid');
  40. if (is_numeric($categoryId)){
  41. $model->setState('filter.category_id', $categoryId);
  42. }
  43. // Set User Filter.
  44. $userId = $user->get('id');
  45. switch ($params->get('user_id')) {
  46. case 'by_me':
  47. $model->setState('filter.author_id', $userId);
  48. break;
  49. case 'not_me':
  50. $model->setState('filter.author_id', $userId);
  51. $model->setState('filter.author_id.include', false);
  52. break;
  53. }
  54. // Set the Start and Limit
  55. $model->setState('list.start', 0);
  56. $model->setState('list.limit', $params->get('count', 5));
  57. $items = $model->getItems();
  58. if ($error = $model->getError()) {
  59. JError::raiseError(500, $error);
  60. return false;
  61. }
  62. // Set the links
  63. foreach ($items as &$item) {
  64. if ($user->authorise('core.edit', 'com_content.article.'.$item->id)){
  65. $item->link = JRoute::_('index.php?option=com_content&task=article.edit&id='.$item->id);
  66. } else {
  67. $item->link = '';
  68. }
  69. }
  70. return $items;
  71. }
  72. /**
  73. * Get the alternate title for the module
  74. *
  75. * @param JObject The module parameters.
  76. * @return string The alternate title for the module.
  77. */
  78. public static function getTitle($params)
  79. {
  80. $who = $params->get('user_id');
  81. $catid = (int) $params->get('catid');
  82. if ($catid)
  83. {
  84. $category = JCategories::getInstance('Content')->get($catid);
  85. if ($category) {
  86. $title = $category->title;
  87. }
  88. else {
  89. $title = JText::_('MOD_POPULAR_UNEXISTING');
  90. }
  91. }
  92. else
  93. {
  94. $title = '';
  95. }
  96. return JText::plural('MOD_POPULAR_TITLE' . ($catid ? "_CATEGORY" : '') . ($who != '0' ? "_$who" : ''), (int) $params->get('count'), $title);
  97. }
  98. }