ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
34 class 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  {
126  if($counter++ == $a_pos)
127  {
128  return $item;
129  }
130  }
131  return null;
132  }
133 
140  public function add($date)
141  {
142  // the unix time is the key.
143  // It's casted to string because array_merge overwrites only string keys
144  // @see merge
145  $this->list_item[(string) $date->get(IL_CAL_UNIX)] = clone $date;
146  }
147 
155  public function merge(ilDateList $other_list)
156  {
157  foreach($other_list->get() as $new_date)
158  {
159  $this->add($new_date);
160  }
161  }
162 
170  public function remove(ilDateTime $remove)
171  {
172  $unix_remove = $remove->get(IL_CAL_UNIX);
173  if(isset($this->list_item[$unix_remove]))
174  {
175  unset($this->list_item[$unix_remove]);
176  }
177  return true;
178  }
179 
180  public function removeByDAY(ilDateTime $remove)
181  {
182  foreach($this->list_item as $key => $dt)
183  {
185  {
186  unset($this->list_item[$key]);
187  }
188  }
189  return true;
190  }
191 
198  public function sort()
199  {
200  return ksort($this->list_item,SORT_NUMERIC);
201  }
202 
209  public function __toString()
210  {
211  $out = '<br />';
212  foreach($this->get() as $date)
213  {
214  $out .= $date->get(IL_CAL_DATETIME,'','Europe/Berlin').'<br/>';
215  }
216  return $out;
217  }
218 }
219 
220 ?>