Source for file timezone.php

Documentation is available at timezone.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  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 Platform.
  16.  *
  17.  * @package     Joomla.Platform
  18.  * @subpackage  Form
  19.  * @since       11.1
  20.  */
  21. {
  22.     /**
  23.      * The form field type.
  24.      *
  25.      * @var    string 
  26.      * @since  11.1
  27.      */
  28.     protected $type = 'Timezone';
  29.  
  30.     /**
  31.      * The list of available timezone groups to use.
  32.      *
  33.      * @var    array 
  34.      * @since  11.1
  35.      */
  36.     protected static $zones array('Africa''America''Antarctica''Arctic''Asia''Atlantic''Australia''Europe''Indian''Pacific');
  37.  
  38.     /**
  39.      * The keyField of timezone field.
  40.      *
  41.      * @var    integer 
  42.      * @since  3.2
  43.      */
  44.     protected $keyField;
  45.  
  46.     /**
  47.      * Method to get certain otherwise inaccessible properties from the form field object.
  48.      *
  49.      * @param   string  $name  The property name for which to the the value.
  50.      *
  51.      * @return  mixed  The property value or null.
  52.      *
  53.      * @since   3.2
  54.      */
  55.     public function __get($name)
  56.     {
  57.         switch ($name)
  58.         {
  59.             case 'keyField':
  60.                 return $this->$name;
  61.         }
  62.  
  63.         return parent::__get($name);
  64.     }
  65.  
  66.     /**
  67.      * Method to set certain otherwise inaccessible properties of the form field object.
  68.      *
  69.      * @param   string  $name   The property name for which to the the value.
  70.      * @param   mixed   $value  The value of the property.
  71.      *
  72.      * @return  void 
  73.      *
  74.      * @since   3.2
  75.      */
  76.     public function __set($name$value)
  77.     {
  78.         switch ($name)
  79.         {
  80.             case 'keyField':
  81.                 $this->keyField = (string) $value;
  82.                 break;
  83.  
  84.             default:
  85.                 parent::__set($name$value);
  86.         }
  87.     }
  88.  
  89.     /**
  90.      * Method to attach a JForm object to the field.
  91.      *
  92.      * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  93.      * @param   mixed             $value    The form field value to validate.
  94.      * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  95.      *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  96.      *                                       full field name would end up being "bar[foo]".
  97.      *
  98.      * @return  boolean  True on success.
  99.      *
  100.      * @see     JFormField::setup()
  101.      * @since   3.2
  102.      */
  103.     public function setup(SimpleXMLElement $element$value$group null)
  104.     {
  105.         $return parent::setup($element$value$group);
  106.  
  107.         if ($return)
  108.         {
  109.             $this->keyField = (string) $this->element['key_field'];
  110.         }
  111.  
  112.         return $return;
  113.     }
  114.  
  115.     /**
  116.      * Method to get the time zone field option groups.
  117.      *
  118.      * @return  array  The field option objects as a nested array in groups.
  119.      *
  120.      * @since   11.1
  121.      */
  122.     protected function getGroups()
  123.     {
  124.         $groups array();
  125.  
  126.         $keyField !empty($this->keyField$this->keyField : 'id';
  127.         $keyValue $this->form->getValue($keyField);
  128.  
  129.         // If the timezone is not set use the server setting.
  130.         if (strlen($this->value== && empty($keyValue))
  131.         {
  132.             $this->value = JFactory::getConfig()->get('offset');
  133.         }
  134.  
  135.         // Get the list of time zones from the server.
  136.         $zones DateTimeZone::listIdentifiers();
  137.  
  138.         // Build the group lists.
  139.         foreach ($zones as $zone)
  140.         {
  141.             // Time zones not in a group we will ignore.
  142.             if (strpos($zone'/'=== false)
  143.             {
  144.                 continue;
  145.             }
  146.  
  147.             // Get the group/locale from the timezone.
  148.             list ($group$localeexplode('/'$zone2);
  149.  
  150.             // Only use known groups.
  151.             if (in_array($groupself::$zones))
  152.             {
  153.                 // Initialize the group if necessary.
  154.                 if (!isset($groups[$group]))
  155.                 {
  156.                     $groups[$grouparray();
  157.                 }
  158.  
  159.                 // Only add options where a locale exists.
  160.                 if (!empty($locale))
  161.                 {
  162.                     $groups[$group][$zoneJHtml::_('select.option'$zonestr_replace('_'' '$locale)'value''text'false);
  163.                 }
  164.             }
  165.         }
  166.  
  167.         // Sort the group lists.
  168.         ksort($groups);
  169.  
  170.         foreach ($groups as &$location)
  171.         {
  172.             sort($location);
  173.         }
  174.  
  175.         // Merge any additional groups in the XML definition.
  176.         $groups array_merge(parent::getGroups()$groups);
  177.  
  178.         return $groups;
  179.     }
  180. }

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