PageRenderTime 43ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/mod_articles_latest/helper.php

https://github.com/joebushi/joomla
PHP | 93 lines | 55 code | 16 blank | 22 comment | 5 complexity | b9708ece4fc1d8c92b0f37e39b17618d MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Site
  5. * @subpackage mod_articles_latest
  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 modArticlesLatestHelper
  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. // User filter
  35. $userId = JFactory::getUser()->get('id');
  36. switch ($params->get('user_id'))
  37. {
  38. case 'by_me':
  39. $model->setState('filter.author_id', $userId);
  40. break;
  41. case 'not_me':
  42. $model->setState('filter.author_id', $userId);
  43. $model->setState('filter.author_id.include', false);
  44. break;
  45. }
  46. // Set ordering
  47. $order_map = array(
  48. 'm_dsc' => 'a.modified DESC, a.created',
  49. /*
  50. * TODO below line does not work because it's running through JDatabase::_getEscaped
  51. * which adds unnecessary quotes before and after the null date.
  52. * This should be uncommented when it's fixed.
  53. */
  54. //'mc_dsc' => 'CASE WHEN (a.modified = \'0000-00-00 00:00:00\') THEN a.created ELSE a.modified END',
  55. 'c_dsc' => 'a.created'
  56. );
  57. $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.created');
  58. $dir = 'DESC';
  59. $model->setState('list.ordering', $ordering);
  60. $model->setState('list.direction', $dir);
  61. $items = $model->getItems();
  62. foreach ($items as &$item) {
  63. $item->slug = $item->id.':'.$item->alias;
  64. $item->catslug = $item->catid.':'.$item->category_alias;
  65. if ($access || in_array($item->access, $authorised))
  66. {
  67. // We know that user has the privilege to view the article
  68. $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
  69. }
  70. else {
  71. $item->link = JRoute::_('index.php?option=com_user&view=login');
  72. }
  73. $item->introtext = JHtml::_('content.prepare', $item->introtext);
  74. }
  75. return $items;
  76. }
  77. }