ILIAS  Release_3_10_x_branch Revision 61812
 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  $query = "DELETE FROM ut_lp_collections ".
100  "WHERE obj_id = '".$this->obj_id."' ".
101  "AND item_id = '".(int) $item_id."'";
102  $this->db->query($query);
103 
104  $query = "REPLACE INTO ut_lp_collections ".
105  "SET obj_id = '".$this->obj_id."', ".
106  "item_id = '".(int) $item_id."'";
107  $this->db->query($query);
108  $this->__read();
109 
110  return true;
111  }
112 
113  function delete($item_id)
114  {
115  $query = "DELETE FROM ut_lp_collections ".
116  "WHERE item_id = '".$item_id."' ".
117  "AND obj_id = '".$this->obj_id."'";
118  $this->db->query($query);
119 
120  $this->__read();
121 
122  return true;
123  }
124 
125 
126  // Static
127  function _getPossibleItems($a_target_id)
128  {
129  global $tree;
130 
131  if($tree->isDeleted($a_target_id))
132  {
133  return array();
134  }
135 
136  $node_data = $tree->getNodeData($a_target_id);
137  foreach($tree->getSubTree($node_data) as $node)
138  {
139  // avoid recursion
140  if($node['ref_id'] == $a_target_id)
141  {
142  continue;
143  }
144 
145  switch($node['type'])
146  {
147  case 'sess':
148  case 'exc':
149  case 'fold':
150  case 'grp':
151  case 'sahs':
152  case 'lm':
153  case 'tst':
154  case 'htlm':
155  $all_possible[] = $node['ref_id'];
156  break;
157  }
158  }
159 
160  return $all_possible ? $all_possible : array();
161  }
162 
163  function _getCountPossibleItems($a_target_id)
164  {
165  return count(ilLPCollections::_getPossibleItems($a_target_id));
166  }
167 
168  function _getCountPossibleSAHSItems($a_target_id)
169  {
170  return count(ilLPCollections::_getPossibleSAHSItems($a_target_id));
171  }
172 
173 
179  {
180  include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
181 
183  {
184  case 'hacp':
185  case 'aicc':
186  include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
187 
189  {
190  $items["$item[obj_id]"]['title'] = $item['title'];
191  #$items[$item->getId()]['title'] = $item->getTitle();
192  }
193  return $items ? $items : array();
194 
195  case 'scorm':
196  include_once './Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
197  include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
198 
200  {
201  $items[$item->getId()]['title'] = $item->getTitle();
202  }
203  return $items ? $items : array();
204 
205  case 'scorm2004':
206  include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
207 
209  {
210  $items[$item["id"]]['title'] = $item["title"];
211  }
212  return $items ? $items : array();
213  }
214  return array();
215  }
216 
217  function deleteAll()
218  {
219  return ilLPCollections::_deleteAll($this->getObjId());
220  }
221 
222 
223  function _deleteAll($a_obj_id)
224  {
225  global $ilDB;
226 
227  $query = "DELETE FROM ut_lp_collections ".
228  "WHERE obj_id = '".$a_obj_id."'";
229  $ilDB->query($query);
230 
231  return true;
232  }
233 
234  function &_getItems($a_obj_id)
235  {
236  global $ilObjDataCache;
237  global $ilDB;
238 
239  include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
240 
241  $mode = ilLPObjSettings::_lookupMode($a_obj_id);
242  if($mode == LP_MODE_OBJECTIVES)
243  {
244  include_once 'Modules/Course/classes/class.ilCourseObjective.php';
245  return ilCourseObjective::_getObjectiveIds($a_obj_id);
246  }
247  if($mode != LP_MODE_SCORM and $mode != LP_MODE_COLLECTION and $mode != LP_MODE_MANUAL_BY_TUTOR)
248  {
249  return array();
250  }
251 
252  if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
253  {
254  $course_ref_ids = ilObject::_getAllReferences($a_obj_id);
255  $course_ref_id = end($course_ref_ids);
256  $possible_items = ilLPCollections::_getPossibleItems($course_ref_id);
257 
258  $query = "SELECT * FROM ut_lp_collections as utc ".
259  "JOIN object_reference as obr ON item_id = ref_id ".
260  "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
261  "WHERE utc.obj_id = ".$ilDB->quote($a_obj_id)." ".
262  "ORDER BY title";
263  }
264  else
265  {
266  // SAHS
267  $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$a_obj_id."'";
268  }
269 
270  $res = $ilDB->query($query);
271  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
272  {
273  if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
274  {
275  if(!in_array($row->item_id,$possible_items))
276  {
277  ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
278  continue;
279  }
280  }
281  // Check anonymized
282  if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
283  {
284  include_once './Modules/Test/classes/class.ilObjTest.php';
285  if(ilObjTest::_lookupAnonymity($item_obj_id))
286  {
287  ilLPCollections::__deleteEntry($a_obj_id,$row->item_id);
288  continue;
289  }
290  }
291  $items[] = $row->item_id;
292  }
293  return $items ? $items : array();
294  }
295 
296  // Private
297  function __deleteEntry($a_obj_id,$a_item_id)
298  {
299  global $ilDB;
300 
301  $query = "DELETE FROM ut_lp_collections ".
302  "WHERE obj_id = '".$a_obj_id."' ".
303  "AND item_id = '".$a_item_id."'";
304  $ilDB->query($query);
305  return true;
306  }
307 
308 
309  function __read()
310  {
311  global $ilObjDataCache;
312 
313  if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
314  {
315  $course_ref_ids = ilObject::_getAllReferences($this->getObjId());
316  $course_ref_id = end($course_ref_ids);
317  $query = "SELECT * FROM ut_lp_collections as utc ".
318  "JOIN object_reference as obr ON item_id = ref_id ".
319  "JOIN object_data as obd ON obr.obj_id = obd.obj_id ".
320  "WHERE utc.obj_id = ".$this->db->quote($this->obj_id)." ".
321  "ORDER BY title";
322  }
323  else
324  {
325  $query = "SELECT * FROM ut_lp_collections WHERE obj_id = '".$this->getObjId()."'";
326  }
327  $res = $this->db->query($query);
328  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
329  {
330  if($ilObjDataCache->lookupType($this->getObjId()) != 'sahs')
331  {
332  if(!in_array($row->item_id,ilLPCollections::_getPossibleItems($course_ref_id)))
333  {
334  $this->__deleteEntry($this->getObjId(),$row->item_id);
335  continue;
336  }
337  }
338  // Check anonymized
339  if($ilObjDataCache->lookupType($item_obj_id = $ilObjDataCache->lookupObjId($row->item_id)) == 'tst')
340  {
341  include_once './Modules/Test/classes/class.ilObjTest.php';
342  if(ilObjTest::_lookupAnonymity($item_obj_id))
343  {
344  $this->__deleteEntry($this->getObjId(),$row->item_id);
345  continue;
346  }
347  }
348  $this->items[] = $row->item_id;
349  }
350 
351  }
352 }
353 ?>