ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLPObjSettings.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 
35 define("LP_MODE_DEACTIVATED",0);
36 define("LP_MODE_TLT",1);
37 define("LP_MODE_VISITS",2);
38 define("LP_MODE_MANUAL",3);
39 define("LP_MODE_OBJECTIVES",4);
40 define("LP_MODE_COLLECTION",5);
41 define("LP_MODE_SCORM",6);
42 define("LP_MODE_TEST_FINISHED",7);
43 define("LP_MODE_TEST_PASSED",8);
44 define("LP_MODE_EXERCISE_RETURNED",9);
45 define("LP_MODE_EVENT",10);
46 define("LP_MODE_MANUAL_BY_TUTOR",11);
47 define("LP_MODE_SCORM_PACKAGE",12);
48 
49 define("LP_DEFAULT_VISITS",30);
50 
51 
53 {
54  var $db = null;
55 
56  var $obj_id = null;
57  var $obj_type = null;
58  var $obj_mode = null;
59  var $visits = null;
60 
61  var $is_stored = false;
62 
63  function ilLPObjSettings($a_obj_id)
64  {
65  global $ilObjDataCache,$ilDB;
66 
67  $this->db =& $ilDB;
68 
69  $this->obj_id = $a_obj_id;
70 
71  if(!$this->__read())
72  {
73  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
74  $this->obj_mode = $this->__getDefaultMode($this->obj_id,$this->obj_type);
75  }
76  }
77 
85  public function cloneSettings($a_new_obj_id)
86  {
87  $query = "INSERT INTO ut_lp_settings ".
88  "SET obj_id = ".$this->db->quote($a_new_obj_id).", ".
89  "obj_type = ".$this->db->quote($this->getObjType()).", ".
90  "mode = ".$this->db->quote($this->getMode()).", ".
91  "visits = ".$this->db->quote($this->getVisits());
92 
93  $this->db->query($query);
94  return true;
95  }
96 
97  function getVisits()
98  {
99  return (int) $this->visits ? $this->visits : LP_DEFAULT_VISITS;
100  }
101 
102  function setVisits($a_visits)
103  {
104  $this->visits = $a_visits;
105  }
106 
107  function setMode($a_mode)
108  {
109  $this->obj_mode = $a_mode;
110  }
111  function getMode()
112  {
113  return $this->obj_mode;
114  }
115 
116  function getObjId()
117  {
118  return (int) $this->obj_id;
119  }
120  function getObjType()
121  {
122  return $this->obj_type;
123  }
124 
125  function update()
126  {
127  if(!$this->is_stored)
128  {
129  return $this->insert();
130  }
131  $query = "UPDATE ut_lp_settings SET mode = '".$this->obj_mode.
132  "', visits = '".$this->visits."' ".
133  "WHERE obj_id = '".$this->getObjId()."'";
134  $this->db->query($query);
135  $this->__read();
136  return true;
137  }
138 
139  function insert()
140  {
141  $query = "INSERT INTO ut_lp_settings SET obj_id = '".$this->obj_id."', ".
142  "obj_type = '".$this->obj_type."', ".
143  "mode = '".$this->obj_mode."'";
144  $this->db->query($query);
145  $this->__read();
146  return true;
147  }
148 
149 
150  // Static
151  function _lookupVisits($a_obj_id)
152  {
153  global $ilDB;
154 
155  #echo $a_obj_id;
156 
157  $query = "SELECT visits FROM ut_lp_settings ".
158  "WHERE obj_id = '".$a_obj_id."'";
159 
160  $res = $ilDB->query($query);
161  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
162  {
163  return $row->visits;
164  }
165  return LP_DEFAULT_VISITS;
166  }
167 
168  function _isContainer($a_mode)
169  {
170  return $a_mode == LP_MODE_COLLECTION or
171  $a_mode == LP_MODE_SCORM or
172  $a_mode == LP_MODE_OBJECTIVES or
173  $a_mode == LP_MODE_MANUAL_BY_TUTOR;
174  }
175 
176 
177  function _delete($a_obj_id)
178  {
179  global $ilDB;
180 
181  $query = "DELETE FROM ut_lp_settings WHERE obj_id = '".$a_obj_id."'";
182  $ilDB->query($query);
183 
184  return true;
185  }
186 
187  function _lookupMode($a_obj_id)
188  {
189  global $ilDB,$ilObjDataCache;
190 
191  if(ilLPObjSettings::_checkObjectives($a_obj_id))
192  {
193  return LP_MODE_OBJECTIVES;
194  }
196  {
197  return LP_MODE_SCORM;
198  }
199 
200  $query = "SELECT mode FROM ut_lp_settings ".
201  "WHERE obj_id = '".$a_obj_id."'";
202 
203  $res = $ilDB->query($query);
204  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
205  {
206  return $row->mode;
207  }
208 
209  // no db entry exists => return default mode by type
210  return ilLPObjSettings::__getDefaultMode($a_obj_id,$ilObjDataCache->lookupType($a_obj_id));
211  }
212 
213  function getValidModes()
214  {
215  global $lng;
216 
217  switch($this->obj_type)
218  {
219  case 'crs':
221  {
222  return array(LP_MODE_OBJECTIVES => $lng->txt('trac_mode_objectives'));
223  }
224 
225  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
226  LP_MODE_MANUAL_BY_TUTOR => $lng->txt('trac_mode_manual_by_tutor'),
227  LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
228 
229  break;
230 
231  case 'dbk':
232  case 'lm':
233  return array(LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
234  LP_MODE_VISITS => $lng->txt('trac_mode_visits'),
235  LP_MODE_TLT => $lng->txt('trac_mode_tlt'),
236  LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
237 
238  case 'htlm':
239  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
240  LP_MODE_MANUAL => $lng->txt('trac_mode_manual'));
241 
242  case 'sahs':
243  include_once './Services/Tracking/classes/class.ilLPCollections.php';
244  include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
246 
247  if ($subtype != "scorm2004")
248  {
250  {
251  return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
252  }
254  {
255  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
256  LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
257  }
258  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
259  }
260  else
261  {
263  {
264  return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'),
265  LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'));
266  }
268  {
269  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
270  LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'),
271  LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
272  }
273  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
274  LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'));
275  }
276  break;
277 
278  case 'tst':
279  return array(LP_MODE_TEST_FINISHED => $lng->txt('trac_mode_test_finished'),
280  LP_MODE_TEST_PASSED => $lng->txt('trac_mode_test_passed'),
281  LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
282 
283  case 'exc':
284  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
285  LP_MODE_EXERCISE_RETURNED => $lng->txt('trac_mode_exercise_returned'));
286 
287  case 'grp':
288  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
289  LP_MODE_MANUAL_BY_TUTOR => $lng->txt('trac_mode_manual_by_tutor'),
290  LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
291 
292  case 'fold':
293  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
294  LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
295 
296  case 'sess':
297  return array(LP_MODE_EVENT => $this->lng->txt('trac_mode_event'));
298 
299  default:
300  return array();
301  }
302  }
303 
304  function _mode2Text($a_mode)
305  {
306  global $lng;
307 
308  switch($a_mode)
309  {
310  case LP_MODE_DEACTIVATED:
311  return $lng->txt('trac_mode_deactivated');
312 
313  case LP_MODE_TLT:
314  return $lng->txt('trac_mode_tlt');
315 
316  case LP_MODE_VISITS:
317  return $lng->txt('trac_mode_visits');
318 
319  case LP_MODE_MANUAL:
320  return $lng->txt('trac_mode_manual');
321 
323  return $lng->txt('trac_mode_manual_by_tutor');
324 
325  case LP_MODE_OBJECTIVES:
326  return $lng->txt('trac_mode_objectives');
327 
328  case LP_MODE_COLLECTION:
329  return $lng->txt('trac_mode_collection');
330 
331  case LP_MODE_SCORM:
332  return $lng->txt('trac_mode_scorm');
333 
335  return $lng->txt('trac_mode_test_finished');
336 
337  case LP_MODE_TEST_PASSED:
338  return $lng->txt('trac_mode_test_passed');
339 
341  return $lng->txt('trac_mode_exercise_returned');
342 
344  return $lng->txt('trac_mode_scorm_package');
345 
346  case LP_MODE_EVENT:
347  return $lng->txt('trac_mode_event');
348 
349 
350  }
351  }
352 
361  public static function _mode2InfoText($a_mode)
362  {
363  global $lng;
364 
365  switch($a_mode)
366  {
367  case LP_MODE_DEACTIVATED:
368  return $lng->txt('trac_mode_deactivated_info');
369 
370  case LP_MODE_TLT:
371  return $lng->txt('trac_mode_tlt_info');
372 
373  case LP_MODE_VISITS:
374  return $lng->txt('trac_mode_visits_info');
375 
376  case LP_MODE_MANUAL:
377  return $lng->txt('trac_mode_manual_info');
378 
380  return $lng->txt('trac_mode_manual_by_tutor_info');
381 
382  case LP_MODE_OBJECTIVES:
383  return $lng->txt('trac_mode_objectives_info');
384 
385  case LP_MODE_COLLECTION:
386  return $lng->txt('trac_mode_collection_info');
387 
388  case LP_MODE_SCORM:
389  return $lng->txt('trac_mode_scorm_info');
390 
392  return $lng->txt('trac_mode_test_finished_info');
393 
394  case LP_MODE_TEST_PASSED:
395  return $lng->txt('trac_mode_test_passed_info');
396 
398  return $lng->txt('trac_mode_exercise_returned_info');
399 
401  return $lng->txt('trac_mode_scorm_package_info');
402 
403  case LP_MODE_EVENT:
404  return $lng->txt('trac_mode_event_info');
405  }
406 
407  }
408 
409 
410 
411 
412  // Private
413  function _checkObjectives($a_obj_id)
414  {
415  global $ilDB,$ilObjDataCache;
416 
417  // Return deactivate for course with objective view
418  if($ilObjDataCache->lookupType($a_obj_id) == 'crs')
419  {
420  include_once 'Modules/Course/classes/class.ilObjCourse.php';
421 
423  {
424  return true;
425  }
426  }
427  return false;
428  }
429 
430  function _checkSCORMPreconditions($a_obj_id)
431  {
432  global $ilObjDataCache;
433 
434  if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
435  {
436  return false;
437  }
438  include_once('classes/class.ilConditionHandler.php');
439  if(count($conditions = ilConditionHandler::_getConditionsOfTrigger('sahs',$a_obj_id)))
440  {
441  return true;
442  }
443  return false;
444  }
445 
446 
447 
448  function __read()
449  {
450  $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = ".$this->db->quote($this->obj_id)." ");
451  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
452  {
453  $this->is_stored = true;
454  $this->obj_type = $row->obj_type;
455  $this->obj_mode = $row->mode;
456  $this->visits = $row->visits;
457 
458  if(ilLPObjSettings::_checkObjectives($this->obj_id))
459  {
460  $this->obj_mode = LP_MODE_OBJECTIVES;
461  }
463  {
464  $this->obj_mode = LP_MODE_SCORM;
465  }
466 
467  return true;
468  }
469 
470  return false;
471  }
472 
473  function __getDefaultMode($a_obj_id,$a_type)
474  {
475  global $ilDB;
476 
477  #$type = strlen($a_type) ? $a_type : $this->obj_type;
478 
479  switch($a_type)
480  {
481  case 'crs':
482  // If objectives are enabled return deactivated
483  if(ilLPObjSettings::_checkObjectives($a_obj_id))
484  {
485  return LP_MODE_OBJECTIVES;
486  }
488 
489  case 'dbk':
490  case 'lm':
491  case 'htlm':
492  return LP_MODE_MANUAL;
493 
494  case 'sahs':
495  return LP_MODE_DEACTIVATED;
496 
497  case 'dbk':
498  return LP_MODE_MANUAL;
499 
500  case 'tst':
501  return LP_MODE_TEST_PASSED;
502 
503  case 'exc':
505 
506  case 'grp':
507  return LP_MODE_DEACTIVATED;
508 
509  case 'fold':
510  return LP_MODE_DEACTIVATED;
511 
512  case 'sess':
513  return LP_MODE_EVENT;
514 
515  default:
516  return LP_MODE_UNDEFINED;
517  }
518  }
519 }
520 ?>