ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $ilErr;
37  var $ilDB;
38  var $tree;
39  var $lng;
40 
41  var $event_id = null;
42  var $items = array();
43 
44 
45  function ilEventItems($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  function getEventId()
58  {
59  return $this->event_id;
60  }
61  function setEventId($a_event_id)
62  {
63  $this->event_id = $a_event_id;
64  }
65  function getItems()
66  {
67  return $this->items ? $this->items : array();
68  }
69  function setItems($a_items)
70  {
71  $this->items = array();
72  foreach($a_items as $item_id)
73  {
74  $this->items[] = (int) $item_id;
75  }
76  }
77  function delete()
78  {
79  return ilEventItems::_delete($this->getEventId());
80  }
81 
82  function _delete($a_event_id)
83  {
84  global $ilDB;
85 
86  $query = "DELETE FROM event_items ".
87  "WHERE event_id = ".$ilDB->quote($a_event_id)." ";
88  $ilDB->query($query);
89  return true;
90  }
91 
92  function update()
93  {
94  global $ilDB;
95 
96  $this->delete();
97 
98  foreach($this->items as $item)
99  {
100  $query = "INSERT INTO event_items ".
101  "SET event_id = ".$ilDB->quote($this->getEventId()).", ".
102  "item_id = ".$ilDB->quote($item)." ";
103  $this->db->query($query);
104  }
105  return true;
106  }
107 
108  function _getItemsOfContainer($a_ref_id)
109  {
110  global $ilDB,$tree;
111 
112  $session_nodes = $tree->getChildsByType($a_ref_id,'sess');
113  foreach($session_nodes as $node)
114  {
115  $session_ids[] = $node['obj_id'];
116  }
117  $in = "IN (".implode(",",ilUtil::quoteArray($session_ids)).") ";
118 
119  $query = "SELECT item_id FROM event_items ".
120  "WHERE event_id ".$in;
121 
122 
123  $res = $ilDB->query($query);
124  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
125  {
126  $items[] = $row->item_id;
127  }
128  return $items ? $items : array();
129  }
130 
139  public static function _getItemsOfEvent($a_event_id)
140  {
141  global $ilDB;
142 
143  $query = "SELECT * FROM event_items ".
144  "WHERE event_id = ".$ilDB->quote($a_event_id);
145  $res = $ilDB->query($query);
146  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
147  {
148  $items[] = $row->item_id;
149  }
150  return $items ? $items : array();
151  }
152 
153  function _isAssigned($a_item_id)
154  {
155  global $ilDB;
156 
157  $query = "SELECT * FROM event_items ".
158  "WHERE item_id = ".$ilDB->quote($a_item_id)." ";
159  $res = $ilDB->query($query);
160 
161  return $res->numRows() ? true : false;
162  }
163 
172  public function cloneItems($a_source_id,$a_copy_id)
173  {
174  global $ilObjDataCache,$ilLog;
175 
176  $ilLog->write(__METHOD__.': Begin cloning session materials ...');
177 
178  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
179  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
180  $mappings = $cwo->getMappings();
181 
182  $new_items = array();
183  foreach(ilEventItems::_getItemsOfEvent($a_source_id) as $item_id)
184  {
185  if(isset($mappings[$item_id]) and $mappings[$item_id])
186  {
187  $ilLog->write(__METHOD__.': Clone session material nr. '.$item_id);
188  $new_items[] = $mappings[$item_id];
189  }
190  else
191  {
192  $ilLog->write(__METHOD__.': No mapping found for session material nr. '.$item_id);
193  }
194  }
195  $this->setItems($new_items);
196  $this->update();
197  $ilLog->write(__METHOD__.': Finished cloning session materials ...');
198  return true;
199  }
200 
201 
202  // PRIVATE
203  function __read()
204  {
205  global $ilDB,$tree;
206 
207  $query = "SELECT * FROM event_items ".
208  "WHERE event_id = ".$ilDB->quote($this->getEventId())." ";
209 
210  $res = $this->db->query($query);
211  $this->items = array();
212  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
213  {
214  if($tree->isDeleted($row->item_id))
215  {
216  continue;
217  }
218  if(!$tree->isInTree($row->item_id))
219  {
220  $query = "DELETE FROM event_items ".
221  "WHERE item_id = ".$ilDB->quote($row->item_id);
222  $ilDB->query($query);
223  continue;
224  }
225 
226  $this->items[] = (int) $row->item_id;
227  }
228  return true;
229  }
230 
231 }
232 ?>