ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLPStatusFactory.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
6
20{
21 private static $class_by_obj_id = array();
22
23 public static function _getClassById($a_obj_id, $a_mode = null)
24 {
25 if ($a_mode === null) {
26 include_once 'Services/Object/classes/class.ilObjectLP.php';
27 $olp = ilObjectLP::getInstance($a_obj_id);
28 $a_mode = $olp->getCurrentMode();
29
30 // please keep the cache in this if-block, otherwise default values
31 // will not trigger the include_once calls
32 if (isset(self::$class_by_obj_id[$a_obj_id])) {
33 return self::$class_by_obj_id[$a_obj_id];
34 }
35 }
36
38
39 if (array_key_exists($a_mode, $map)) {
40 $class = $map[$a_mode];
41
42 // undefined? try object lp directly
43 if ($class === null) {
44 include_once 'Services/Object/classes/class.ilObjectLP.php';
45 $olp = ilObjectLP::getInstance($a_obj_id);
46 $mode = $olp->getCurrentMode();
48 return self::_getClassById($a_obj_id, $mode);
49 }
50 } else {
51 self::includeClass($class);
52 self::$class_by_obj_id[$a_obj_id] = $class;
53 return $class;
54 }
55 }
56
57 // we probably can do better
58 echo "ilLPStatusFactory: unknown type " . $a_mode;
59 exit;
60 }
61
62 protected static function includeClass($a_class)
63 {
64 $path = ($a_class == 'ilLPStatus')
65 ? 'Services/Tracking/classes/'
66 : 'Services/Tracking/classes/status/';
67 include_once $path . 'class.' . $a_class . '.php';
68 }
69
70 public static function _getClassByIdAndType($a_obj_id, $a_type)
71 {
72 // id is ignored in the moment
73 switch ($a_type) {
74 case 'event':
75 self::includeClass('ilLPStatusEvent');
76 return 'ilLPStatusEvent';
77
78 default:
79 echo "ilLPStatusFactory: unknown type: " . $a_type;
80 exit;
81 }
82 }
83
84 public static function _getInstance($a_obj_id, $a_mode = null)
85 {
86 if ($a_mode === null) {
87 include_once 'Services/Object/classes/class.ilObjectLP.php';
88 $olp = ilObjectLP::getInstance($a_obj_id);
89 $a_mode = $olp->getCurrentMode();
90 }
91
93
94 if (array_key_exists($a_mode, $map)) {
95 $class = $map[$a_mode];
96
97 // undefined? try object lp directly
98 if ($class === null) {
99 include_once 'Services/Object/classes/class.ilObjectLP.php';
100 $olp = ilObjectLP::getInstance($a_obj_id);
101 $mode = $olp->getCurrentMode();
103 return self::_getInstance($a_obj_id, $mode);
104 }
105 } else {
106 self::includeClass($class);
107 return new $class($a_obj_id);
108 }
109 }
110
111 // we probably can do better
112 echo "ilLPStatusFactory: unknown type " . $a_mode;
113 exit;
114 }
115}
An exception for terminatinating execution or to throw for unit testing.
Class ilLPStatusFactory Creates status class instances for learning progress modes of an object.
static includeClass($a_class)
static _getClassById($a_obj_id, $a_mode=null)
static _getClassByIdAndType($a_obj_id, $a_type)
static _getInstance($a_obj_id, $a_mode=null)
static getInstance($a_obj_id)
$a_type
Definition: workflow.php:92