ILIAS  Release_4_2_x_branch Revision 61807
 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 
70  function getItems()
71  {
72  return $this->items ? $this->items : array();
73  }
74  function setItems($a_items)
75  {
76  $this->items = array();
77  foreach($a_items as $item_id)
78  {
79  $this->items[] = (int) $item_id;
80  }
81  }
82 
83 
89  public function addItem($a_item_ref_id)
90  {
91  $this->items[] = (int) $a_item_ref_id;
92  }
93 
94 
95  function delete()
96  {
97  return ilEventItems::_delete($this->getEventId());
98  }
99 
100  function _delete($a_event_id)
101  {
102  global $ilDB;
103 
104  $query = "DELETE FROM event_items ".
105  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ";
106  $res = $ilDB->manipulate($query);
107  return true;
108  }
109 
110  function update()
111  {
112  global $ilDB;
113 
114  $this->delete();
115 
116  foreach($this->items as $item)
117  {
118  $query = "INSERT INTO event_items (event_id,item_id) ".
119  "VALUES( ".
120  $ilDB->quote($this->getEventId() ,'integer').", ".
121  $ilDB->quote($item ,'integer')." ".
122  ")";
123  $res = $ilDB->manipulate($query);
124  }
125  return true;
126  }
127 
128  function _getItemsOfContainer($a_ref_id)
129  {
130  global $ilDB,$tree;
131 
132  $session_nodes = $tree->getChildsByType($a_ref_id,'sess');
133  foreach($session_nodes as $node)
134  {
135  $session_ids[] = $node['obj_id'];
136  }
137  $query = "SELECT item_id FROM event_items ".
138  "WHERE ".$ilDB->in('event_id',$session_ids,false,'integer');
139 
140 
141  $res = $ilDB->query($query);
142  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
143  {
144  $items[] = $row->item_id;
145  }
146  return $items ? $items : array();
147  }
148 
157  public static function _getItemsOfEvent($a_event_id)
158  {
159  global $ilDB;
160 
161  $query = "SELECT * FROM event_items ".
162  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer');
163  $res = $ilDB->query($query);
164  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
165  {
166  $items[] = $row->item_id;
167  }
168  return $items ? $items : array();
169  }
170 
171  function _isAssigned($a_item_id)
172  {
173  global $ilDB;
174 
175  $query = "SELECT * FROM event_items ".
176  "WHERE item_id = ".$ilDB->quote($a_item_id ,'integer')." ";
177  $res = $ilDB->query($query);
178 
179  return $res->numRows() ? true : false;
180  }
181 
190  public function cloneItems($a_source_id,$a_copy_id)
191  {
192  global $ilObjDataCache,$ilLog;
193 
194  $ilLog->write(__METHOD__.': Begin cloning session materials ...');
195 
196  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
197  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
198  $mappings = $cwo->getMappings();
199 
200  $new_items = array();
201  foreach(ilEventItems::_getItemsOfEvent($a_source_id) as $item_id)
202  {
203  if(isset($mappings[$item_id]) and $mappings[$item_id])
204  {
205  $ilLog->write(__METHOD__.': Clone session material nr. '.$item_id);
206  $new_items[] = $mappings[$item_id];
207  }
208  else
209  {
210  $ilLog->write(__METHOD__.': No mapping found for session material nr. '.$item_id);
211  }
212  }
213  $this->setItems($new_items);
214  $this->update();
215  $ilLog->write(__METHOD__.': Finished cloning session materials ...');
216  return true;
217  }
218 
219 
220  // PRIVATE
221  function __read()
222  {
223  global $ilDB,$tree;
224 
225  $query = "SELECT * FROM event_items ".
226  "WHERE event_id = ".$ilDB->quote($this->getEventId() ,'integer')." ";
227 
228  $res = $this->db->query($query);
229  $this->items = array();
230  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
231  {
232  if($tree->isDeleted($row->item_id))
233  {
234  continue;
235  }
236  if(!$tree->isInTree($row->item_id))
237  {
238  $query = "DELETE FROM event_items ".
239  "WHERE item_id = ".$ilDB->quote($row->item_id ,'integer');
240  $ilDB->manipulate($query);
241  continue;
242  }
243 
244  $this->items[] = (int) $row->item_id;
245  }
246  return true;
247  }
248 
249 }
250 ?>