ILIAS  release_8 Revision v8.24
class.ilDateList.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
32class ilDateList implements Iterator
33{
34 public const TYPE_DATE = 1;
35 public const TYPE_DATETIME = 2;
36
37 protected array $list_item = array();
38
39 protected int $type;
40
41 public function __construct(int $a_type)
42 {
43 $this->type = $a_type;
44 $this->list_item = array();
45 }
46
50 public function rewind()
51 {
52 reset($this->list_item);
53 }
54
58 public function current()
59 {
60 return current($this->list_item);
61 }
62
66 public function key()
67 {
68 return key($this->list_item);
69 }
70
74 public function next()
75 {
76 return next($this->list_item);
77 }
78
82 public function valid(): bool
83 {
84 return $this->current() !== false;
85 }
86
89 public function get(): array
90 {
91 return $this->list_item ?: array();
92 }
93
97 public function getAtPosition(int $a_pos): ?ilDateTime
98 {
99 $counter = 1;
100 foreach ($this->get() as $item) {
101 if ($counter++ == $a_pos) {
102 return $item;
103 }
104 }
105 return null;
106 }
107
111 public function add(ilDateTime $date): void
112 {
113 $this->list_item[(string) $date->get(IL_CAL_UNIX)] = clone $date;
114 }
115
119 public function merge(ilDateList $other_list): void
120 {
121 foreach ($other_list->get() as $new_date) {
122 $this->add($new_date);
123 }
124 }
125
129 public function remove(ilDateTime $remove): void
130 {
131 $unix_remove = $remove->get(IL_CAL_UNIX);
132 if (isset($this->list_item[$unix_remove])) {
133 unset($this->list_item[$unix_remove]);
134 }
135 }
136
137 public function removeByDAY(ilDateTime $remove): void
138 {
139 foreach ($this->list_item as $key => $dt) {
140 if (ilDateTime::_equals($remove, $dt, IL_CAL_DAY, ilTimeZone::UTC)) {
141 unset($this->list_item[$key]);
142 }
143 }
144 }
145
149 public function sort(): void
150 {
151 ksort($this->list_item, SORT_NUMERIC);
152 }
153
154 public function __toString(): string
155 {
156 $out = '<br />';
157 foreach ($this->get() as $date) {
158 $out .= $date->get(IL_CAL_DATETIME, '', 'Europe/Berlin') . '<br/>';
159 }
160 return $out;
161 }
162}
$out
Definition: buildRTE.php:24
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
List of dates.
removeByDAY(ilDateTime $remove)
current()
@inheritDoc
__construct(int $a_type)
add(ilDateTime $date)
add a date to the date list
key()
@inheritDoc
getAtPosition(int $a_pos)
get item at specific position
rewind()
@inheritDoc
merge(ilDateList $other_list)
Merge two lists.
next()
@inheritDoc
valid()
@inheritDoc
sort()
Sort list.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
string $key
Consumer key/client ID value.
Definition: System.php:193