ILIAS  Release_4_1_x_branch Revision 61804
 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 define("LP_MODE_UNDEFINED",13);
49 
50 define("LP_DEFAULT_VISITS",30);
51 
52 
54 {
55  var $db = null;
56 
57  var $obj_id = null;
58  var $obj_type = null;
59  var $obj_mode = null;
60  var $visits = null;
61 
62  var $is_stored = false;
63 
64  static private $mode_by_obj_id = array();
65 
66  function ilLPObjSettings($a_obj_id)
67  {
68  global $ilObjDataCache,$ilDB;
69 
70  $this->db =& $ilDB;
71 
72  $this->obj_id = $a_obj_id;
73 
74  if(!$this->__read())
75  {
76  $this->obj_type = $ilObjDataCache->lookupType($this->obj_id);
77  $this->obj_mode = $this->__getDefaultMode($this->obj_id,$this->obj_type);
78  }
79  }
80 
88  public function cloneSettings($a_new_obj_id)
89  {
90  global $ilDB;
91 
92  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) ".
93  "VALUES( ".
94  $this->db->quote($a_new_obj_id ,'integer').", ".
95  $this->db->quote($this->getObjType() ,'text').", ".
96  $this->db->quote($this->getMode() ,'integer').", ".
97  $this->db->quote($this->getVisits() ,'integer').
98  ")";
99  $res = $ilDB->manipulate($query);
100  return true;
101  }
102 
103  function getVisits()
104  {
105  return (int) $this->visits ? $this->visits : LP_DEFAULT_VISITS;
106  }
107 
108  function setVisits($a_visits)
109  {
110  $this->visits = $a_visits;
111  }
112 
113  function setMode($a_mode)
114  {
115  $this->obj_mode = $a_mode;
116  }
117  function getMode()
118  {
119  return $this->obj_mode;
120  }
121 
122  function getObjId()
123  {
124  return (int) $this->obj_id;
125  }
126  function getObjType()
127  {
128  return $this->obj_type;
129  }
130 
131  function update()
132  {
133  global $ilDB;
134 
135  if(!$this->is_stored)
136  {
137  return $this->insert();
138  }
139  $query = "UPDATE ut_lp_settings SET u_mode = ".$ilDB->quote($this->getMode() ,'integer').", ".
140  "visits = ".$ilDB->quote($this->getVisits() ,'integer')." ".
141  "WHERE obj_id = ".$ilDB->quote($this->getObjId() ,'integer');
142  $res = $ilDB->manipulate($query);
143  $this->__read();
144 
145  // refresh learning progress
146  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
148 
149  return true;
150  }
151 
152  function insert()
153  {
154  global $ilDB,$ilLog;
155 
156  $ilLog->logStack();
157 
158  $query = "INSERT INTO ut_lp_settings (obj_id,obj_type,u_mode,visits) ".
159  "VALUES(".
160  $ilDB->quote($this->getObjId() ,'integer').", ".
161  $ilDB->quote($this->getObjType(),'text').", ".
162  $ilDB->quote($this->getMode(),'integer').", ".
163  $ilDB->quote(0, 'integer').
164  ")";
165  $res = $ilDB->manipulate($query);
166  $this->__read();
167 
168  // refresh learning progress
169  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
171 
172  return true;
173  }
174 
175 
176  // Static
177  function _lookupVisits($a_obj_id)
178  {
179  global $ilDB;
180 
181  $query = "SELECT visits FROM ut_lp_settings ".
182  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
183 
184  $res = $ilDB->query($query);
185  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
186  {
187  return $row->visits;
188  }
189  return LP_DEFAULT_VISITS;
190  }
191 
192  function _isContainer($a_mode)
193  {
194  return $a_mode == LP_MODE_COLLECTION or
195  $a_mode == LP_MODE_SCORM or
196  $a_mode == LP_MODE_OBJECTIVES or
197  $a_mode == LP_MODE_MANUAL_BY_TUTOR;
198  }
199 
200 
201  function _delete($a_obj_id)
202  {
203  global $ilDB;
204 
205  $query = "DELETE FROM ut_lp_settings WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
206  $res = $ilDB->manipulate($query);
207 
208  return true;
209  }
210 
211  function _lookupMode($a_obj_id)
212  {
213  global $ilDB,$ilObjDataCache;
214 
215  if (isset(self::$mode_by_obj_id[$a_obj_id]))
216  {
217  return self::$mode_by_obj_id[$a_obj_id];
218  }
219 
220  if(ilLPObjSettings::_checkObjectives($a_obj_id))
221  {
222  self::$mode_by_obj_id[$a_obj_id] = LP_MODE_OBJECTIVES;
223  return LP_MODE_OBJECTIVES;
224  }
226  {
227  self::$mode_by_obj_id[$a_obj_id] = LP_MODE_SCORM;
228  return LP_MODE_SCORM;
229  }
230 
231  $query = "SELECT u_mode FROM ut_lp_settings ".
232  "WHERE obj_id = ".$ilDB->quote($a_obj_id ,'integer');
233 
234  $res = $ilDB->query($query);
235  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
236  {
237  self::$mode_by_obj_id[$a_obj_id] = $row->u_mode;
238  return $row->u_mode;
239  }
240 
241  // no db entry exists => return default mode by type
242  $def_mode = ilLPObjSettings::__getDefaultMode($a_obj_id,$ilObjDataCache->lookupType($a_obj_id));
243  self::$mode_by_obj_id[$a_obj_id] = $def_mode;
244 
245  return $def_mode;
246  }
247 
248  function getValidModes()
249  {
250  global $lng;
251 
252  switch($this->obj_type)
253  {
254  case 'crs':
256  {
257  return array(LP_MODE_OBJECTIVES => $lng->txt('trac_mode_objectives'));
258  }
259 
260  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
261  LP_MODE_MANUAL_BY_TUTOR => $lng->txt('trac_mode_manual_by_tutor'),
262  LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
263 
264  break;
265 
266  case 'dbk':
267  return array(
268  LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
269  LP_MODE_DEACTIVATE => $lng->txt('trac_mode_deactivated')
270  );
271  case 'lm':
272  return array(LP_MODE_MANUAL => $lng->txt('trac_mode_manual'),
273  LP_MODE_VISITS => $lng->txt('trac_mode_visits'),
274  LP_MODE_TLT => $lng->txt('trac_mode_tlt'),
275  LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
276 
277  case 'htlm':
278  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
279  LP_MODE_MANUAL => $lng->txt('trac_mode_manual'));
280 
281  case 'sahs':
282  include_once './Services/Tracking/classes/class.ilLPCollections.php';
283  include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
285 
286  if ($subtype != "scorm2004")
287  {
289  {
290  return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
291  }
293  {
294  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
295  LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
296  }
297  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
298  }
299  else
300  {
302  {
303  return array(LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'),
304  LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'));
305  }
307  {
308  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
309  LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'),
310  LP_MODE_SCORM => $lng->txt('trac_mode_scorm_aicc'));
311  }
312  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
313  LP_MODE_SCORM_PACKAGE => $lng->txt('trac_mode_scorm_package'));
314  }
315  break;
316 
317  case 'tst':
318  return array(LP_MODE_TEST_FINISHED => $lng->txt('trac_mode_test_finished'),
319  LP_MODE_TEST_PASSED => $lng->txt('trac_mode_test_passed'),
320  LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'));
321 
322  case 'exc':
323  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
324  LP_MODE_EXERCISE_RETURNED => $lng->txt('trac_mode_exercise_returned'));
325 
326  case 'grp':
327  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
328  LP_MODE_MANUAL_BY_TUTOR => $lng->txt('trac_mode_manual_by_tutor'),
329  LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
330 
331  case 'fold':
332  return array(LP_MODE_DEACTIVATED => $lng->txt('trac_mode_deactivated'),
333  LP_MODE_COLLECTION => $lng->txt('trac_mode_collection'));
334 
335  case 'sess':
336  return array(LP_MODE_EVENT => $this->lng->txt('trac_mode_event'));
337 
338  default:
339  return array();
340  }
341  }
342 
343  function _mode2Text($a_mode)
344  {
345  global $lng;
346 
347  switch($a_mode)
348  {
349  case LP_MODE_DEACTIVATED:
350  return $lng->txt('trac_mode_deactivated');
351 
352  case LP_MODE_TLT:
353  return $lng->txt('trac_mode_tlt');
354 
355  case LP_MODE_VISITS:
356  return $lng->txt('trac_mode_visits');
357 
358  case LP_MODE_MANUAL:
359  return $lng->txt('trac_mode_manual');
360 
362  return $lng->txt('trac_mode_manual_by_tutor');
363 
364  case LP_MODE_OBJECTIVES:
365  return $lng->txt('trac_mode_objectives');
366 
367  case LP_MODE_COLLECTION:
368  return $lng->txt('trac_mode_collection');
369 
370  case LP_MODE_SCORM:
371  return $lng->txt('trac_mode_scorm');
372 
374  return $lng->txt('trac_mode_test_finished');
375 
376  case LP_MODE_TEST_PASSED:
377  return $lng->txt('trac_mode_test_passed');
378 
380  return $lng->txt('trac_mode_exercise_returned');
381 
383  return $lng->txt('trac_mode_scorm_package');
384 
385  case LP_MODE_EVENT:
386  return $lng->txt('trac_mode_event');
387 
388 
389  }
390  }
391 
400  public static function _mode2InfoText($a_mode)
401  {
402  global $lng;
403 
404  switch($a_mode)
405  {
406  case LP_MODE_DEACTIVATED:
407  return $lng->txt('trac_mode_deactivated_info_new');
408 
409  case LP_MODE_TLT:
410  return $lng->txt('trac_mode_tlt_info');
411 
412  case LP_MODE_VISITS:
413  return $lng->txt('trac_mode_visits_info');
414 
415  case LP_MODE_MANUAL:
416  return $lng->txt('trac_mode_manual_info');
417 
419  return $lng->txt('trac_mode_manual_by_tutor_info');
420 
421  case LP_MODE_OBJECTIVES:
422  return $lng->txt('trac_mode_objectives_info');
423 
424  case LP_MODE_COLLECTION:
425  return $lng->txt('trac_mode_collection_info');
426 
427  case LP_MODE_SCORM:
428  return $lng->txt('trac_mode_scorm_info');
429 
431  return $lng->txt('trac_mode_test_finished_info');
432 
433  case LP_MODE_TEST_PASSED:
434  return $lng->txt('trac_mode_test_passed_info');
435 
437  return $lng->txt('trac_mode_exercise_returned_info');
438 
440  return $lng->txt('trac_mode_scorm_package_info');
441 
442  case LP_MODE_EVENT:
443  return $lng->txt('trac_mode_event_info');
444  }
445 
446  }
447 
448 
449 
450 
451  // Private
452  function _checkObjectives($a_obj_id)
453  {
454  global $ilDB,$ilObjDataCache;
455 
456  // Return deactivate for course with objective view
457  if($ilObjDataCache->lookupType($a_obj_id) == 'crs')
458  {
459  include_once 'Modules/Course/classes/class.ilObjCourse.php';
460 
462  {
463  return true;
464  }
465  }
466  return false;
467  }
468 
469  function _checkSCORMPreconditions($a_obj_id)
470  {
471  global $ilObjDataCache;
472 
473  if($ilObjDataCache->lookupType($a_obj_id) != 'sahs')
474  {
475  return false;
476  }
477  include_once('classes/class.ilConditionHandler.php');
478  if(count($conditions = ilConditionHandler::_getConditionsOfTrigger('sahs',$a_obj_id)))
479  {
480  return true;
481  }
482  return false;
483  }
484 
485 
486 
487  function __read()
488  {
489  $res = $this->db->query("SELECT * FROM ut_lp_settings WHERE obj_id = ".
490  $this->db->quote($this->obj_id ,'integer'));
491  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
492  {
493  $this->is_stored = true;
494  $this->obj_type = $row->obj_type;
495  $this->obj_mode = $row->u_mode;
496  $this->visits = $row->visits;
497 
498  if(ilLPObjSettings::_checkObjectives($this->obj_id))
499  {
500  $this->obj_mode = LP_MODE_OBJECTIVES;
501  }
503  {
504  $this->obj_mode = LP_MODE_SCORM;
505  }
506 
507  return true;
508  }
509 
510  return false;
511  }
512 
513  function __getDefaultMode($a_obj_id,$a_type)
514  {
515  global $ilDB;
516 
517  #$type = strlen($a_type) ? $a_type : $this->obj_type;
518 
519  switch($a_type)
520  {
521  case 'crs':
522  // If objectives are enabled return deactivated
523  if(ilLPObjSettings::_checkObjectives($a_obj_id))
524  {
525  return LP_MODE_OBJECTIVES;
526  }
528 
529  case 'dbk':
530  case 'lm':
531  case 'htlm':
532  return LP_MODE_MANUAL;
533 
534  case 'sahs':
535  return LP_MODE_DEACTIVATED;
536 
537  case 'dbk':
538  return LP_MODE_MANUAL;
539 
540  case 'tst':
541  return LP_MODE_TEST_PASSED;
542 
543  case 'exc':
545 
546  case 'grp':
547  return LP_MODE_DEACTIVATED;
548 
549  case 'fold':
550  return LP_MODE_DEACTIVATED;
551 
552  case 'sess':
553  return LP_MODE_EVENT;
554 
555  default:
556  return LP_MODE_UNDEFINED;
557  }
558  }
559 }
560 ?>