[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_templates/models/ -> styles.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  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.component.modellist');
  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  class TemplatesModelStyles extends JModelList
  20  {
  21      /**
  22       * Constructor.
  23       *
  24       * @param    array    An optional associative array of configuration settings.
  25       * @see        JController
  26       * @since    1.6
  27       */
  28  	public function __construct($config = array())
  29      {
  30          if (empty($config['filter_fields'])) {
  31              $config['filter_fields'] = array(
  32                  'id', 'a.id',
  33                  'title', 'a.title',
  34                  'client_id', 'a.client_id',
  35                  'template', 'a.template',
  36                  'home', 'a.home',
  37              );
  38          }
  39  
  40          parent::__construct($config);
  41      }
  42  
  43      /**
  44       * Method to auto-populate the model state.
  45       *
  46       * Note. Calling getState in this method will result in recursion.
  47       *
  48       * @since    1.6
  49       */
  50  	protected function populateState($ordering = null, $direction = null)
  51      {
  52          // Initialise variables.
  53          $app = JFactory::getApplication('administrator');
  54  
  55          // Load the filter state.
  56          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  57          $this->setState('filter.search', $search);
  58  
  59          $template = $this->getUserStateFromRequest($this->context.'.filter.template', 'filter_template', '0', 'cmd');
  60          $this->setState('filter.template', $template);
  61  
  62          $clientId = $this->getUserStateFromRequest($this->context.'.filter.client_id', 'filter_client_id', null);
  63          $this->setState('filter.client_id', $clientId);
  64  
  65          // Load the parameters.
  66          $params = JComponentHelper::getParams('com_templates');
  67          $this->setState('params', $params);
  68  
  69          // List state information.
  70          parent::populateState('a.template', 'asc');
  71      }
  72  
  73      /**
  74       * Method to get a store id based on model configuration state.
  75       *
  76       * This is necessary because the model is used by the component and
  77       * different modules that might need different sets of data or different
  78       * ordering requirements.
  79       *
  80       * @param    string        $id    A prefix for the store id.
  81       *
  82       * @return    string        A store id.
  83       */
  84  	protected function getStoreId($id = '')
  85      {
  86          // Compile the store id.
  87          $id    .= ':'.$this->getState('filter.search');
  88          $id    .= ':'.$this->getState('filter.template');
  89          $id    .= ':'.$this->getState('filter.client_id');
  90  
  91          return parent::getStoreId($id);
  92      }
  93  
  94      /**
  95       * Build an SQL query to load the list data.
  96       *
  97       * @return    JDatabaseQuery
  98       */
  99  	protected function getListQuery()
 100      {
 101          // Create a new query object.
 102          $db        = $this->getDbo();
 103          $query    = $db->getQuery(true);
 104  
 105          // Select the required fields from the table.
 106          $query->select(
 107              $this->getState(
 108                  'list.select',
 109                  'a.id, a.template, a.title, a.home, a.client_id, l.title AS language_title, l.image as image'
 110              )
 111          );
 112          $query->from($db->quoteName('#__template_styles').' AS a');
 113  
 114          // Join on menus.
 115          $query->select('COUNT(m.template_style_id) AS assigned');
 116          $query->leftjoin('#__menu AS m ON m.template_style_id = a.id');
 117          $query->group('a.id, a.template, a.title, a.home, a.client_id, l.title, l.image, e.extension_id');
 118  
 119          // Join over the language
 120          $query->join('LEFT', '#__languages AS l ON l.lang_code = a.home');
 121  
 122          // Filter by extension enabled
 123          $query->select('extension_id AS e_id');
 124          $query->join('LEFT', '#__extensions AS e ON e.element = a.template');
 125          $query->where('e.enabled = 1');
 126          $query->where($db->quoteName('e.type') . '=' . $db->quote('template'));
 127  
 128          // Filter by template.
 129          if ($template = $this->getState('filter.template')) {
 130              $query->where('a.template = '.$db->quote($template));
 131          }
 132  
 133          // Filter by client.
 134          $clientId = $this->getState('filter.client_id');
 135          if (is_numeric($clientId)) {
 136              $query->where('a.client_id = '.(int) $clientId);
 137          }
 138  
 139          // Filter by search in title
 140          $search = $this->getState('filter.search');
 141          if (!empty($search)) {
 142              if (stripos($search, 'id:') === 0) {
 143                  $query->where('a.id = '.(int) substr($search, 3));
 144              } else {
 145                  $search = $db->Quote('%'.$db->escape($search, true).'%');
 146                  $query->where('a.template LIKE '.$search.' OR a.title LIKE '.$search);
 147              }
 148          }
 149  
 150          // Add the list ordering clause.
 151          $query->order($db->escape($this->getState('list.ordering', 'a.title')).' '.$db->escape($this->getState('list.direction', 'ASC')));
 152  
 153          //echo nl2br(str_replace('#__','jos_',$query));
 154          return $query;
 155      }
 156  }


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