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