Source for file styles.php

Documentation is available at styles.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_templates
  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 template style records.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_templates
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   array  $config  An optional associative array of configuration settings.
  24.      *
  25.      * @see     JControllerLegacy
  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.                 'title''a.title',
  35.                 'client_id''a.client_id',
  36.                 'template''a.template',
  37.                 'home''a.home',
  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.      * @param   string  $ordering   An optional ordering field.
  50.      * @param   string  $direction  An optional direction (asc|desc).
  51.      *
  52.      * @return  void 
  53.      *
  54.      * @since   1.6
  55.      */
  56.     protected function populateState($ordering null$direction null)
  57.     {
  58.         // Load the filter state.
  59.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  60.         $this->setState('filter.search'$search);
  61.  
  62.         $template $this->getUserStateFromRequest($this->context . '.filter.template''filter_template');
  63.         $this->setState('filter.template'$template);
  64.  
  65.         $clientId $this->getUserStateFromRequest($this->context . '.filter.client_id''filter_client_id'null);
  66.         $this->setState('filter.client_id'$clientId);
  67.  
  68.         // Load the parameters.
  69.         $params JComponentHelper::getParams('com_templates');
  70.         $this->setState('params'$params);
  71.  
  72.         // List state information.
  73.         parent::populateState('a.template''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.template');
  92.         $id .= ':' $this->getState('filter.client_id');
  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.         // Select the required fields from the table.
  109.         $query->select(
  110.             $this->getState(
  111.                 'list.select',
  112.                 'a.id, a.template, a.title, a.home, a.client_id, l.title AS language_title, l.image as image'
  113.             )
  114.         );
  115.         $query->from($db->quoteName('#__template_styles'' AS a');
  116.  
  117.         // Join on menus.
  118.         $query->select('COUNT(m.template_style_id) AS assigned')
  119.             ->join('LEFT''#__menu AS m ON m.template_style_id = a.id')
  120.             ->group('a.id, a.template, a.title, a.home, a.client_id, l.title, l.image, e.extension_id');
  121.  
  122.         // Join over the language
  123.         $query->join('LEFT''#__languages AS l ON l.lang_code = a.home');
  124.  
  125.         // Filter by extension enabled
  126.         $query->select('extension_id AS e_id')
  127.             ->join('LEFT''#__extensions AS e ON e.element = a.template')
  128.             ->where('e.enabled = 1')
  129.             ->where('e.type=' $db->quote('template'));
  130.  
  131.         // Filter by template.
  132.         if ($template $this->getState('filter.template'))
  133.         {
  134.             $query->where('a.template = ' $db->quote($template));
  135.         }
  136.  
  137.         // Filter by client.
  138.         $clientId $this->getState('filter.client_id');
  139.  
  140.         if (is_numeric($clientId))
  141.         {
  142.             $query->where('a.client_id = ' . (int) $clientId);
  143.         }
  144.  
  145.         // Filter by search in title
  146.         $search $this->getState('filter.search');
  147.  
  148.         if (!empty($search))
  149.         {
  150.             if (stripos($search'id:'=== 0)
  151.             {
  152.                 $query->where('a.id = ' . (int) substr($search3));
  153.             }
  154.             else
  155.             {
  156.                 $search $db->quote('%' $db->escape($searchtrue'%');
  157.                 $query->where('a.template LIKE ' $search ' OR a.title LIKE ' $search);
  158.             }
  159.         }
  160.  
  161.         // Add the list ordering clause.
  162.         $query->order($db->escape($this->getState('list.ordering''a.title')) ' ' $db->escape($this->getState('list.direction''ASC')));
  163.  
  164.         return $query;
  165.     }
  166. }

Documentation generated on Tue, 19 Nov 2013 15:14:43 +0100 by phpDocumentor 1.4.3