[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_content/models/ -> featured.php (source)

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


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1