[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_weblinks/models/ -> weblinks.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: weblinks.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   * Weblinks Component Weblink Model
  22   *
  23   * @package        Joomla
  24   * @subpackage    Content
  25   * @since 1.5
  26   */
  27  class WeblinksModelWeblinks extends JModel
  28  {
  29      /**
  30       * Category ata array
  31       *
  32       * @var array
  33       */
  34      var $_data = null;
  35  
  36      /**
  37       * Category total
  38       *
  39       * @var integer
  40       */
  41      var $_total = null;
  42  
  43      /**
  44       * Pagination object
  45       *
  46       * @var object
  47       */
  48      var $_pagination = null;
  49  
  50      /**
  51       * Constructor
  52       *
  53       * @since 1.5
  54       */
  55  	function __construct()
  56      {
  57          parent::__construct();
  58  
  59          global $mainframe, $option;
  60  
  61          // Get the pagination request variables
  62          $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
  63          $limitstart    = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
  64  
  65          // In case limit has been changed, adjust limitstart accordingly
  66          $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
  67  
  68          $this->setState('limit', $limit);
  69          $this->setState('limitstart', $limitstart);
  70      }
  71  
  72      /**
  73       * Method to get weblinks item data
  74       *
  75       * @access public
  76       * @return array
  77       */
  78  	function getData()
  79      {
  80          // Lets load the content if it doesn't already exist
  81          if (empty($this->_data))
  82          {
  83              $query = $this->_buildQuery();
  84              $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
  85          }
  86  
  87          return $this->_data;
  88      }
  89  
  90      /**
  91       * Method to get the total number of weblink items
  92       *
  93       * @access public
  94       * @return integer
  95       */
  96  	function getTotal()
  97      {
  98          // Lets load the content if it doesn't already exist
  99          if (empty($this->_total))
 100          {
 101              $query = $this->_buildQuery();
 102              $this->_total = $this->_getListCount($query);
 103          }
 104  
 105          return $this->_total;
 106      }
 107  
 108      /**
 109       * Method to get a pagination object for the weblinks
 110       *
 111       * @access public
 112       * @return integer
 113       */
 114  	function getPagination()
 115      {
 116          // Lets load the content if it doesn't already exist
 117          if (empty($this->_pagination))
 118          {
 119              jimport('joomla.html.pagination');
 120              $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
 121          }
 122  
 123          return $this->_pagination;
 124      }
 125  
 126  	function _buildQuery()
 127      {
 128          // Get the WHERE and ORDER BY clauses for the query
 129          $where        = $this->_buildContentWhere();
 130          $orderby    = $this->_buildContentOrderBy();
 131  
 132          $query = ' SELECT a.*, cc.title AS category, u.name AS editor '
 133              . ' FROM #__weblinks AS a '
 134              . ' LEFT JOIN #__categories AS cc ON cc.id = a.catid '
 135              . ' LEFT JOIN #__users AS u ON u.id = a.checked_out '
 136              . $where
 137              . $orderby
 138          ;
 139  
 140          return $query;
 141      }
 142  
 143  	function _buildContentOrderBy()
 144      {
 145          global $mainframe, $option;
 146  
 147          $filter_order        = $mainframe->getUserStateFromRequest( $option.'filter_order',        'filter_order',        'a.ordering',    'cmd' );
 148          $filter_order_Dir    = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir',    'filter_order_Dir',    '',                'word' );
 149  
 150          // sanitize $filter_order
 151          if (!in_array($filter_order, array('a.title', 'a.published', 'a.ordering', 'category', 'a.hits', 'a.id'))) {
 152              $filter_order = 'a.ordering';
 153          }
 154  
 155          if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 156              $filter_order_Dir = '';
 157          }
 158  
 159          if ($filter_order == 'a.ordering'){
 160              $orderby     = ' ORDER BY category, a.ordering '.$filter_order_Dir;
 161          } else {
 162              $orderby     = ' ORDER BY '.$filter_order.' '.$filter_order_Dir.' , category, a.ordering ';
 163          }
 164  
 165          return $orderby;
 166      }
 167  
 168  	function _buildContentWhere()
 169      {
 170          global $mainframe, $option;
 171          $db                    =& JFactory::getDBO();
 172          $filter_state        = $mainframe->getUserStateFromRequest( $option.'filter_state',        'filter_state',        '',                'word' );
 173          $filter_catid        = $mainframe->getUserStateFromRequest( $option.'filter_catid',        'filter_catid',        0,                'int' );
 174          $filter_order        = $mainframe->getUserStateFromRequest( $option.'filter_order',        'filter_order',        'a.ordering',    'cmd' );
 175          $filter_order_Dir    = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir',    'filter_order_Dir',    '',                'word' );
 176          $search                = $mainframe->getUserStateFromRequest( $option.'search',            'search',            '',                'string' );
 177          if (strpos($search, '"') !== false) {
 178              $search = str_replace(array('=', '<'), '', $search);
 179          }
 180          $search = JString::strtolower($search);
 181  
 182          $where = array();
 183  
 184          if ($filter_catid > 0) {
 185              $where[] = 'a.catid = '.(int) $filter_catid;
 186          }
 187          if ($search) {
 188              $where[] = 'LOWER(a.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
 189          }
 190          if ( $filter_state ) {
 191              if ( $filter_state == 'P' ) {
 192                  $where[] = 'a.published = 1';
 193              } else if ($filter_state == 'U' ) {
 194                  $where[] = 'a.published = 0';
 195              }
 196          }
 197  
 198          $where         = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
 199  
 200          return $where;
 201      }
 202  }


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