ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPCollections.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 
36 {
37  var $db = null;
38 
39  var $obj_id = null;
40  var $items = array();
41 
42  function ilLPCollections($a_obj_id)
43  {
44  global $ilObjDataCache,$ilDB;
45 
46  $this->db =& $ilDB;
47 
48  $this->obj_id = $a_obj_id;
49 
50  $this->__read();
51  }
52 
60  public function cloneCollections($a_target_id,$a_copy_id)
61  {
62  global $ilObjDataCache,$ilLog;
63 
64  $target_obj_id = $ilObjDataCache->lookupObjId($a_target_id);
65 
66  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
67  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
68  $mappings = $cwo->getMappings();
69 
70  $new_collections = new ilLPCollections($target_obj_id);
71  foreach($this->items as $item)
72  {
73  if(!isset($mappings[$item]) or !$mappings[$item])
74  {
75  continue;
76  }
77  $new_collections->add($mappings[$item]);
78  $ilLog->write(__METHOD__.': Added learning progress collection.');
79  }
80  }
81 
82  function getObjId()
83  {
84  return (int) $this->obj_id;
85  }
86 
87  function getItems()
88  {
89  return $this->items;
90  }
91 
92  function isAssigned($a_ref_id)
93  {
94  return (bool) in_array($a_ref_id,$this->items);
95  }
96 
97  function add($item_id)
98  {
99  global $ilDB;
100 
101  $query = "DELETE FROM ut_lp_collections ".
102  "WHERE obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ".
103  "AND item_id = ".$ilDB->quote($item_id ,'integer')." ";
104  $res = $ilDB->manipulate($query);
105 
106  $query = "INSERT INTO ut_lp_collections (obj_id, item_id) ".
107  "VALUES( ".
108  $ilDB->quote($this->obj_id ,'integer').", ".
109  $ilDB->quote($item_id ,'integer').
110  ")";
111  $res = $ilDB->manipulate($query);
112  $this->__read();
113 
114  return true;
115  }
116 
117  function delete($item_id)
118  {
119  global $ilDB;
120 
121  $query = "DELETE FROM ut_lp_collections ".
122  "WHERE item_id = ".$ilDB->quote($item_id ,'integer')." ".
123  "AND obj_id = ".$ilDB->quote($this->obj_id ,'integer')." ";
124  $res = $ilDB->manipulate($query);
125 
126  $this->__read();
127 
128  return true;
129  }
130 
131 
132  // Static
133  function _getPossibleItems($a_target_id)
134  {
135  global $tree;
136 
137  if($tree->isDeleted($a_target_id))
138  {
139  return array();
140  }
141 
142  $node_data = $tree->getNodeData($a_target_id);
143  foreach($tree->getSubTree($node_data) as $node)
144  {
145  // avoid recursion
146  if($node['ref_id'] == $a_target_id)
147  {
148  continue;
149  }
150 
151  switch($node['type'])
152  {
153  case 'sess':
154  case 'exc':
155  case 'fold':
156  case 'grp':
157  case 'sahs':
158  case 'lm':
159  case 'tst':
160  case 'htlm':
161  $all_possible[] = $node['ref_id'];
162  break;
163  }
164  }
165 
166  return $all_possible ? $all_possible : array();
167  }
168 
169  function _getCountPossibleItems($a_target_id)
170  {
171  return count(ilLPCollections::_getPossibleItems($a_target_id));
172  }
173 
174  function _getCountPossibleSAHSItems($a_target_id)
175  {
176  return count(ilLPCollections::_getPossibleSAHSItems($a_target_id));
177  }
178 
179 
185  {
186  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
187 
189  {
190  case 'hacp':
191  case 'aicc':
192  include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
193 
195  {
196  $items["$item[obj_id]"]['title'] = $item['title'];
197  #$items[$item->getId()]['title'] = $item->getTitle();
198  }
199  return $items ? $items : array();
200 
201  case 'scorm':
202  include_once './Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
203  include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
204 
206  {
207  $items[$item->getId()]['title'] = $item->getTitle();
208  }
209  return $items ? $items : array();
210 
211  case 'scorm2004':
212  include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
213 
215  {
216  $items[$item["id"]]['title'] = $item["title"];
217  }
218  return $items ? $items : array();
219  }
220  return array();
221  }
222 
223  function deleteAll()
224  {
225  return ilLPCollections::_deleteAll($this->getObjId());
226  }
227 
228 
229  function _deleteAll($a_obj_id)
230  {
231  global $ilDB;
232 
233  $query = "DELETE FROM ut_lp_collections ".
234  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')."";
235  $res = $ilDB->manipulate($query);
236 
237  return true;
238  }
239 
240  function &_getItems($a_obj_id)
241  {
242  global $ilObjDataCache;
243  global $ilDB;
244 
245  include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
246 
247  $mode = ilLPObjSettings::_lookupMode($a_obj_id);
248  if($mode == LP_MODE_OBJECTIVES)
249  {
250  include_once 'Modules/Course/classes/class.ilCourseObjective.php';
251  return ilCourseObjective::_getObjectiveIds($a_obj_id);
252  }
253  if($mode != LP_MODE_SCORM and $mode != LP_MODE_COLLECTION and $mode != LP_MODE_MANUAL_BY_TUTOR)
254  {
255  return array();
256  }
257 
258  if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
259  {
260  $course_ref_ids = ilObject::_getAllReferences($a_obj_id);
261  $course_ref_id = end($course_ref_ids);
262  $possible_items = ilLPCollections::_getPossibleItems($course_ref_id);
263 
264  $query = "SELECT * FROM ut_lp_collections utc ".
265  "JOIN object_reference obr ON item_id = ref_id ".
266  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
267  "WHERE utc.obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
268  "ORDER BY title";
269  }
270  else
271  {
272  // SAHS
273  $query = "SELECT * FROM ut_lp_collections WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
274  }
275 
276  $res = $ilDB->query($query);
277  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
278  {
279  if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
280  {
281  if(!in_array($row->item_id,$possible_items))
282  {
283  ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
284  continue;
285  }
286  }
287  // Check anonymized
288  if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
289  {
290  include_once './Modules/Test/classes/class.ilObjTest.php';
291  if(ilObjTest::_lookupAnonymity($item_obj_id))
292  {
293  ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
294  continue;
295  }
296  }
297  $items[] = $row->item_id;
298  }
299  return $items ? $items : array();
300  }
301 
302  // Private
303  function __deleteEntry($a_obj_id,$a_item_id)
304  {
305  global $ilDB;
306 
307  $query = "DELETE FROM ut_lp_collections ".
308  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
309  "AND item_id = ".$ilDB->quote($a_item_id ,'integer')." ";
310  $res = $ilDB->manipulate($query);
311  return true;
312  }
313 
314 
315  function __read()
316  {
317  global $ilObjDataCache, $ilDB;
318 
319  if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
320  {
321  $course_ref_ids = ilObject::_getAllReferences($this->getObjId());
322  $course_ref_id = end($course_ref_ids);
323  $query = "SELECT * FROM ut_lp_collections utc ".
324  "JOIN object_reference obr ON item_id = ref_id ".
325  "JOIN object_data obd ON obr.obj_id = obd.obj_id ".
326  "WHERE utc.obj_id = ".$this->db->quote($this->obj_id,'integer')." ".
327  "ORDER BY title";
328  }
329  else
330  {
331  $query = "SELECT * FROM ut_lp_collections WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ";
332  }
333  $res = $this->db->query($query);
334  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
335  {
336  if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
337  {
338  if(!in_array($row->item_id,ilLPCollections::_getPossibleItems($course_ref_id)))
339  {
340  $this->__deleteEntry($this->getObjId(),$row->item_id);
341  continue;
342  }
343  }
344  // Check anonymized
345  if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
346  {
347  include_once './Modules/Test/classes/class.ilObjTest.php';
348  if(ilObjTest::_lookupAnonymity($item_obj_id))
349  {
350  $this->__deleteEntry($this->getObjId(),$row->item_id);
351  continue;
352  }
353  }
354  $this->items[] = $row->item_id;
355  }
356 
357  }
358 }
359 ?>