ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDateList.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
27class ilDateList implements Iterator, Countable
28{
29 public const TYPE_DATE = 1;
30 public const TYPE_DATETIME = 2;
31
33 protected array $list_item = [];
34
35 protected int $type;
36
37 public function __construct(int $a_type)
38 {
39 $this->type = $a_type;
40 $this->list_item = [];
41 }
42
43 public function rewind(): void
44 {
45 reset($this->list_item);
46 }
47
48 public function current(): ilDateTime
49 {
50 return current($this->list_item);
51 }
52
53 public function key(): string
54 {
55 return key($this->list_item);
56 }
57
58 public function next(): void
59 {
60 next($this->list_item);
61 }
62
63 public function valid(): bool
64 {
65 return key($this->list_item) !== null;
66 }
67
68 public function count(): int
69 {
70 return count($this->list_item);
71 }
72
74 public function get(): array
75 {
76 return $this->list_item;
77 }
78
79 public function getAtPosition(int $a_pos): ?ilDateTime
80 {
81 $counter = 1;
82 foreach ($this->get() as $item) {
83 if ($counter++ == $a_pos) {
84 return $item;
85 }
86 }
87
88 return null;
89 }
90
91 public function add(ilDateTime $date): void
92 {
93 $this->list_item[(string) $date->get(IL_CAL_UNIX)] = clone $date;
94 }
95
96 public function merge(ilDateList $other_list): void
97 {
98 foreach ($other_list->get() as $new_date) {
99 $this->add($new_date);
100 }
101 }
102
103 public function remove(ilDateTime $remove): void
104 {
105 $unix_remove = (string) $remove->get(IL_CAL_UNIX);
106 if (isset($this->list_item[$unix_remove])) {
107 unset($this->list_item[$unix_remove]);
108 }
109 }
110
111 public function removeByDAY(ilDateTime $remove): void
112 {
113 foreach ($this->list_item as $key => $dt) {
114 if (ilDateTime::_equals($remove, $dt, IL_CAL_DAY, ilTimeZone::UTC)) {
115 unset($this->list_item[$key]);
116 }
117 }
118 }
119
120 public function sort(): void
121 {
122 ksort($this->list_item, SORT_NUMERIC);
123 }
124
125 public function __toString(): string
126 {
127 $out = '<br />';
128 foreach ($this->get() as $date) {
129 $out .= $date->get(IL_CAL_DATETIME, '', 'Europe/Berlin') . '<br/>';
130 }
131
132 return $out;
133 }
134}
$out
Definition: buildRTE.php:24
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
List of dates.
removeByDAY(ilDateTime $remove)
__construct(int $a_type)
add(ilDateTime $date)
getAtPosition(int $a_pos)
merge(ilDateList $other_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
$counter