Source for file templatestyle.php

Documentation is available at templatestyle.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Form
  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
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. JFormHelper::loadFieldClass('groupedlist');
  13.  
  14. /**
  15.  * Form Field class for the Joomla CMS.
  16.  * Supports a select grouped list of template styles
  17.  *
  18.  * @package     Joomla.Libraries
  19.  * @subpackage  Form
  20.  * @since       1.6
  21.  */
  22. {
  23.     /**
  24.      * The form field type.
  25.      *
  26.      * @var    string 
  27.      * @since  1.6
  28.      */
  29.     public $type = 'TemplateStyle';
  30.  
  31.     /**
  32.      * The client name.
  33.      *
  34.      * @var    mixed 
  35.      * @since  3.2
  36.      */
  37.     protected $clientName;
  38.  
  39.     /**
  40.      * The template.
  41.      *
  42.      * @var    mixed 
  43.      * @since  3.2
  44.      */
  45.     protected $template;
  46.  
  47.     /**
  48.      * Method to get certain otherwise inaccessible properties from the form field object.
  49.      *
  50.      * @param   string  $name  The property name for which to the the value.
  51.      *
  52.      * @return  mixed  The property value or null.
  53.      *
  54.      * @since   3.2
  55.      */
  56.     public function __get($name)
  57.     {
  58.         switch ($name)
  59.         {
  60.             case 'clientName':
  61.             case 'template':
  62.                 return $this->$name;
  63.         }
  64.  
  65.         return parent::__get($name);
  66.     }
  67.  
  68.     /**
  69.      * Method to set certain otherwise inaccessible properties of the form field object.
  70.      *
  71.      * @param   string  $name   The property name for which to the the value.
  72.      * @param   mixed   $value  The value of the property.
  73.      *
  74.      * @return  void 
  75.      *
  76.      * @since   3.2
  77.      */
  78.     public function __set($name$value)
  79.     {
  80.         switch ($name)
  81.         {
  82.             case 'clientName':
  83.             case 'template':
  84.                 $this->$name = (string) $value;
  85.                 break;
  86.  
  87.             default:
  88.                 parent::__set($name$value);
  89.         }
  90.     }
  91.  
  92.     /**
  93.      * Method to attach a JForm object to the field.
  94.      *
  95.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  96.      * @param   mixed             $value    The form field value to validate.
  97.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  98.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  99.      *                                       full field name would end up being "bar[foo]".
  100.      *
  101.      * @return  boolean  True on success.
  102.      *
  103.      * @see     JFormField::setup()
  104.      * @since   3.2
  105.      */
  106.     public function setup(SimpleXMLElement $element$value$group null)
  107.     {
  108.         $result parent::setup($element$value$group);
  109.  
  110.         if ($result == true)
  111.         {
  112.             // Get the clientName template.
  113.             $this->clientName = $this->element['client'? (string) $this->element['client''site';
  114.             $this->template = (string) $this->element['template'];
  115.         }
  116.  
  117.         return $result;
  118.     }
  119.  
  120.     /**
  121.      * Method to get the list of template style options grouped by template.
  122.      * Use the client attribute to specify a specific client.
  123.      * Use the template attribute to specify a specific template
  124.      *
  125.      * @return  array  The field option objects as a nested array in groups.
  126.      *
  127.      * @since   1.6
  128.      */
  129.     protected function getGroups()
  130.     {
  131.         $groups array();
  132.         $lang JFactory::getLanguage();
  133.  
  134.         // Get the client and client_id.
  135.         $client JApplicationHelper::getClientInfo($this->clientNametrue);
  136.  
  137.         // Get the template.
  138.         $template $this->template;
  139.  
  140.         // Get the database object and a new query object.
  141.         $db JFactory::getDbo();
  142.         $query $db->getQuery(true);
  143.  
  144.         // Build the query.
  145.         $query->select('s.id, s.title, e.name as name, s.template')
  146.             ->from('#__template_styles as s')
  147.             ->where('s.client_id = ' . (int) $client->id)
  148.             ->order('template')
  149.             ->order('title');
  150.  
  151.         if ($template)
  152.         {
  153.             $query->where('s.template = ' $db->quote($template));
  154.         }
  155.  
  156.         $query->join('LEFT''#__extensions as e on e.element=s.template')
  157.             ->where('e.enabled = 1')
  158.             ->where($db->quoteName('e.type'' = ' $db->quote('template'));
  159.  
  160.         // Set the query and load the styles.
  161.         $db->setQuery($query);
  162.         $styles $db->loadObjectList();
  163.  
  164.         // Build the grouped list array.
  165.         if ($styles)
  166.         {
  167.             foreach ($styles as $style)
  168.             {
  169.                 $template $style->template;
  170.                 $lang->load('tpl_' $template '.sys'$client->pathnullfalsetrue)
  171.                     || $lang->load('tpl_' $template '.sys'$client->path '/templates/' $templatenullfalsetrue);
  172.                 $name JText::_($style->name);
  173.  
  174.                 // Initialize the group if necessary.
  175.                 if (!isset($groups[$name]))
  176.                 {
  177.                     $groups[$namearray();
  178.                 }
  179.  
  180.                 $groups[$name][JHtml::_('select.option'$style->id$style->title);
  181.             }
  182.         }
  183.  
  184.         // Merge any additional groups in the XML definition.
  185.         $groups array_merge(parent::getGroups()$groups);
  186.  
  187.         return $groups;
  188.     }
  189. }

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