Source for file templates.php

Documentation is available at templates.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 extension 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.                 'name''a.name',
  35.                 'folder''a.folder',
  36.                 'element''a.element',
  37.                 'checked_out''a.checked_out',
  38.                 'checked_out_time''a.checked_out_time',
  39.                 'state''a.state',
  40.                 'enabled''a.enabled',
  41.                 'access''a.access''access_level',
  42.                 'ordering''a.ordering',
  43.                 'client_id''a.client_id',
  44.             );
  45.         }
  46.  
  47.         parent::__construct($config);
  48.     }
  49.  
  50.     /**
  51.      * Override parent getItems to add extra XML metadata.
  52.      *
  53.      * @return  array 
  54.      *
  55.      * @since   1.6
  56.      */
  57.     public function getItems()
  58.     {
  59.         $items parent::getItems();
  60.  
  61.         foreach ($items as &$item)
  62.         {
  63.             $client JApplicationHelper::getClientInfo($item->client_id);
  64.             $item->xmldata TemplatesHelper::parseXMLTemplateFile($client->path$item->element);
  65.         }
  66.  
  67.         return $items;
  68.     }
  69.  
  70.     /**
  71.      * Build an SQL query to load the list data.
  72.      *
  73.      * @return  JDatabaseQuery 
  74.      *
  75.      * @since   1.6
  76.      */
  77.     protected function getListQuery()
  78.     {
  79.         // Create a new query object.
  80.         $db $this->getDbo();
  81.         $query $db->getQuery(true);
  82.  
  83.         // Select the required fields from the table.
  84.         $query->select(
  85.             $this->getState(
  86.                 'list.select',
  87.                 'a.extension_id, a.name, a.element, a.client_id'
  88.             )
  89.         );
  90.         $query->from($db->quoteName('#__extensions'' AS a');
  91.  
  92.         // Filter by extension type.
  93.         $query->where($db->quoteName('type'' = ' $db->quote('template'));
  94.  
  95.         // Filter by client.
  96.         $clientId $this->getState('filter.client_id');
  97.  
  98.         if (is_numeric($clientId))
  99.         {
  100.             $query->where('a.client_id = ' . (int) $clientId);
  101.         }
  102.  
  103.         // Filter by search in title
  104.         $search $this->getState('filter.search');
  105.  
  106.         if (!empty($search))
  107.         {
  108.             if (stripos($search'id:'=== 0)
  109.             {
  110.                 $query->where('a.id = ' . (int) substr($search3));
  111.             }
  112.             else
  113.             {
  114.                 $search $db->quote('%' $db->escape($searchtrue'%');
  115.                 $query->where('(a.element LIKE ' $search ' OR a.name LIKE ' $search ')');
  116.             }
  117.         }
  118.  
  119.         // Add the list ordering clause.
  120.         $query->order($db->escape($this->getState('list.ordering''a.folder')) ' ' $db->escape($this->getState('list.direction''ASC')));
  121.  
  122.         return $query;
  123.     }
  124.  
  125.     /**
  126.      * Method to get a store id based on model configuration state.
  127.      *
  128.      * This is necessary because the model is used by the component and
  129.      * different modules that might need different sets of data or different
  130.      * ordering requirements.
  131.      *
  132.      * @param   string  $id  A prefix for the store id.
  133.      *
  134.      * @return  string  A store id.
  135.      *
  136.      * @since   1.6
  137.      */
  138.     protected function getStoreId($id '')
  139.     {
  140.         // Compile the store id.
  141.         $id .= ':' $this->getState('filter.search');
  142.         $id .= ':' $this->getState('filter.client_id');
  143.  
  144.         return parent::getStoreId($id);
  145.     }
  146.  
  147.     /**
  148.      * Method to auto-populate the model state.
  149.      *
  150.      * Note. Calling getState in this method will result in recursion.
  151.      *
  152.      * @param   string  $ordering   An optional ordering field.
  153.      * @param   string  $direction  An optional direction (asc|desc).
  154.      *
  155.      * @return  void 
  156.      *
  157.      * @since   1.6
  158.      */
  159.     protected function populateState($ordering null$direction null)
  160.     {
  161.         // Load the filter state.
  162.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  163.         $this->setState('filter.search'$search);
  164.  
  165.         $clientId $this->getUserStateFromRequest($this->context . '.filter.client_id''filter_client_id'null);
  166.         $this->setState('filter.client_id'$clientId);
  167.  
  168.         // Load the parameters.
  169.         $params JComponentHelper::getParams('com_templates');
  170.         $this->setState('params'$params);
  171.  
  172.         // List state information.
  173.         parent::populateState('a.element''asc');
  174.     }
  175. }

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