Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  mod_latest
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR '/components/com_content/models''ContentModel');
  13.  
  14. /**
  15.  * Helper for mod_latest
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  mod_latest
  19.  * @since       1.5
  20.  */
  21. abstract class ModLatestHelper
  22. {
  23.     /**
  24.      * Get a list of articles.
  25.      *
  26.      * @param   JRegistry  &$params  The module parameters.
  27.      *
  28.      * @return  mixed  An array of articles, or false on error.
  29.      */
  30.     public static function getList(&$params)
  31.     {
  32.         $user JFactory::getuser();
  33.  
  34.         // Get an instance of the generic articles model
  35.         $model JModelLegacy::getInstance('Articles''ContentModel'array('ignore_request' => true));
  36.  
  37.         // Set List SELECT
  38.         $model->setState('list.select''a.id, a.title, a.checked_out, a.checked_out_time, ' .
  39.             ' a.access, a.created, a.created_by, a.created_by_alias, a.featured, a.state');
  40.  
  41.         // Set Ordering filter
  42.         switch ($params->get('ordering'))
  43.         {
  44.             case 'm_dsc':
  45.                 $model->setState('list.ordering''modified DESC, created');
  46.                 $model->setState('list.direction''DESC');
  47.                 break;
  48.  
  49.             case 'c_dsc':
  50.             default:
  51.                 $model->setState('list.ordering''created');
  52.                 $model->setState('list.direction''DESC');
  53.                 break;
  54.         }
  55.  
  56.         // Set Category Filter
  57.         $categoryId $params->get('catid');
  58.  
  59.         if (is_numeric($categoryId))
  60.         {
  61.             $model->setState('filter.category_id'$categoryId);
  62.         }
  63.  
  64.         // Set User Filter.
  65.         $userId $user->get('id');
  66.  
  67.         switch ($params->get('user_id'))
  68.         {
  69.             case 'by_me':
  70.                 $model->setState('filter.author_id'$userId);
  71.                 break;
  72.  
  73.             case 'not_me':
  74.                 $model->setState('filter.author_id'$userId);
  75.                 $model->setState('filter.author_id.include'false);
  76.                 break;
  77.         }
  78.  
  79.         // Set the Start and Limit
  80.         $model->setState('list.start'0);
  81.         $model->setState('list.limit'$params->get('count'5));
  82.  
  83.         $items $model->getItems();
  84.  
  85.         if ($error $model->getError())
  86.         {
  87.             JError::raiseError(500$error);
  88.  
  89.             return false;
  90.         }
  91.  
  92.         // Set the links
  93.         foreach ($items as &$item)
  94.         {
  95.             if ($user->authorise('core.edit''com_content.article.' $item->id))
  96.             {
  97.                 $item->link JRoute::_('index.php?option=com_content&task=article.edit&id=' $item->id);
  98.             }
  99.             else
  100.             {
  101.                 $item->link '';
  102.             }
  103.         }
  104.  
  105.         return $items;
  106.     }
  107.  
  108.     /**
  109.      * Get the alternate title for the module.
  110.      *
  111.      * @param   JRegistry  $params  The module parameters.
  112.      *
  113.      * @return  string  The alternate title for the module.
  114.      */
  115.     public static function getTitle($params)
  116.     {
  117.         $who   $params->get('user_id');
  118.         $catid = (int) $params->get('catid');
  119.         $type  $params->get('ordering'== 'c_dsc' '_CREATED' '_MODIFIED';
  120.  
  121.         if ($catid)
  122.         {
  123.             $category JCategories::getInstance('Content')->get($catid);
  124.  
  125.             if ($category)
  126.             {
  127.                 $title $category->title;
  128.             }
  129.             else
  130.             {
  131.                 $title JText::_('MOD_POPULAR_UNEXISTING');
  132.             }
  133.         }
  134.         else
  135.         {
  136.             $title '';
  137.         }
  138.  
  139.         return JText::plural('MOD_LATEST_TITLE' $type ($catid "_CATEGORY" ''($who != '0' "_$who'')(int) $params->get('count')$title);
  140.     }
  141. }

Documentation generated on Tue, 19 Nov 2013 15:04:23 +0100 by phpDocumentor 1.4.3