Source for file banners.php

Documentation is available at banners.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  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.         {
  31.             $config['filter_fields'array(
  32.                 'id''a.id',
  33.                 'cid''a.cid''client_name',
  34.                 'name''a.name',
  35.                 'alias''a.alias',
  36.                 'state''a.state',
  37.                 'ordering''a.ordering',
  38.                 'language''a.language',
  39.                 'catid''a.catid''category_title',
  40.                 'checked_out''a.checked_out',
  41.                 'checked_out_time''a.checked_out_time',
  42.                 'created''a.created',
  43.                 'impmade''a.impmade',
  44.                 'imptotal''a.imptotal',
  45.                 'clicks''a.clicks',
  46.                 'publish_up''a.publish_up',
  47.                 'publish_down''a.publish_down',
  48.                 'state''sticky''a.sticky',
  49.                 'client_id',
  50.                 'category_id',
  51.                 'published'
  52.             );
  53.         }
  54.  
  55.         parent::__construct($config);
  56.     }
  57.  
  58.     /**
  59.      * Method to get the maximum ordering value for each category.
  60.      *
  61.      * @since   1.6
  62.      */
  63.     public function &getCategoryOrders()
  64.     {
  65.         if (!isset($this->cache['categoryorders']))
  66.         {
  67.             $db $this->getDbo();
  68.             $query $db->getQuery(true)
  69.                 ->select('MAX(ordering) as ' $db->quoteName('max'', catid')
  70.                 ->select('catid')
  71.                 ->from('#__banners')
  72.                 ->group('catid');
  73.             $db->setQuery($query);
  74.             $this->cache['categoryorders'$db->loadAssocList('catid'0);
  75.         }
  76.         return $this->cache['categoryorders'];
  77.     }
  78.  
  79.     /**
  80.      * Build an SQL query to load the list data.
  81.      *
  82.      * @return  JDatabaseQuery 
  83.      * @since   1.6
  84.      */
  85.     protected function getListQuery()
  86.     {
  87.         $db $this->getDbo();
  88.         $query $db->getQuery(true);
  89.  
  90.         // Select the required fields from the table.
  91.         $query->select(
  92.             $this->getState(
  93.                 'list.select',
  94.                 'a.id AS id, a.name AS name, a.alias AS alias,' .
  95.                     'a.checked_out AS checked_out,' .
  96.                     'a.checked_out_time AS checked_out_time, a.catid AS catid,' .
  97.                     'a.clicks AS clicks, a.metakey AS metakey, a.sticky AS sticky,' .
  98.                     'a.impmade AS impmade, a.imptotal AS imptotal,' .
  99.                     'a.state AS state, a.ordering AS ordering,' .
  100.                     'a.purchase_type as purchase_type,' .
  101.                     'a.language, a.publish_up, a.publish_down'
  102.             )
  103.         );
  104.         $query->from($db->quoteName('#__banners'' AS a');
  105.  
  106.         // Join over the language
  107.         $query->select('l.title AS language_title')
  108.             ->join('LEFT'$db->quoteName('#__languages'' AS l ON l.lang_code = a.language');
  109.  
  110.         // Join over the users for the checked out user.
  111.         $query->select('uc.name AS editor')
  112.             ->join('LEFT''#__users AS uc ON uc.id=a.checked_out');
  113.  
  114.         // Join over the categories.
  115.         $query->select('c.title AS category_title')
  116.             ->join('LEFT''#__categories AS c ON c.id = a.catid');
  117.  
  118.         // Join over the clients.
  119.         $query->select('cl.name AS client_name,cl.purchase_type as client_purchase_type')
  120.             ->join('LEFT''#__banner_clients AS cl ON cl.id = a.cid');
  121.  
  122.         // Filter by published state
  123.         $published $this->getState('filter.state');
  124.         if (is_numeric($published))
  125.         {
  126.             $query->where('a.state = ' . (int) $published);
  127.         }
  128.         elseif ($published === '')
  129.         {
  130.             $query->where('(a.state IN (0, 1))');
  131.         }
  132.  
  133.         // Filter by category.
  134.         $categoryId $this->getState('filter.category_id');
  135.         if (is_numeric($categoryId))
  136.         {
  137.             $query->where('a.catid = ' . (int) $categoryId);
  138.         }
  139.  
  140.         // Filter by client.
  141.         $clientId $this->getState('filter.client_id');
  142.         if (is_numeric($clientId))
  143.         {
  144.             $query->where('a.cid = ' . (int) $clientId);
  145.         }
  146.  
  147.         // Filter by search in title
  148.         $search $this->getState('filter.search');
  149.         if (!empty($search))
  150.         {
  151.             if (stripos($search'id:'=== 0)
  152.             {
  153.                 $query->where('a.id = ' . (int) substr($search3));
  154.             }
  155.             else
  156.             {
  157.                 $search $db->quote('%' $db->escape($searchtrue'%');
  158.                 $query->where('(a.name LIKE ' $search ' OR a.alias LIKE ' $search ')');
  159.             }
  160.         }
  161.  
  162.         // Filter on the language.
  163.         if ($language $this->getState('filter.language'))
  164.         {
  165.             $query->where('a.language = ' $db->quote($language));
  166.         }
  167.  
  168.         // Add the list ordering clause.
  169.         $orderCol $this->state->get('list.ordering''ordering');
  170.         $orderDirn $this->state->get('list.direction''ASC');
  171.         if ($orderCol == 'ordering' || $orderCol == 'category_title')
  172.         {
  173.             $orderCol 'c.title ' $orderDirn ', a.ordering';
  174.         }
  175.         if ($orderCol == 'client_name')
  176.         {
  177.             $orderCol 'cl.name';
  178.         }
  179.         $query->order($db->escape($orderCol ' ' $orderDirn));
  180.  
  181.         return $query;
  182.     }
  183.  
  184.     /**
  185.      * Method to get a store id based on model configuration state.
  186.      *
  187.      * This is necessary because the model is used by the component and
  188.      * different modules that might need different sets of data or different
  189.      * ordering requirements.
  190.      *
  191.      * @param   string  $id    A prefix for the store id.
  192.      * @return  string  A store id.
  193.      * @since   1.6
  194.      */
  195.     protected function getStoreId($id '')
  196.     {
  197.         // Compile the store id.
  198.         $id .= ':' $this->getState('filter.search');
  199.         $id .= ':' $this->getState('filter.access');
  200.         $id .= ':' $this->getState('filter.state');
  201.         $id .= ':' $this->getState('filter.category_id');
  202.         $id .= ':' $this->getState('filter.language');
  203.  
  204.         return parent::getStoreId($id);
  205.     }
  206.  
  207.     /**
  208.      * Returns a reference to the a Table object, always creating it.
  209.      *
  210.      * @param   type      The table type to instantiate
  211.      * @param   string    A prefix for the table class name. Optional.
  212.      * @param   array     Configuration array for model. Optional.
  213.      * @return  JTable    A database object
  214.      * @since   1.6
  215.      */
  216.     public function getTable($type 'Banner'$prefix 'BannersTable'$config array())
  217.     {
  218.         return JTable::getInstance($type$prefix$config);
  219.     }
  220.  
  221.     /**
  222.      * Method to auto-populate the model state.
  223.      *
  224.      * Note. Calling getState in this method will result in recursion.
  225.      *
  226.      * @since   1.6
  227.      */
  228.     protected function populateState($ordering null$direction null)
  229.     {
  230.         // Load the filter state.
  231.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  232.         $this->setState('filter.search'$search);
  233.  
  234.         $state $this->getUserStateFromRequest($this->context . '.filter.state''filter_state''''string');
  235.         $this->setState('filter.state'$state);
  236.  
  237.         $categoryId $this->getUserStateFromRequest($this->context . '.filter.category_id''filter_category_id''');
  238.         $this->setState('filter.category_id'$categoryId);
  239.  
  240.         $clientId $this->getUserStateFromRequest($this->context . '.filter.client_id''filter_client_id''');
  241.         $this->setState('filter.client_id'$clientId);
  242.  
  243.         $language $this->getUserStateFromRequest($this->context . '.filter.language''filter_language''');
  244.         $this->setState('filter.language'$language);
  245.  
  246.         // Load the parameters.
  247.         $params JComponentHelper::getParams('com_banners');
  248.         $this->setState('params'$params);
  249.  
  250.         // List state information.
  251.         parent::populateState('a.name''asc');
  252.     }
  253. }

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