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