[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/modules/mod_articles_latest/ -> helper.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Site
   4   * @subpackage    mod_articles_latest
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // no direct access
  10  defined('_JEXEC') or die;
  11  
  12  require_once  JPATH_SITE.'/components/com_content/helpers/route.php';
  13  
  14  jimport('joomla.application.component.model');
  15  
  16  JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
  17  
  18  abstract class modArticlesLatestHelper
  19  {
  20  	public static function getList(&$params)
  21      {
  22          // Get the dbo
  23          $db = JFactory::getDbo();
  24  
  25          // Get an instance of the generic articles model
  26          $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
  27  
  28          // Set application parameters in model
  29          $app = JFactory::getApplication();
  30          $appParams = $app->getParams();
  31          $model->setState('params', $appParams);
  32  
  33          // Set the filters based on the module params
  34          $model->setState('list.start', 0);
  35          $model->setState('list.limit', (int) $params->get('count', 5));
  36          $model->setState('filter.published', 1);
  37  
  38          // Access filter
  39          $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
  40          $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
  41          $model->setState('filter.access', $access);
  42  
  43          // Category filter
  44          $model->setState('filter.category_id', $params->get('catid', array()));
  45  
  46          // User filter
  47          $userId = JFactory::getUser()->get('id');
  48          switch ($params->get('user_id'))
  49          {
  50              case 'by_me':
  51                  $model->setState('filter.author_id', (int) $userId);
  52                  break;
  53              case 'not_me':
  54                  $model->setState('filter.author_id', $userId);
  55                  $model->setState('filter.author_id.include', false);
  56                  break;
  57  
  58              case '0':
  59                  break;
  60  
  61              default:
  62                  $model->setState('filter.author_id', (int) $params->get('user_id'));
  63                  break;
  64          }
  65  
  66          // Filter by language
  67          $model->setState('filter.language', $app->getLanguageFilter());
  68  
  69          //  Featured switch
  70          switch ($params->get('show_featured'))
  71          {
  72              case '1':
  73                  $model->setState('filter.featured', 'only');
  74                  break;
  75              case '0':
  76                  $model->setState('filter.featured', 'hide');
  77                  break;
  78              default:
  79                  $model->setState('filter.featured', 'show');
  80                  break;
  81          }
  82  
  83          // Set ordering
  84          $order_map = array(
  85              'm_dsc' => 'a.modified DESC, a.created',
  86              'mc_dsc' => 'CASE WHEN (a.modified = '.$db->quote($db->getNullDate()).') THEN a.created ELSE a.modified END',
  87              'c_dsc' => 'a.created',
  88              'p_dsc' => 'a.publish_up',
  89          );
  90          $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.publish_up');
  91          $dir = 'DESC';
  92  
  93          $model->setState('list.ordering', $ordering);
  94          $model->setState('list.direction', $dir);
  95  
  96          $items = $model->getItems();
  97  
  98          foreach ($items as &$item) {
  99              $item->slug = $item->id.':'.$item->alias;
 100              $item->catslug = $item->catid.':'.$item->category_alias;
 101  
 102              if ($access || in_array($item->access, $authorised)) {
 103                  // We know that user has the privilege to view the article
 104                  $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
 105              } else {
 106                  $item->link = JRoute::_('index.php?option=com_users&view=login');
 107              }
 108          }
 109  
 110          return $items;
 111      }
 112  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1