ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDateList.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
34class ilDateList implements Iterator
35{
36 const TYPE_DATE = 1;
37 const TYPE_DATETIME = 2;
38
39 protected $list_item = array();
40
41 protected $type;
42
50 public function __construct($a_type)
51 {
52 $this->type = $a_type;
53 $this->list_item = array();
54 }
55
56 // Iterator
61 public function rewind()
62 {
63 reset($this->list_item);
64 }
65
70 public function current()
71 {
72 return current($this->list_item);
73 }
74
79 public function key()
80 {
81 return key($this->list_item);
82 }
83
88 public function next()
89 {
90 return next($this->list_item);
91 }
92
97 public function valid()
98 {
99 return $this->current() !== false;
100 }
101
102
109 public function get()
110 {
111 return $this->list_item ? $this->list_item : array();
112 }
113
121 public function getAtPosition($a_pos)
122 {
123 $counter = 1;
124 foreach ($this->get() as $item) {
125 if ($counter++ == $a_pos) {
126 return $item;
127 }
128 }
129 return null;
130 }
131
138 public function add($date)
139 {
140 // the unix time is the key.
141 // It's casted to string because array_merge overwrites only string keys
142 // @see merge
143 $this->list_item[(string) $date->get(IL_CAL_UNIX)] = clone $date;
144 }
145
153 public function merge(ilDateList $other_list)
154 {
155 foreach ($other_list->get() as $new_date) {
156 $this->add($new_date);
157 }
158 }
159
167 public function remove(ilDateTime $remove)
168 {
169 $unix_remove = $remove->get(IL_CAL_UNIX);
170 if (isset($this->list_item[$unix_remove])) {
171 unset($this->list_item[$unix_remove]);
172 }
173 return true;
174 }
175
176 public function removeByDAY(ilDateTime $remove)
177 {
178 foreach ($this->list_item as $key => $dt) {
179 if (ilDateTime::_equals($remove, $dt, IL_CAL_DAY, ilTimeZone::UTC)) {
180 unset($this->list_item[$key]);
181 }
182 }
183 return true;
184 }
185
192 public function sort()
193 {
194 return ksort($this->list_item, SORT_NUMERIC);
195 }
196
203 public function __toString()
204 {
205 $out = '<br />';
206 foreach ($this->get() as $date) {
207 $out .= $date->get(IL_CAL_DATETIME, '', 'Europe/Berlin') . '<br/>';
208 }
209 return $out;
210 }
211}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
List of dates.
removeByDAY(ilDateTime $remove)
current()
Iterator Current.
key()
Iterator key.
add($date)
add a date to the date list
rewind()
Iterator Rewind.
merge(ilDateList $other_list)
Merge two lists.
__construct($a_type)
Constructor.
next()
Iterator next.
__toString()
to string
valid()
Iterator valid.
getAtPosition($a_pos)
get item at specific position
sort()
Sort list.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
$a_type
Definition: workflow.php:92