/modules/mod_articles_latest/helper.php
PHP | 93 lines | 55 code | 16 blank | 22 comment | 5 complexity | b9708ece4fc1d8c92b0f37e39b17618d MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
- <?php
- /**
- * @version $Id$
- * @package Joomla.Site
- * @subpackage mod_articles_latest
- * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE.txt
- */
- // no direct access
- defined('_JEXEC') or die;
- require_once JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php';
- JModel::addIncludePath(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'models');
- abstract class modArticlesLatestHelper
- {
- public static function getList(&$params)
- {
- // Get an instance of the generic articles model
- $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
- // Set application parameters in model
- $appParams = JFactory::getApplication()->getParams();
- $model->setState('params', $appParams);
- // Set the filters based on the module params
- $model->setState('list.start', 0);
- $model->setState('list.limit', (int) $params->get('count', 5));
- $model->setState('filter.published', 1);
- // Access filter
- $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
- $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
- $model->setState('filter.access', $access);
- // Category filter
- if ($catid = $params->get('catid')) {
- $model->setState('filter.category_id', $catid);
- }
- // User filter
- $userId = JFactory::getUser()->get('id');
- switch ($params->get('user_id'))
- {
- case 'by_me':
- $model->setState('filter.author_id', $userId);
- break;
- case 'not_me':
- $model->setState('filter.author_id', $userId);
- $model->setState('filter.author_id.include', false);
- break;
- }
- // Set ordering
- $order_map = array(
- 'm_dsc' => 'a.modified DESC, a.created',
- /*
- * TODO below line does not work because it's running through JDatabase::_getEscaped
- * which adds unnecessary quotes before and after the null date.
- * This should be uncommented when it's fixed.
- */
- //'mc_dsc' => 'CASE WHEN (a.modified = \'0000-00-00 00:00:00\') THEN a.created ELSE a.modified END',
- 'c_dsc' => 'a.created'
- );
- $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.created');
- $dir = 'DESC';
- $model->setState('list.ordering', $ordering);
- $model->setState('list.direction', $dir);
- $items = $model->getItems();
- foreach ($items as &$item) {
- $item->slug = $item->id.':'.$item->alias;
- $item->catslug = $item->catid.':'.$item->category_alias;
- if ($access || in_array($item->access, $authorised))
- {
- // We know that user has the privilege to view the article
- $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
- }
- else {
- $item->link = JRoute::_('index.php?option=com_user&view=login');
- }
- $item->introtext = JHtml::_('content.prepare', $item->introtext);
- }
- return $items;
- }
- }