00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00016 final class TimeList extends BasePrimitive
00017 {
00018 public function import($scope)
00019 {
00020 if (
00021 empty($scope[$this->name])
00022 || !is_array($scope[$this->name])
00023 )
00024 return null;
00025
00026 $this->raw = $scope[$this->name];
00027 $this->imported = true;
00028
00029 $array = $scope[$this->name];
00030 $list = array();
00031
00032 foreach ($array as $string) {
00033 $timeList = self::stringToTimeList($string);
00034
00035 if ($timeList)
00036 $list[] = $timeList;
00037 }
00038
00039 $this->value = $list;
00040
00041 return ($this->value !== array());
00042 }
00043
00044 public function getActualValue()
00045 {
00046 if (is_array($this->value) && $this->value[0])
00047 return $this->value;
00048 elseif (is_array($this->raw) && $this->raw[0])
00049 return $this->raw;
00050
00051 return array($this->default);
00052 }
00053
00054 public static function stringToTimeList($string)
00055 {
00056 $list = array();
00057
00058 $times = split("([,; \n]+)", $string);
00059
00060 for ($i = 0, $size = count($times); $i < $size; ++$i) {
00061 $time = mb_ereg_replace('[^0-9:]', ':', $times[$i]);
00062
00063 try {
00064 $list[] = Time::create($time);
00065 } catch (WrongArgumentException $e) {}
00066 }
00067
00068 return $list;
00069 }
00070 }
00071 ?>