TimeList.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov, Igor V. Gulyaev    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: TimeList.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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) {/* ignore */}
00066             }
00067             
00068             return $list;
00069         }
00070     }
00071 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4