PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/modules/mod_latest/helper.php

https://github.com/joebushi/joomla
PHP | 93 lines | 53 code | 15 blank | 25 comment | 6 complexity | 44f4e99cb6acd201babec9d15018ac8c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. // No direct access.
  8. defined('_JEXEC') or die;
  9. JModel::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_content/models');
  10. /**
  11. * @package Joomla.Administrator
  12. * @subpackage mod_latest
  13. */
  14. abstract class modLatestHelper
  15. {
  16. /**
  17. * Get a list of articles.
  18. *
  19. * @param JObject The module parameters.
  20. *
  21. * @return mixed An array of articles, or false on error.
  22. */
  23. public static function getList($params)
  24. {
  25. // Initialise variables
  26. $user = JFactory::getuser();
  27. // Get an instance of the generic articles model
  28. $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
  29. // Set List SELECT
  30. $model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
  31. ' a.access, a.created, a.created_by, a.created_by_alias, a.featured');
  32. // Set Ordering filter
  33. switch ($params->get('ordering')) {
  34. case 'm_dsc':
  35. $model->setState('list.ordering', 'modified DESC, created');
  36. $model->setState('list.direction', 'DESC');
  37. break;
  38. case 'c_dsc':
  39. default:
  40. $model->setState('list.ordering', 'created');
  41. $model->setState('list.direction', 'DESC');
  42. break;
  43. }
  44. // Set Category Filter
  45. $categoryId = $params->get('catid');
  46. if (is_numeric($categoryId)){
  47. $model->setState('filter.category_id', $categoryId);
  48. }
  49. // Set User Filter.
  50. $userId = $user->get('id');
  51. switch ($params->get('user_id')) {
  52. case 'by_me':
  53. $model->setState('filter.author_id', $userId);
  54. break;
  55. case 'not_me':
  56. $model->setState('filter.author_id', $userId);
  57. $model->setState('filter.author_id.include', false);
  58. break;
  59. }
  60. // Set the Start and Limit
  61. $model->setState('list.start', 0);
  62. $model->setState('list.limit', $params->get('count', 5));
  63. $items = $model->getItems();
  64. if ($error = $model->getError()) {
  65. JError::raiseError(500, $error);
  66. return false;
  67. }
  68. // Set the links
  69. foreach ($items as &$item) {
  70. if ($user->authorise('core.edit','com_content.article.'.$item->id)){
  71. $item->link = JRoute::_('index.php?option=com_content&task=article.edit&id='.$item->id);
  72. } else {
  73. $item->link = '';
  74. }
  75. }
  76. return $items;
  77. }
  78. }