ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilEventItems.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
24
35{
36 public $ilErr;
37 public $ilDB;
38 public $tree;
39 public $lng;
40
41 public $event_id = null;
42 public $items = array();
43
44
45 public function __construct($a_event_id)
46 {
47 global $DIC;
48
49 $ilErr = $DIC['ilErr'];
50 $ilDB = $DIC['ilDB'];
51 $lng = $DIC['lng'];
52 $tree = $DIC['tree'];
53
54 $this->ilErr = $ilErr;
55 $this->db = $ilDB;
56 $this->lng = $lng;
57
58 $this->event_id = $a_event_id;
59 $this->__read();
60 }
61
62 public function getEventId()
63 {
64 return $this->event_id;
65 }
66 public function setEventId($a_event_id)
67 {
68 $this->event_id = $a_event_id;
69 }
70
75 public function getItems()
76 {
77 return $this->items ? $this->items : array();
78 }
79 public function setItems($a_items)
80 {
81 $this->items = array();
82 foreach ($a_items as $item_id) {
83 $this->items[] = (int) $item_id;
84 }
85 }
86
87
93 public function addItem($a_item_ref_id)
94 {
95 $this->items[] = (int) $a_item_ref_id;
96 }
97
98
99 public function delete()
100 {
101 return ilEventItems::_delete($this->getEventId());
102 }
103
104 public static function _delete($a_event_id)
105 {
106 global $DIC;
107
108 $ilDB = $DIC['ilDB'];
109
110 $query = "DELETE FROM event_items " .
111 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
112 $res = $ilDB->manipulate($query);
113 return true;
114 }
115
121 public function removeItems($a_items)
122 {
123 $query = "DELETE FROM event_items WHERE " . $this->db->in('item_id', $a_items, false, 'integer') .
124 " AND event_id = " . $this->db->quote($this->event_id, 'integer');
125
126 $res = $this->db->manipulate($query);
127
128 return true;
129 }
130
131 public function update()
132 {
133 global $DIC;
134
135 $ilDB = $DIC['ilDB'];
136
137 $this->delete();
138
139 foreach ($this->items as $item) {
140 $query = "INSERT INTO event_items (event_id,item_id) " .
141 "VALUES( " .
142 $ilDB->quote($this->getEventId(), 'integer') . ", " .
143 $ilDB->quote($item, 'integer') . " " .
144 ")";
145 $res = $ilDB->manipulate($query);
146 }
147 return true;
148 }
149
150 public static function _getItemsOfContainer($a_ref_id)
151 {
152 global $DIC;
153
154 $ilDB = $DIC['ilDB'];
155 $tree = $DIC['tree'];
156
157 $session_nodes = $tree->getChildsByType($a_ref_id, 'sess');
158 $session_ids = [];
159 foreach ($session_nodes as $node) {
160 $session_ids[] = $node['obj_id'];
161 }
162 $query = "SELECT item_id FROM event_items " .
163 "WHERE " . $ilDB->in('event_id', $session_ids, false, 'integer');
164
165
166 $res = $ilDB->query($query);
167 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
168 $items[] = $row->item_id;
169 }
170 return $items ? $items : array();
171 }
172
181 public static function _getItemsOfEvent($a_event_id)
182 {
183 global $DIC;
184
185 $ilDB = $DIC['ilDB'];
186
187 $query = "SELECT * FROM event_items " .
188 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer');
189 $res = $ilDB->query($query);
190 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
191 $items[] = $row->item_id;
192 }
193 return $items ? $items : array();
194 }
195
196 public function _isAssigned($a_item_id)
197 {
198 global $DIC;
199
200 $ilDB = $DIC['ilDB'];
201
202 $query = "SELECT * FROM event_items " .
203 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " ";
204 $res = $ilDB->query($query);
205
206 return $res->numRows() ? true : false;
207 }
208
213 public static function getEventsForItemOrderedByStartingTime($item_ref_id)
214 {
215 global $DIC;
216
217 $db = $DIC->database();
218 $query = 'SELECT e.event_id,e_start FROM event_items e ' .
219 'JOIN event_appointment ea ON e.event_id = ea.event_id ' .
220 'WHERE item_id = ' . $db->quote($item_ref_id, 'integer') . ' ' .
221 'ORDER BY (e_start)';
222 $res = $db->query($query);
223
224 $events = [];
225 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
226 $dt = new ilDateTime($row->e_start, IL_CAL_DATETIME);
227 $events[$row->event_id] = $dt->getUnixTime();
228 }
229 return $events;
230 }
231
232
241 public function cloneItems($a_source_id, $a_copy_id)
242 {
243 global $DIC;
244
245 $ilObjDataCache = $DIC['ilObjDataCache'];
246 $ilLog = $DIC->logger()->sess();
247
248 $ilLog->debug('Begin cloning session materials ...');
249
250 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
251 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
252 $mappings = $cwo->getMappings();
253
254 $new_items = array();
255 foreach (ilEventItems::_getItemsOfEvent($a_source_id) as $item_id) {
256 if (isset($mappings[$item_id]) and $mappings[$item_id]) {
257 $ilLog->debug('Clone session material nr. ' . $item_id);
258 $new_items[] = $mappings[$item_id];
259 } else {
260 $ilLog->debug('No mapping found for session material nr. ' . $item_id);
261 }
262 }
263 $this->setItems($new_items);
264 $this->update();
265 $ilLog->debug('Finished cloning session materials ...');
266 return true;
267 }
268
269
270 // PRIVATE
271 public function __read()
272 {
273 global $DIC;
274
275 $ilDB = $DIC['ilDB'];
276 $tree = $DIC['tree'];
277
278 $query = "SELECT * FROM event_items " .
279 "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " ";
280
281 $res = $this->db->query($query);
282 $this->items = array();
283 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
284 if ($tree->isDeleted($row->item_id)) {
285 continue;
286 }
287 if (!$tree->isInTree($row->item_id)) {
288 $query = "DELETE FROM event_items " .
289 "WHERE item_id = " . $ilDB->quote($row->item_id, 'integer');
290 $ilDB->manipulate($query);
291 continue;
292 }
293
294 $this->items[] = (int) $row->item_id;
295 }
296 return true;
297 }
298}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
@classDescription Date and time handling
class ilEvent
addItem($a_item_ref_id)
Add one item.
_isAssigned($a_item_id)
static _getItemsOfEvent($a_event_id)
Get items by event.
static _getItemsOfContainer($a_ref_id)
removeItems($a_items)
Remove specific items from the DB.
__construct($a_event_id)
static getEventsForItemOrderedByStartingTime($item_ref_id)
cloneItems($a_source_id, $a_copy_id)
Clone items.
static _delete($a_event_id)
getItems()
get assigned items
setEventId($a_event_id)
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res