ILIAS  Release_4_0_x_branch Revision 61816
 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  function delete()
83  {
84  return ilEventItems::_delete($this->getEventId());
85  }
86 
87  function _delete($a_event_id)
88  {
89  global $ilDB;
90 
91  $query = "DELETE FROM event_items ".
92  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ";
93  $res = $ilDB->manipulate($query);
94  return true;
95  }
96 
97  function update()
98  {
99  global $ilDB;
100 
101  $this->delete();
102 
103  foreach($this->items as $item)
104  {
105  $query = "INSERT INTO event_items (event_id,item_id) ".
106  "VALUES( ".
107  $ilDB->quote($this->getEventId() ,'integer').", ".
108  $ilDB->quote($item ,'integer')." ".
109  ")";
110  $res = $ilDB->manipulate($query);
111  }
112  return true;
113  }
114 
115  function _getItemsOfContainer($a_ref_id)
116  {
117  global $ilDB,$tree;
118 
119  $session_nodes = $tree->getChildsByType($a_ref_id,'sess');
120  foreach($session_nodes as $node)
121  {
122  $session_ids[] = $node['obj_id'];
123  }
124  $query = "SELECT item_id FROM event_items ".
125  "WHERE ".$ilDB->in('event_id',$session_ids,false,'integer');
126 
127 
128  $res = $ilDB->query($query);
129  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
130  {
131  $items[] = $row->item_id;
132  }
133  return $items ? $items : array();
134  }
135 
144  public static function _getItemsOfEvent($a_event_id)
145  {
146  global $ilDB;
147 
148  $query = "SELECT * FROM event_items ".
149  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer');
150  $res = $ilDB->query($query);
151  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
152  {
153  $items[] = $row->item_id;
154  }
155  return $items ? $items : array();
156  }
157 
158  function _isAssigned($a_item_id)
159  {
160  global $ilDB;
161 
162  $query = "SELECT * FROM event_items ".
163  "WHERE item_id = ".$ilDB->quote($a_item_id ,'integer')." ";
164  $res = $ilDB->query($query);
165 
166  return $res->numRows() ? true : false;
167  }
168 
177  public function cloneItems($a_source_id,$a_copy_id)
178  {
179  global $ilObjDataCache,$ilLog;
180 
181  $ilLog->write(__METHOD__.': Begin cloning session materials ...');
182 
183  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
184  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
185  $mappings = $cwo->getMappings();
186 
187  $new_items = array();
188  foreach(ilEventItems::_getItemsOfEvent($a_source_id) as $item_id)
189  {
190  if(isset($mappings[$item_id]) and $mappings[$item_id])
191  {
192  $ilLog->write(__METHOD__.': Clone session material nr. '.$item_id);
193  $new_items[] = $mappings[$item_id];
194  }
195  else
196  {
197  $ilLog->write(__METHOD__.': No mapping found for session material nr. '.$item_id);
198  }
199  }
200  $this->setItems($new_items);
201  $this->update();
202  $ilLog->write(__METHOD__.': Finished cloning session materials ...');
203  return true;
204  }
205 
206 
207  // PRIVATE
208  function __read()
209  {
210  global $ilDB,$tree;
211 
212  $query = "SELECT * FROM event_items ".
213  "WHERE event_id = ".$ilDB->quote($this->getEventId() ,'integer')." ";
214 
215  $res = $this->db->query($query);
216  $this->items = array();
217  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
218  {
219  if($tree->isDeleted($row->item_id))
220  {
221  continue;
222  }
223  if(!$tree->isInTree($row->item_id))
224  {
225  $query = "DELETE FROM event_items ".
226  "WHERE item_id = ".$ilDB->quote($row->item_id ,'integer');
227  $ilDB->manipulate($query);
228  continue;
229  }
230 
231  $this->items[] = (int) $row->item_id;
232  }
233  return true;
234  }
235 
236 }
237 ?>