Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  mod_popular
  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_popular
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  mod_popular
  19.  * @since       1.6
  20.  */
  21. abstract class ModPopularHelper
  22. {
  23.     /**
  24.      * Get a list of the most popular articles
  25.      *
  26.      * @param   JObject  &$params  The module parameters.
  27.      *
  28.      * @return  array 
  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.created, a.hits');
  40.  
  41.         // Set Ordering filter
  42.         $model->setState('list.ordering', 'a.hits');
  43.         $model->setState('list.direction', 'DESC');
  44.  
  45.         // Set Category Filter
  46.         $categoryId = $params->get('catid');
  47.  
  48.         if (is_numeric($categoryId))
  49.         {
  50.             $model->setState('filter.category_id', $categoryId);
  51.         }
  52.  
  53.         // Set User Filter.
  54.         $userId = $user->get('id');
  55.  
  56.         switch ($params->get('user_id'))
  57.         {
  58.             case 'by_me':
  59.                 $model->setState('filter.author_id', $userId);
  60.                 break;
  61.  
  62.             case 'not_me':
  63.                 $model->setState('filter.author_id', $userId);
  64.                 $model->setState('filter.author_id.include', false);
  65.                 break;
  66.         }
  67.  
  68.         // Set the Start and Limit
  69.         $model->setState('list.start', 0);
  70.         $model->setState('list.limit', $params->get('count', 5));
  71.  
  72.         $items = $model->getItems();
  73.  
  74.         if ($error = $model->getError())
  75.         {
  76.             JError::raiseError(500, $error);
  77.  
  78.             return false;
  79.         }
  80.  
  81.         // Set the links
  82.         foreach ($items as &$item)
  83.         {
  84.             if ($user->authorise('core.edit', 'com_content.article.' . $item->id))
  85.             {
  86.                 $item->link = JRoute::_('index.php?option=com_content&task=article.edit&id=' . $item->id);
  87.             }
  88.             else
  89.             {
  90.                 $item->link = '';
  91.             }
  92.         }
  93.  
  94.         return $items;
  95.     }
  96.  
  97.     /**
  98.      * Get the alternate title for the module
  99.      *
  100.      * @param   JObject  $params  The module parameters.
  101.      *
  102.      * @return  string    The alternate title for the module.
  103.      */
  104.     public static function getTitle($params)
  105.     {
  106.         $who = $params->get('user_id');
  107.         $catid = (int) $params->get('catid');
  108.  
  109.         if ($catid)
  110.         {
  111.             $category = JCategories::getInstance('Content')->get($catid);
  112.  
  113.             if ($category)
  114.             {
  115.                 $title = $category->title;
  116.             }
  117.             else
  118.             {
  119.                 $title = JText::_('MOD_POPULAR_UNEXISTING');
  120.             }
  121.         }
  122.         else
  123.         {
  124.             $title = '';
  125.         }
  126.  
  127.         return JText::plural('MOD_POPULAR_TITLE' . ($catid ? "_CATEGORY" : '') . ($who != '0' ? "_$who" : ''), (int) $params->get('count'), $title);
  128.     }
  129. }

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