コード例 #1
0
 /**
  * Builds a XMLElement containing a `<select>` with all the available timezone
  * options grouped by the different DateTimeZone constants allowed by an instance
  * of this field. Developers can select what Timezones are available from the
  * Section Editor.
  *
  * @link http://www.php.net/manual/en/class.datetimezone.php
  * @param array $data
  * @param string $prefix
  * @param string $postfix
  * @return XMLElement
  */
 public function buildTZSelection($data = array(), $prefix = null, $postfix = null)
 {
     if (is_null($data)) {
         $data = array();
     }
     $groups = array();
     if ($this->get('required') != 'yes') {
         $groups[] = array(NULL, false, NULL);
     }
     $zones = explode(",", $this->get('available_zones'));
     foreach ($zones as $zone) {
         $timezones = DateTimeObj::getTimezones($zone);
         $options = array();
         foreach ($timezones as $timezone) {
             $tz = new DateTime('now', new DateTimeZone($timezone));
             $options[] = array($timezone, $timezone == $data['value'], sprintf("%s %s", str_replace('_', ' ', substr(strrchr($timezone, '/'), 1)), $tz->format('P')));
         }
         $groups[] = array('label' => ucwords(strtolower($zone)), 'options' => $options);
     }
     $label = new XMLElement('label', $this->get('label'));
     $label->appendChild(Widget::Select("fields{$prefix}[{$this->get('element_name')}]{$postfix}", $groups));
     return $label;
 }