[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_content/models/ -> archive.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   * Content Component Archive Model
  16   *
  17   * @package        Joomla.Site
  18   * @subpackage    com_content
  19   * @since        1.5
  20   */
  21  class ContentModelArchive extends ContentModelArticles
  22  {
  23      /**
  24       * Model context string.
  25       *
  26       * @var        string
  27       */
  28      public $_context = 'com_content.archive';
  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();
  40  
  41          // Add archive properties
  42          $params = $this->state->params;
  43  
  44          // Filter on archived articles
  45          $this->setState('filter.published', 2);
  46  
  47          // Filter on month, year
  48          $this->setState('filter.month', JRequest::getInt('month'));
  49          $this->setState('filter.year', JRequest::getInt('year'));
  50  
  51          // Optional filter text
  52          $this->setState('list.filter', JRequest::getString('filter-search'));
  53  
  54          // Get list limit
  55          $app = JFactory::getApplication();
  56          $itemid = JRequest::getInt('Itemid', 0);
  57          $limit = $app->getUserStateFromRequest('com_content.archive.list' . $itemid . '.limit', 'limit', $params->get('display_num'));
  58          $this->setState('list.limit', $limit);
  59      }
  60  
  61      /**
  62       * @return    JDatabaseQuery
  63       */
  64  	function getListQuery()
  65      {
  66          // Set the archive ordering
  67          $params = $this->state->params;
  68          $articleOrderby = $params->get('orderby_sec', 'rdate');
  69          $articleOrderDate = $params->get('order_date');
  70  
  71          // No category ordering
  72          $categoryOrderby = '';
  73          $secondary = ContentHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', ';
  74          $primary = ContentHelperQuery::orderbyPrimary($categoryOrderby);
  75  
  76          $orderby = $primary . ' ' . $secondary . ' a.created DESC ';
  77          $this->setState('list.ordering', $orderby);
  78          $this->setState('list.direction', '');
  79          // Create a new query object.
  80          $query = parent::getListQuery();
  81  
  82              // Add routing for archive
  83              //sqlsrv changes
  84          $case_when = ' CASE WHEN ';
  85          $case_when .= $query->charLength('a.alias');
  86          $case_when .= ' THEN ';
  87          $a_id = $query->castAsChar('a.id');
  88          $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
  89          $case_when .= ' ELSE ';
  90          $case_when .= $a_id.' END as slug';
  91  
  92          $query->select($case_when);
  93  
  94          $case_when = ' CASE WHEN ';
  95          $case_when .= $query->charLength('c.alias');
  96          $case_when .= ' THEN ';
  97          $c_id = $query->castAsChar('c.id');
  98          $case_when .= $query->concatenate(array($c_id, 'c.alias'), ':');
  99          $case_when .= ' ELSE ';
 100          $case_when .= $c_id.' END as catslug';
 101          $query->select($case_when);
 102  
 103          // Filter on month, year
 104          // First, get the date field
 105          $queryDate = ContentHelperQuery::getQueryDate($articleOrderDate);
 106  
 107          if ($month = $this->getState('filter.month')) {
 108              $query->where('MONTH('. $queryDate . ') = ' . $month);
 109          }
 110  
 111          if ($year = $this->getState('filter.year')) {
 112              $query->where('YEAR('. $queryDate . ') = ' . $year);
 113          }
 114  
 115          //echo nl2br(str_replace('#__','jos_',$query));
 116  
 117          return $query;
 118      }
 119  
 120      /**
 121       * Method to get the archived article list
 122       *
 123       * @access public
 124       * @return array
 125       */
 126  	public function getData()
 127      {
 128          $app = JFactory::getApplication();
 129  
 130          // Lets load the content if it doesn't already exist
 131          if (empty($this->_data)) {
 132              // Get the page/component configuration
 133              $params = $app->getParams();
 134  
 135              // Get the pagination request variables
 136              $limit        = JRequest::getVar('limit', $params->get('display_num', 20), '', 'int');
 137              $limitstart    = JRequest::getVar('limitstart', 0, '', 'int');
 138  
 139              $query = $this->_buildQuery();
 140  
 141              $this->_data = $this->_getList($query, $limitstart, $limit);
 142          }
 143  
 144          return $this->_data;
 145      }
 146  
 147      // JModel override to add alternating value for $odd
 148  	protected function _getList($query, $limitstart=0, $limit=0)
 149      {
 150          $result = parent::_getList($query, $limitstart, $limit);
 151  
 152          $odd = 1;
 153          foreach ($result as $k => $row) {
 154              $result[$k]->odd = $odd;
 155              $odd = 1 - $odd;
 156          }
 157  
 158          return $result;
 159      }
 160  }


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