Source for file featured.php

Documentation is available at featured.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_content
  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. require_once __DIR__ . '/articles.php';
  13.  
  14. /**
  15.  * Frontpage Component Model
  16.  *
  17.  * @package     Joomla.Site
  18.  * @subpackage  com_content
  19.  * @since       1.5
  20.  */
  21. {
  22.     /**
  23.      * Model context string.
  24.      *
  25.      * @var        string 
  26.      */
  27.     public $_context = 'com_content.frontpage';
  28.  
  29.     /**
  30.      * Method to auto-populate the model state.
  31.      *
  32.      * Note. Calling getState in this method will result in recursion.
  33.      *
  34.      * @since   1.6
  35.      */
  36.     protected function populateState($ordering = null, $direction = null)
  37.     {
  38.         parent::populateState($ordering, $direction);
  39.  
  40.         $input = JFactory::getApplication()->input;
  41.         $user  = JFactory::getUser();
  42.  
  43.         // List state information
  44.         $limitstart = $input->getUInt('limitstart', 0);
  45.         $this->setState('list.start', $limitstart);
  46.  
  47.         $params = $this->state->params;
  48.         $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
  49.         $this->setState('list.limit', $limit);
  50.         $this->setState('list.links', $params->get('num_links'));
  51.  
  52.         $this->setState('filter.frontpage', true);
  53.  
  54.         if ((!$user->authorise('core.edit.state', 'com_content')) &&  (!$user->authorise('core.edit', 'com_content'))){
  55.             // filter on published for those who do not have edit or edit.state rights.
  56.             $this->setState('filter.published', 1);
  57.         }
  58.         else
  59.         {
  60.             $this->setState('filter.published', array(0, 1, 2));
  61.         }
  62.  
  63.         // check for category selection
  64.         if ($params->get('featured_categories') && implode(',', $params->get('featured_categories')) == true)
  65.         {
  66.             $featuredCategories = $params->get('featured_categories');
  67.             $this->setState('filter.frontpage.categories', $featuredCategories);
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * Method to get a list of articles.
  73.      *
  74.      * @return  mixed  An array of objects on success, false on failure.
  75.      */
  76.     public function getItems()
  77.     {
  78.         $params = clone $this->getState('params');
  79.         $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
  80.         if ($limit > 0)
  81.         {
  82.             $this->setState('list.limit', $limit);
  83.             return parent::getItems();
  84.         }
  85.         return array();
  86.  
  87.     }
  88.  
  89.     /**
  90.      * Method to get a store id based on model configuration state.
  91.      *
  92.      * This is necessary because the model is used by the component and
  93.      * different modules that might need different sets of data or different
  94.      * ordering requirements.
  95.      *
  96.      * @param   string  $id    A prefix for the store id.
  97.      *
  98.      * @return  string  A store id.
  99.      */
  100.     protected function getStoreId($id = '')
  101.     {
  102.         // Compile the store id.
  103.         $id .= $this->getState('filter.frontpage');
  104.  
  105.         return parent::getStoreId($id);
  106.     }
  107.  
  108.     /**
  109.      * @return  JDatabaseQuery 
  110.      */
  111.     protected function getListQuery()
  112.     {
  113.         // Set the blog ordering
  114.         $params = $this->state->params;
  115.         $articleOrderby = $params->get('orderby_sec', 'rdate');
  116.         $articleOrderDate = $params->get('order_date');
  117.         $categoryOrderby = $params->def('orderby_pri', '');
  118.         $secondary = ContentHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', ';
  119.         $primary = ContentHelperQuery::orderbyPrimary($categoryOrderby);
  120.  
  121.         $orderby = $primary . ' ' . $secondary . ' a.created DESC ';
  122.         $this->setState('list.ordering', $orderby);
  123.         $this->setState('list.direction', '');
  124.  
  125.         // Create a new query object.
  126.         $query = parent::getListQuery();
  127.  
  128.         // Filter by frontpage.
  129.         if ($this->getState('filter.frontpage'))
  130.         {
  131.             $query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id');
  132.         }
  133.  
  134.         // Filter by categories
  135.         $featuredCategories = $this->getState('filter.frontpage.categories');
  136.  
  137.         if (is_array($featuredCategories) && !in_array('', $featuredCategories))
  138.         {
  139.             $query->where('a.catid IN (' . implode(',', $featuredCategories) . ')');
  140.         }
  141.  
  142.         return $query;
  143.     }
  144. }

Documentation generated on Tue, 19 Nov 2013 15:02:51 +0100 by phpDocumentor 1.4.3