1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<?php
class Ez_Form_Element_Timezone extends Zend_Form_Element_Multi
{
private $timezone_identifiers = array();
private $areas = array('Africa', 'America', 'Antartica', 'Arctic', 'Asia',
'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
public $helper = 'formSelect';
public function __construct($spec, $options = null)
{
$this->timezone_identifiers = DateTimeZone::listIdentifiers();
foreach($this->timezone_identifiers as $zone) {
$zone = explode('/',$zone);
if (in_array($zone[0], $this->areas)) {
$listZone[$zone[0]]["{$zone[0]}/{$zone[1]}"] = $zone[1];
asort($listZone[$zone[0]], SORT_STRING);
}
}
$this->setMultiOptions($listZone);
parent::__construct($spec, $options);
}
public function setAreas(array $areas)
{
$this->areas = $areas;
}
public function addAreas($areas)
{
if (is_string($areas)) {
$this->areas[] = $areas;
}elseif (is_array($areas)) {
$this->areas = array_merge($this->areas, $areas);
} else {
throw new Ez_Exception("Argument 1 passed to ".__METHOD__." must be a string or an array, ".gettype($areas)." given");
}
sort($this->areas, SORT_STRING);
}
} |
Partager