ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilErr,$ilDB,$lng,$tree;
48
49 $this->ilErr = $ilErr;
50 $this->db = $ilDB;
51 $this->lng = $lng;
52
53 $this->event_id = $a_event_id;
54 $this->__read();
55 }
56
57 public function getEventId()
58 {
59 return $this->event_id;
60 }
61 public function setEventId($a_event_id)
62 {
63 $this->event_id = $a_event_id;
64 }
65
70 public function getItems()
71 {
72 return $this->items ? $this->items : array();
73 }
74 public function setItems($a_items)
75 {
76 $this->items = array();
77 foreach ($a_items as $item_id) {
78 $this->items[] = (int) $item_id;
79 }
80 }
81
82
88 public function addItem($a_item_ref_id)
89 {
90 $this->items[] = (int) $a_item_ref_id;
91 }
92
93
94 public function delete()
95 {
96 return ilEventItems::_delete($this->getEventId());
97 }
98
99 public static function _delete($a_event_id)
100 {
101 global $ilDB;
102
103 $query = "DELETE FROM event_items " .
104 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
105 $res = $ilDB->manipulate($query);
106 return true;
107 }
108
109 public function update()
110 {
111 global $ilDB;
112
113 $this->delete();
114
115 foreach ($this->items as $item) {
116 $query = "INSERT INTO event_items (event_id,item_id) " .
117 "VALUES( " .
118 $ilDB->quote($this->getEventId(), 'integer') . ", " .
119 $ilDB->quote($item, 'integer') . " " .
120 ")";
121 $res = $ilDB->manipulate($query);
122 }
123 return true;
124 }
125
126 public static function _getItemsOfContainer($a_ref_id)
127 {
128 global $ilDB,$tree;
129
130 $session_nodes = $tree->getChildsByType($a_ref_id, 'sess');
131 $session_ids = [];
132 foreach ($session_nodes as $node) {
133 $session_ids[] = $node['obj_id'];
134 }
135 $query = "SELECT item_id FROM event_items " .
136 "WHERE " . $ilDB->in('event_id', $session_ids, false, 'integer');
137
138
139 $res = $ilDB->query($query);
140 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
141 $items[] = $row->item_id;
142 }
143 return $items ? $items : array();
144 }
145
154 public static function _getItemsOfEvent($a_event_id)
155 {
156 global $ilDB;
157
158 $query = "SELECT * FROM event_items " .
159 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer');
160 $res = $ilDB->query($query);
161 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
162 $items[] = $row->item_id;
163 }
164 return $items ? $items : array();
165 }
166
167 public function _isAssigned($a_item_id)
168 {
169 global $ilDB;
170
171 $query = "SELECT * FROM event_items " .
172 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " ";
173 $res = $ilDB->query($query);
174
175 return $res->numRows() ? true : false;
176 }
177
186 public function cloneItems($a_source_id, $a_copy_id)
187 {
188 global $ilObjDataCache,$ilLog;
189
190 $ilLog->write(__METHOD__ . ': Begin cloning session materials ...');
191
192 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
193 $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
194 $mappings = $cwo->getMappings();
195
196 $new_items = array();
197 foreach (ilEventItems::_getItemsOfEvent($a_source_id) as $item_id) {
198 if (isset($mappings[$item_id]) and $mappings[$item_id]) {
199 $ilLog->write(__METHOD__ . ': Clone session material nr. ' . $item_id);
200 $new_items[] = $mappings[$item_id];
201 } else {
202 $ilLog->write(__METHOD__ . ': No mapping found for session material nr. ' . $item_id);
203 }
204 }
205 $this->setItems($new_items);
206 $this->update();
207 $ilLog->write(__METHOD__ . ': Finished cloning session materials ...');
208 return true;
209 }
210
211
212 // PRIVATE
213 public function __read()
214 {
215 global $ilDB,$tree;
216
217 $query = "SELECT * FROM event_items " .
218 "WHERE event_id = " . $ilDB->quote($this->getEventId(), 'integer') . " ";
219
220 $res = $this->db->query($query);
221 $this->items = array();
222 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
223 if ($tree->isDeleted($row->item_id)) {
224 continue;
225 }
226 if (!$tree->isInTree($row->item_id)) {
227 $query = "DELETE FROM event_items " .
228 "WHERE item_id = " . $ilDB->quote($row->item_id, 'integer');
229 $ilDB->manipulate($query);
230 continue;
231 }
232
233 $this->items[] = (int) $row->item_id;
234 }
235 return true;
236 }
237}
An exception for terminatinating execution or to throw for unit testing.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
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)
__construct($a_event_id)
cloneItems($a_source_id, $a_copy_id)
Clone items.
static _delete($a_event_id)
getItems()
get assigned items
setEventId($a_event_id)
$query
foreach($_POST as $key=> $value) $res