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