[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_banners/models/ -> clients.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  defined('_JEXEC') or die;
   8  
   9  jimport('joomla.application.component.modellist');
  10  
  11  /**
  12   * Methods supporting a list of banner records.
  13   *
  14   * @package        Joomla.Administrator
  15   * @subpackage    com_banners
  16   * @since        1.6
  17   */
  18  class BannersModelClients extends JModelList
  19  {
  20      /**
  21       * Constructor.
  22       *
  23       * @param    array    An optional associative array of configuration settings.
  24       * @see        JController
  25       * @since    1.6
  26       */
  27  	public function __construct($config = array())
  28      {
  29          if (empty($config['filter_fields'])) {
  30              $config['filter_fields'] = array(
  31                  'id', 'a.id',
  32                  'name', 'a.name',
  33                  'contact', 'a.contact',
  34                  'state', 'a.state',
  35                  'checked_out', 'a.checked_out',
  36                  'checked_out_time', 'a.checked_out_time',
  37                  'nbanners',
  38              );
  39          }
  40  
  41          parent::__construct($config);
  42      }
  43  
  44      /**
  45       * Method to auto-populate the model state.
  46       *
  47       * Note. Calling getState in this method will result in recursion.
  48       *
  49       * @since    1.6
  50       */
  51  	protected function populateState($ordering = null, $direction = null)
  52      {
  53          // Initialise variables.
  54          $app = JFactory::getApplication('administrator');
  55  
  56          // Load the filter state.
  57          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  58          $this->setState('filter.search', $search);
  59  
  60          $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string');
  61          $this->setState('filter.state', $state);
  62  
  63          // Load the parameters.
  64          $params = JComponentHelper::getParams('com_banners');
  65          $this->setState('params', $params);
  66  
  67          // List state information.
  68          parent::populateState('a.name', 'asc');
  69      }
  70  
  71      /**
  72       * Method to get a store id based on model configuration state.
  73       *
  74       * This is necessary because the model is used by the component and
  75       * different modules that might need different sets of data or different
  76       * ordering requirements.
  77       *
  78       * @param    string        $id    A prefix for the store id.
  79       *
  80       * @return    string        A store id.
  81       */
  82  	protected function getStoreId($id = '')
  83      {
  84          // Compile the store id.
  85          $id    .= ':'.$this->getState('filter.search');
  86          $id    .= ':'.$this->getState('filter.access');
  87          $id    .= ':'.$this->getState('filter.state');
  88  
  89          return parent::getStoreId($id);
  90      }
  91  
  92      /**
  93       * Build an SQL query to load the list data.
  94       *
  95       * @return    JDatabaseQuery
  96       */
  97  	protected function getListQuery()
  98      {
  99          // Create a new query object.
 100          $db = $this->getDbo();
 101          $query = $db->getQuery(true);
 102  
 103          // Select the required fields from the table.
 104          $query->select(
 105              $this->getState(
 106                  'list.select',
 107                  'a.id AS id,'.
 108                  'a.name AS name,'.
 109                  'a.contact AS contact,'.
 110                  'a.checked_out AS checked_out,'.
 111                  'a.checked_out_time AS checked_out_time, ' .
 112                  'a.state AS state,'.
 113                  'a.metakey AS metakey,'.
 114                  'a.purchase_type as purchase_type'
 115              )
 116          );
 117  
 118          $query->from($db->quoteName('#__banner_clients').' AS a');
 119  
 120          // Join over the banners for counting
 121          $query->select('COUNT(b.id) as nbanners');
 122          $query->join('LEFT', '#__banners AS b ON a.id = b.cid');
 123  
 124          // Join over the users for the checked out user.
 125          $query->select('uc.name AS editor');
 126          $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
 127  
 128          // Filter by published state
 129          $published = $this->getState('filter.state');
 130          if (is_numeric($published)) {
 131              $query->where('a.state = '.(int) $published);
 132          } elseif ($published === '') {
 133              $query->where('(a.state IN (0, 1))');
 134          }
 135  
 136          $query->group('a.id, b.id,a.name, a.contact, a.checked_out, a.checked_out_time, a.state, a.metakey, a.purchase_type, uc.name, b.cid, uc.id');
 137  
 138          // Filter by search in title
 139          $search = $this->getState('filter.search');
 140          if (!empty($search)) {
 141              if (stripos($search, 'id:') === 0) {
 142                  $query->where('a.id = '.(int) substr($search, 3));
 143              } else {
 144                  $search = $db->Quote('%'.$db->escape($search, true).'%');
 145                  $query->where('a.name LIKE '.$search);
 146              }
 147          }
 148          $ordering_o = $this->getState('list.ordering', 'ordering');
 149          if($ordering_o == 'nbanners')
 150              $ordering_o = 'COUNT(b.id)';
 151          // Add the list ordering clause.
 152          $query->order($db->escape($ordering_o).' '.$db->escape($this->getState('list.direction', 'ASC')));
 153  
 154          //echo nl2br(str_replace('#__','jos_',$query));
 155          return $query;
 156      }
 157  }


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