Source for file clients.php

Documentation is available at clients.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_banners
  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. /**
  13.  * Methods supporting a list of banner records.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_banners
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   array  $config  An optional associative array of configuration settings.
  24.      *
  25.      * @see     JController
  26.      * @since   1.6
  27.      */
  28.     public function __construct($config array())
  29.     {
  30.         if (empty($config['filter_fields']))
  31.         {
  32.             $config['filter_fields'array(
  33.                 'id''a.id',
  34.                 'name''a.name',
  35.                 'contact''a.contact',
  36.                 'state''a.state',
  37.                 'checked_out''a.checked_out',
  38.                 'checked_out_time''a.checked_out_time',
  39.                 'nbanners',
  40.                 'purchase_type'
  41.             );
  42.         }
  43.  
  44.         parent::__construct($config);
  45.     }
  46.  
  47.     /**
  48.      * Method to auto-populate the model state.
  49.      *
  50.      * Note. Calling getState in this method will result in recursion.
  51.      *
  52.      * @param   string  $ordering   An optional ordering field.
  53.      * @param   string  $direction  An optional direction (asc|desc).
  54.      *
  55.      * @return  void 
  56.      *
  57.      * @since   1.6
  58.      */
  59.     protected function populateState($ordering null$direction null)
  60.     {
  61.         // Load the filter state.
  62.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  63.         $this->setState('filter.search'$search);
  64.  
  65.         $state $this->getUserStateFromRequest($this->context . '.filter.state''filter_state''''string');
  66.         $this->setState('filter.state'$state);
  67.  
  68.         // Load the parameters.
  69.         $params JComponentHelper::getParams('com_banners');
  70.         $this->setState('params'$params);
  71.  
  72.         // List state information.
  73.         parent::populateState('a.name''asc');
  74.     }
  75.  
  76.     /**
  77.      * Method to get a store id based on model configuration state.
  78.      *
  79.      * This is necessary because the model is used by the component and
  80.      * different modules that might need different sets of data or different
  81.      * ordering requirements.
  82.      *
  83.      * @param   string  $id  A prefix for the store id.
  84.      *
  85.      * @return  string  A store id.
  86.      */
  87.     protected function getStoreId($id '')
  88.     {
  89.         // Compile the store id.
  90.         $id .= ':' $this->getState('filter.search');
  91.         $id .= ':' $this->getState('filter.access');
  92.         $id .= ':' $this->getState('filter.state');
  93.  
  94.         return parent::getStoreId($id);
  95.     }
  96.  
  97.     /**
  98.      * Build an SQL query to load the list data.
  99.      *
  100.      * @return  JDatabaseQuery 
  101.      */
  102.     protected function getListQuery()
  103.     {
  104.         // Create a new query object.
  105.         $db $this->getDbo();
  106.         $query $db->getQuery(true);
  107.  
  108.         $params JComponentHelper::getParams('com_banners');
  109.         $defaultPurchase $params->get('purchase_type'3);
  110.  
  111.         // Select the required fields from the table.
  112.         $query->select(
  113.             $this->getState(
  114.                 'list.select',
  115.                 'a.id AS id,' .
  116.                     'a.name AS name,' .
  117.                     'a.contact AS contact,' .
  118.                     'a.checked_out AS checked_out,' .
  119.                     'a.checked_out_time AS checked_out_time, ' .
  120.                     'a.state AS state,' .
  121.                     'a.metakey AS metakey,' .
  122.                     'a.purchase_type as purchase_type'
  123.             )
  124.         );
  125.  
  126.         $query->from($db->quoteName('#__banner_clients'' AS a');
  127.  
  128.         // Join over the banners for counting
  129.         $query->select('COUNT(b.id) as nbanners')
  130.             ->join('LEFT''#__banners AS b ON a.id = b.cid');
  131.  
  132.         // Join over the users for the checked out user.
  133.         $query->select('uc.name AS editor')
  134.             ->join('LEFT''#__users AS uc ON uc.id=a.checked_out');
  135.  
  136.         // Filter by published state
  137.         $published $this->getState('filter.state');
  138.  
  139.         if (is_numeric($published))
  140.         {
  141.             $query->where('a.state = ' . (int) $published);
  142.         }
  143.         elseif ($published === '')
  144.         {
  145.             $query->where('(a.state IN (0, 1))');
  146.         }
  147.  
  148.         $query->group('a.id, a.name, a.contact, a.checked_out, a.checked_out_time, a.state, a.metakey, a.purchase_type, uc.name');
  149.  
  150.         // Filter by search in title
  151.         $search $this->getState('filter.search');
  152.  
  153.         if (!empty($search))
  154.         {
  155.             if (stripos($search'id:'=== 0)
  156.             {
  157.                 $query->where('a.id = ' . (int) substr($search3));
  158.             }
  159.             else
  160.             {
  161.                 $search $db->quote('%' $db->escape($searchtrue'%');
  162.                 $query->where('a.name LIKE ' $search);
  163.             }
  164.         }
  165.  
  166.         // Filter by purchase type
  167.         $purchaseType $this->getState('filter.purchase_type');
  168.  
  169.         if (!empty($purchaseType))
  170.         {
  171.             if ($defaultPurchase == $purchaseType)
  172.             {
  173.                 $query->where('(a.purchase_type = ' . (int) $purchaseType ' OR a.purchase_type = -1)');
  174.             }
  175.             else
  176.             {
  177.                 $query->where('a.purchase_type = ' . (int) $purchaseType);
  178.             }
  179.         }
  180.  
  181.         $ordering $this->getState('list.ordering''ordering');
  182.  
  183.         if ($ordering == 'nbanners')
  184.         {
  185.             $ordering 'COUNT(b.id)';
  186.         }
  187.  
  188.         // Add the list ordering clause.
  189.         $query->order($db->escape($ordering' ' $db->escape($this->getState('list.direction''ASC')));
  190.  
  191.         return $query;
  192.     }
  193. }

Documentation generated on Tue, 19 Nov 2013 14:55:54 +0100 by phpDocumentor 1.4.3