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