00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class PrimitiveMultiList extends PrimitiveList
00017 {
00018 private $selected = array();
00019
00020 public function getChoiceValue()
00021 {
00022 return $this->selected;
00023 }
00024
00025 public function getActualChoiceValue()
00026 {
00027 if ($this->value !== null)
00028 return $this->selected;
00029 elseif ($this->default) {
00030 $out = array();
00031
00032 foreach ($this->default as $index)
00033 $out[] = $this->list[$index];
00034
00035 return $out;
00036 }
00037
00038 return array();
00039 }
00040
00044 public function setDefault($default)
00045 {
00046 Assert::isArray($default);
00047
00048 foreach ($default as $index)
00049 Assert::isTrue(array_key_exists($index, $this->list));
00050
00051 return parent::setDefault($default);
00052 }
00053
00054 public function import($scope)
00055 {
00056 if (!BasePrimitive::import($scope))
00057 return null;
00058
00059 if (!$this->list)
00060 throw new WrongStateException(
00061 'list to check is not set; '
00062 .'use PrimitiveArray in case it is intentional'
00063 );
00064
00065 if (is_array($scope[$this->name])) {
00066 $values = array();
00067
00068 foreach ($scope[$this->name] as $value) {
00069 if (isset($this->list[$value])) {
00070 $values[] = $value;
00071 $this->selected[$value] = $this->list[$value];
00072 }
00073 }
00074
00075 if (count($values)) {
00076 $this->value = $values;
00077
00078 return true;
00079 }
00080 } elseif (!empty($scope[$this->name])) {
00081 $this->value = array($scope[$this->name]);
00082
00083 return true;
00084 }
00085
00086 return false;
00087 }
00088
00092 public function clean()
00093 {
00094 $this->selected = array();
00095
00096 return parent::clean();
00097 }
00098 }
00099 ?>