/administrator/modules/mod_latest/helper.php
PHP | 93 lines | 53 code | 15 blank | 25 comment | 6 complexity | 44f4e99cb6acd201babec9d15018ac8c MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
- <?php
- /**
- * @version $Id$
- * @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;
- JModel::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_content/models');
- /**
- * @package Joomla.Administrator
- * @subpackage mod_latest
- */
- abstract class modLatestHelper
- {
- /**
- * Get a list of articles.
- *
- * @param JObject The module parameters.
- *
- * @return mixed An array of articles, or false on error.
- */
- public static function getList($params)
- {
- // Initialise variables
- $user = JFactory::getuser();
- // Get an instance of the generic articles model
- $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
- // Set List SELECT
- $model->setState('list.select', 'a.id, a.title, a.checked_out, a.checked_out_time, ' .
- ' a.access, a.created, a.created_by, a.created_by_alias, a.featured');
- // Set Ordering filter
- switch ($params->get('ordering')) {
- case 'm_dsc':
- $model->setState('list.ordering', 'modified DESC, created');
- $model->setState('list.direction', 'DESC');
- break;
- case 'c_dsc':
- default:
- $model->setState('list.ordering', 'created');
- $model->setState('list.direction', 'DESC');
- break;
- }
- // Set Category Filter
- $categoryId = $params->get('catid');
- if (is_numeric($categoryId)){
- $model->setState('filter.category_id', $categoryId);
- }
- // Set User Filter.
- $userId = $user->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 the Start and Limit
- $model->setState('list.start', 0);
- $model->setState('list.limit', $params->get('count', 5));
- $items = $model->getItems();
- if ($error = $model->getError()) {
- JError::raiseError(500, $error);
- return false;
- }
- // Set the links
- foreach ($items as &$item) {
- if ($user->authorise('core.edit','com_content.article.'.$item->id)){
- $item->link = JRoute::_('index.php?option=com_content&task=article.edit&id='.$item->id);
- } else {
- $item->link = '';
- }
- }
- return $items;
- }
- }