ILIAS  release_7 Revision v7.30-3-g800a261c036
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
15{
19 private static $instance;
20
24 private $logger;
25
26
27
28 private static $class_by_obj_id = array();
29
33 private static function getFactoryInstance() : ilLPStatusFactory
34 {
35 if (!self::$instance) {
36 self::$instance = new self();
37 }
38 return self::$instance;
39
40 }
41
45 private function __construct()
46 {
47 global $DIC;
48
49 $this->logger = $DIC->logger()->trac();
50 }
51
55 private function getLogger()
56 {
57 return $this->logger;
58 }
59
66 public static function _getClassById($a_obj_id, $a_mode = null)
67 {
68 if ($a_mode === null) {
69 include_once 'Services/Object/classes/class.ilObjectLP.php';
70 $olp = ilObjectLP::getInstance($a_obj_id);
71 $a_mode = $olp->getCurrentMode();
72
73 // please keep the cache in this if-block, otherwise default values
74 // will not trigger the include_once calls
75 if (isset(self::$class_by_obj_id[$a_obj_id])) {
76 return self::$class_by_obj_id[$a_obj_id];
77 }
78 }
79
81
82 if (array_key_exists($a_mode, $map)) {
83 $class = $map[$a_mode];
84
85 // undefined? try object lp directly
86 if ($class === null) {
87 include_once 'Services/Object/classes/class.ilObjectLP.php';
88 $olp = ilObjectLP::getInstance($a_obj_id);
89 $mode = $olp->getCurrentMode();
91 return self::_getClassById($a_obj_id, $mode);
92 }
93 } else {
94 self::includeClass($class);
95 self::$class_by_obj_id[$a_obj_id] = $class;
96 return $class;
97 }
98 }
99
101 $message = 'Unknown LP mode given: ' . $a_mode;
102 $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
104 }
105
106 protected static function includeClass($a_class)
107 {
108 $path = ($a_class == 'ilLPStatus')
109 ? 'Services/Tracking/classes/'
110 : 'Services/Tracking/classes/status/';
111 include_once $path . 'class.' . $a_class . '.php';
112 }
113
120 public static function _getClassByIdAndType($a_obj_id, $a_type)
121 {
122 // id is ignored in the moment
123 switch ($a_type) {
124 case 'event':
125 self::includeClass('ilLPStatusEvent');
126 return 'ilLPStatusEvent';
127
128 default:
130 $message = 'Unknown LP type given: ' . $a_type;
131 $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
133 }
134 }
135
142 public static function _getInstance($a_obj_id, $a_mode = null)
143 {
144 if ($a_mode === null) {
145 include_once 'Services/Object/classes/class.ilObjectLP.php';
146 $olp = ilObjectLP::getInstance($a_obj_id);
147 $a_mode = $olp->getCurrentMode();
148 }
149
151
152 if (array_key_exists($a_mode, $map)) {
153 $class = $map[$a_mode];
154
155 // undefined? try object lp directly
156 if ($class === null) {
157 include_once 'Services/Object/classes/class.ilObjectLP.php';
158 $olp = ilObjectLP::getInstance($a_obj_id);
159 $mode = $olp->getCurrentMode();
161 return self::_getInstance($a_obj_id, $mode);
162 }
163 } else {
164 self::includeClass($class);
165 return new $class($a_obj_id);
166 }
167 }
168
170 $message = 'Unknown LP mode given: ' . $a_mode;
171 $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
173 }
174}
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)
__construct()
ilLPStatusFactory constructor.
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)
global $DIC
Definition: goto.php:24
$factory
Definition: metadata.php:58
$message
Definition: xapiexit.php:14