Source for file archive.php

Documentation is available at archive.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.  * Content Component Archive 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.archive';
  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();
  39.  
  40.         $app = JFactory::getApplication();
  41.  
  42.         // Add archive properties
  43.         $params = $this->state->params;
  44.  
  45.         // Filter on archived articles
  46.         $this->setState('filter.published', 2);
  47.  
  48.         // Filter on month, year
  49.         $this->setState('filter.month', $app->input->getInt('month'));
  50.         $this->setState('filter.year', $app->input->getInt('year'));
  51.  
  52.         // Optional filter text
  53.         $this->setState('list.filter', $app->input->getString('filter-search'));
  54.  
  55.         // Get list limit
  56.         $itemid = $app->input->get('Itemid', 0, 'int');
  57.         $limit = $app->getUserStateFromRequest('com_content.archive.list' . $itemid . '.limit', 'limit', $params->get('display_num'), 'uint');
  58.         $this->setState('list.limit', $limit);
  59.     }
  60.  
  61.     /**
  62.      * @return  JDatabaseQuery 
  63.      */
  64.     protected 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', '!=', '0');
  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', '!=', '0');
  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.         {
  109.             $query->where('MONTH('. $queryDate . ') = ' . $month);
  110.         }
  111.  
  112.         if ($year = $this->getState('filter.year'))
  113.         {
  114.             $query->where('YEAR('. $queryDate . ') = ' . $year);
  115.         }
  116.  
  117.         //echo nl2br(str_replace('#__','jos_',$query));
  118.  
  119.         return $query;
  120.     }
  121.  
  122.     /**
  123.      * Method to get the archived article list
  124.      *
  125.      * @access public
  126.      * @return array 
  127.      */
  128.     public function getData()
  129.     {
  130.         $app = JFactory::getApplication();
  131.  
  132.         // Lets load the content if it doesn't already exist
  133.         if (empty($this->_data))
  134.         {
  135.             // Get the page/component configuration
  136.             $params = $app->getParams();
  137.  
  138.             // Get the pagination request variables
  139.             $limit        = $app->input->get('limit', $params->get('display_num', 20), 'uint');
  140.             $limitstart    = $app->input->get('limitstart', 0, 'uint');
  141.  
  142.             $query = $this->_buildQuery();
  143.  
  144.             $this->_data = $this->_getList($query, $limitstart, $limit);
  145.         }
  146.  
  147.         return $this->_data;
  148.     }
  149.  
  150.     // JModelLegacy override to add alternating value for $odd
  151.     protected function _getList($query, $limitstart=0, $limit=0)
  152.     {
  153.         $result = parent::_getList($query, $limitstart, $limit);
  154.  
  155.         $odd = 1;
  156.         foreach ($result as $k => $row)
  157.         {
  158.             $result[$k]->odd = $odd;
  159.             $odd = 1 - $odd;
  160.         }
  161.  
  162.         return $result;
  163.     }
  164. }

Documentation generated on Tue, 19 Nov 2013 14:53:49 +0100 by phpDocumentor 1.4.3