ILIAS  release_8 Revision v8.24
class.ilEventItems.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
30{
31 protected ilDBInterface $db;
32 protected ilTree $tree;
33 protected int $event_id = 0;
34 protected array $items = [];
35
36
37 public function __construct(int $a_event_id)
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42 $this->tree = $DIC->repositoryTree();
43
44 $this->event_id = $a_event_id;
45 $this->__read();
46 }
47
48 public function getEventId(): int
49 {
50 return $this->event_id;
51 }
52
53 public function setEventId(int $a_event_id): void
54 {
55 $this->event_id = $a_event_id;
56 }
57
58 public function getItems(): array
59 {
60 return $this->items;
61 }
62
63 public function setItems(array $a_items): void
64 {
65 $this->items = [];
66 foreach ($a_items as $item_id) {
67 $this->items[] = (int) $item_id;
68 }
69 }
70
71 public function addItem(int $a_item_ref_id): void
72 {
73 $this->items[] = $a_item_ref_id;
74 }
75
76 public function delete(): bool
77 {
78 return self::_delete($this->getEventId());
79 }
80
81 public static function _delete(int $a_event_id): bool
82 {
83 global $DIC;
84
85 $ilDB = $DIC->database();
86
87 $query = "DELETE FROM event_items " .
88 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
89 $res = $ilDB->manipulate($query);
90 return true;
91 }
92
93 public function removeItems(array $a_items): bool
94 {
95 $query = "DELETE FROM event_items WHERE " . $this->db->in('item_id', $a_items, false, 'integer') .
96 " AND event_id = " . $this->db->quote($this->event_id, 'integer');
97
98 $res = $this->db->manipulate($query);
99
100 return true;
101 }
102
103 public function update(): bool
104 {
105 global $DIC;
106
107 $ilDB = $DIC->database();
108
109 $this->delete();
110
111 foreach ($this->items as $item) {
112 $query = "INSERT INTO event_items (event_id,item_id) " .
113 "VALUES( " .
114 $ilDB->quote($this->getEventId(), 'integer') . ", " .
115 $ilDB->quote($item, 'integer') . " " .
116 ")";
117 $res = $ilDB->manipulate($query);
118 }
119 return true;
120 }
121
122 public static function _getItemsOfContainer(int $a_ref_id): array
123 {
124 global $DIC;
125
126 $ilDB = $DIC->database();
127 $tree = $DIC->repositoryTree();
128
129 $session_nodes = $tree->getChildsByType($a_ref_id, 'sess');
130 $session_ids = [];
131 foreach ($session_nodes as $node) {
132 $session_ids[] = $node['obj_id'];
133 }
134 $query = "SELECT item_id FROM event_items " .
135 "WHERE " . $ilDB->in('event_id', $session_ids, false, 'integer');
136
137
138 $res = $ilDB->query($query);
139 $items = [];
140 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
141 $items[] = $row->item_id;
142 }
143 return $items;
144 }
145
146 public static function _getItemsOfEvent(int $a_event_id): array
147 {
148 global $DIC;
149
150 $ilDB = $DIC->database();
151
152 $query = "SELECT * FROM event_items " .
153 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer');
154 $res = $ilDB->query($query);
155 $items = [];
156 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
157 $items[] = $row->item_id;
158 }
159 return $items;
160 }
161
162 public function _isAssigned(int $a_item_id): bool
163 {
164 global $DIC;
165
166 $ilDB = $DIC->database();
167
168 $query = "SELECT * FROM event_items " .
169 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " ";
170 $res = $ilDB->query($query);
171
172 return $res->numRows() ? true : false;
173 }
174
179 public static function getEventsForItemOrderedByStartingTime(int $item_ref_id): array
180 {
181 global $DIC;
182
183 $db = $DIC->database();
184 $query = 'SELECT e.event_id,e_start FROM event_items e ' .
185 'JOIN event_appointment ea ON e.event_id = ea.event_id ' .
186 'WHERE item_id = ' . $db->quote($item_ref_id, 'integer') . ' ' .
187 'ORDER BY (e_start)';
188 $res = $db->query($query);
189
190 $events = [];
191 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
192 $dt = new ilDateTime($row->e_start, IL_CAL_DATETIME);
193 $events[$row->event_id] = $dt->getUnixTime();
194 }
195 return $events;
196 }
197
198 public function cloneItems(int $a_source_id, int $a_copy_id): bool
199 {
200 global $DIC;
201
202 $ilObjDataCache = $DIC['ilObjDataCache'];
203 $ilLog = $DIC->logger()->sess();
204
205 $ilLog->debug('Begin cloning session materials ...');
206
207 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
208 $mappings = $cwo->getMappings();
209
210 $new_items = [];
211 foreach (ilEventItems::_getItemsOfEvent($a_source_id) as $item_id) {
212 if (isset($mappings[$item_id]) && $mappings[$item_id]) {
213 $ilLog->debug('Clone session material nr. ' . $item_id);
214 $new_items[] = $mappings[$item_id];
215 } else {
216 $ilLog->debug('No mapping found for session material nr. ' . $item_id);
217 }
218 }
219 $this->setItems($new_items);
220 $this->update();
221 $ilLog->debug('Finished cloning session materials ...');
222 return true;
223 }
224
225 protected function __read(): bool
226 {
227 global $DIC;
228
231
232 $query = "SELECT * FROM event_items " .
233 "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " ";
234
235 $res = $this->db->query($query);
236 $this->items = [];
237 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
238 if ($tree->isDeleted((int) $row->item_id)) {
239 continue;
240 }
241 if (!$tree->isInTree((int) $row->item_id)) {
242 $query = "DELETE FROM event_items " .
243 "WHERE item_id = " . $ilDB->quote($row->item_id, 'integer');
244 $ilDB->manipulate($query);
245 continue;
246 }
247
248 $this->items[] = (int) $row->item_id;
249 }
250 return true;
251 }
252}
const IL_CAL_DATETIME
return true
static _getInstance(int $a_copy_id)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setEventId(int $a_event_id)
removeItems(array $a_items)
_isAssigned(int $a_item_id)
static _getItemsOfContainer(int $a_ref_id)
addItem(int $a_item_ref_id)
setItems(array $a_items)
ilDBInterface $db
static getEventsForItemOrderedByStartingTime(int $item_ref_id)
cloneItems(int $a_source_id, int $a_copy_id)
static _getItemsOfEvent(int $a_event_id)
static _delete(int $a_event_id)
__construct(int $a_event_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isInTree(?int $a_node_id)
get all information of a node.
isDeleted(int $a_node_id)
This is a wrapper for isSaved() with a more useful name.
getChildsByType(int $a_node_id, string $a_type)
get child nodes of given node by object type
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
$res
Definition: ltiservices.php:69
$query