[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @version        $Id: archive.php 19343 2010-11-03 18:12:02Z ian $
   4   * @package        Joomla
   5   * @subpackage    Content
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.model');
  19  
  20  /**
  21   * Content Component Archive Model
  22   *
  23   * @package     Joomla
  24   * @subpackage    Content
  25   * @since        1.5
  26   */
  27  class ContentModelArchive extends JModel
  28  {
  29      /**
  30       * Article list array
  31       *
  32       * @var array
  33       */
  34      var $_data = array();
  35  
  36      /**
  37       * Article total
  38       *
  39       * @var integer
  40       */
  41      var $_total = array();
  42  
  43      /**
  44       * Method to get the archived article list
  45       *
  46       * @access public
  47       * @return array
  48       */
  49  	function getData()
  50      {
  51          global $mainframe;
  52          // Lets load the content if it doesn't already exist
  53          if (empty($this->_data))
  54          {
  55              // Get the page/component configuration
  56              $params = &$mainframe->getParams();
  57  
  58              // Get the pagination request variables
  59              $limit        = JRequest::getVar('limit', $params->get('display_num', 20), '', 'int');
  60              $limitstart    = JRequest::getVar('limitstart', 0, '', 'int');
  61  
  62              $query = $this->_buildQuery();
  63  
  64              $this->_data = $this->_getList($query, $limitstart, $limit);
  65          }
  66  
  67          return $this->_data;
  68      }
  69  
  70      /**
  71       * Method to get the total number of content items for the frontpage
  72       *
  73       * @access public
  74       * @return integer
  75       */
  76  	function getTotal()
  77      {
  78          // Lets load the content if it doesn't already exist
  79          if (empty($this->_total))
  80          {
  81              $query = $this->_buildQuery();
  82              $this->_total = $this->_getListCount($query);
  83          }
  84  
  85          return $this->_total;
  86      }
  87  
  88      // JModel override to add alternating value for $odd
  89      function &_getList( $query, $limitstart=0, $limit=0 )
  90      {
  91          $result =& parent::_getList($query, $limitstart, $limit);
  92  
  93          $odd = 1;
  94          foreach ($result as $k => $row) {
  95              $result[$k]->odd = $odd;
  96              $odd = 1 - $odd;
  97          }
  98  
  99          return $result;
 100      }
 101  
 102  	function _buildQuery()
 103      {
 104          global $mainframe;
 105          // Get the page/component configuration
 106          $params = &$mainframe->getParams();
 107  
 108          // If voting is turned on, get voting data as well for the content items
 109          $voting    = ContentHelperQuery::buildVotingQuery($params);
 110  
 111          // Get the WHERE and ORDER BY clauses for the query
 112          $where        = $this->_buildContentWhere();
 113          $orderby    = $this->_buildContentOrderBy();
 114  
 115          $query = 'SELECT a.id, a.title, a.alias, a.title_alias, a.introtext, a.sectionid, a.state, a.catid, a.created, a.created_by, a.created_by_alias, a.modified, a.modified_by,'.
 116              ' a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, a.attribs, a.hits, a.images, a.urls, a.ordering, a.metakey, a.metadesc, a.access, cc.title AS category, s.title AS section,' .
 117              ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug,'.
 118              ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
 119              ' CHAR_LENGTH( a.`fulltext` ) AS readmore, u.name AS author, u.usertype, g.name AS groups'.$voting['select'] .
 120              ' FROM #__content AS a' .
 121              ' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
 122              ' LEFT JOIN #__sections AS s ON s.id = a.sectionid' .
 123              ' LEFT JOIN #__users AS u ON u.id = a.created_by' .
 124              ' LEFT JOIN #__groups AS g ON a.access = g.id'.
 125              $voting['join'].
 126              $where.
 127              $orderby;
 128  
 129          return $query;
 130      }
 131  
 132  	function _buildContentOrderBy()
 133      {
 134          $filter_order        = JRequest::getCmd('filter_order');
 135          $filter_order_Dir    = JRequest::getWord('filter_order_Dir');
 136  
 137          if (!in_array($filter_order, array('a.id', 'a.title', 'a.alias', 'a.title_alias', 'a.introtext', 'a.sectionid', 'a.state', 'a.catid',
 138              'a.created', 'a.created_by', 'a.created_by_alias', 'a.modified', 'a.modified_by', 'a.hits', 'a.ordering', 'cc.title', 's.title'))) {
 139              $filter_order = '';
 140          }
 141  
 142          if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 143              $filter_order_Dir = '';
 144          }
 145  
 146          $orderby = ' ORDER BY ';
 147          if ($filter_order) {
 148              $orderby .= $filter_order.' '.$filter_order_Dir.', ';
 149          }
 150  
 151          // Get the page/component configuration
 152          $params = $this->getState('parameters.menu');
 153          if (!is_object($params)) {
 154              $params = &JComponentHelper::getParams('com_content');
 155          }
 156  
 157          // Special ordering for archive articles
 158          $orderby_sec    = $params->def('orderby', 'rdate');
 159          $primary        = ContentHelperQuery::orderbySecondary($orderby_sec);
 160          $orderby        .= $primary;
 161  
 162          return $orderby;
 163      }
 164  
 165  	function _buildContentWhere()
 166      {
 167          global $mainframe;
 168  
 169          // Initialize some variables
 170          $user    =& JFactory::getUser();
 171          $db        =& JFactory::getDBO();
 172          $aid    = (int) $user->get('aid', 0);
 173  
 174          // First thing we need to do is build the access section of the clause
 175          $where = ' WHERE a.access <= '.$aid;
 176          $where .= ' AND s.access <= '.$aid;
 177          $where .= ' AND cc.access <= '.$aid;
 178          $where .= ' AND s.published = 1';
 179          $where .= ' AND cc.published = 1';
 180  
 181          $where .= ' AND a.state = \'-1\'';
 182          $year    = JRequest::getInt( 'year' );
 183          if ($year) {
 184              $where .= ' AND YEAR( a.created ) = \''.$year.'\'';
 185          }
 186          $month    = JRequest::getInt( 'month' );
 187          if ($month) {
 188              $where .= ' AND MONTH( a.created ) = \''.$month.'\'';
 189          }
 190  
 191          /*
 192           * If we have a filter... lets tack the AND clause
 193           * for the filter onto the WHERE clause of the archive query.
 194           */
 195          $filter = JRequest::getString('filter', '', 'post');
 196          if ($filter) {
 197              // clean filter variable
 198              $filter = JString::strtolower($filter);
 199              $filter    = $db->Quote( '%'.$db->getEscaped( $filter, true ).'%', false );
 200  
 201              // Get the page/component configuration
 202              $params = &$mainframe->getParams();
 203              switch ($params->get('filter_type', 'title'))
 204              {
 205                  case 'title' :
 206                       default :
 207                      $where .= ' AND LOWER( a.title ) LIKE '.$filter;
 208                      break;
 209  
 210                  case 'author' :
 211                      $where .= ' AND ( ( LOWER( u.name ) LIKE '.$filter.' ) OR ( LOWER( a.created_by_alias ) LIKE '.$filter.' ) )';
 212                      break;
 213  
 214                  case 'hits' :
 215                      $where .= ' AND a.hits LIKE '.$filter;
 216                      break;
 217              }
 218          }
 219          return $where;
 220      }
 221  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1