Go to the documentation of this file.00001 <?php
00016 class axSelectHelper extends axBaseHelper {
00017
00024 public function __construct ($name, $values = array(), $multiple = false) {
00025 parent::__construct('select', array('name' => $name));
00026
00027 $this->addOption("--", "");
00028 if (!empty($values))
00029 $this->addOptions($values);
00030
00031 if ($multiple)
00032 $this->setMultiple('multiple');
00033 }
00034
00038 public function setValue ($value) {
00039 if (is_scalar($value)) {
00040 if (isset($this->_children[$value]))
00041 $this->_children[$value]->setSelected("selected");
00042 }
00043 elseif (is_array($value)) {
00044 foreach ($value as $val)
00045 $this->setValue($val);
00046 }
00047 else
00048 throw new RuntimeException("First parameter is expected to be scalar or array, " . gettype($value) . " given", 3004);
00049
00050 return $this;
00051 }
00052
00056 public function getValue () {
00057 return null;
00058 }
00059
00065 public function addOption ($name, $value) {
00066 $this->_children[$value] = axOptionHelper::export($name,$value);
00067 return $this;
00068 }
00069
00076 public function addOptions ($array) {
00077 foreach ($array as $key => $value) {
00078 $this->addOption($key, $value);
00079 }
00080 return $this;
00081 }
00082
00089 public static function export ($name, $values = array(), $multiple = false) {
00090 return new self ($name, $values, $multiple);
00091 }
00092
00093 }