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