ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPStatusFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
29{
30 private static ?self $instance = null;
31 private static array $class_by_obj_id = array();
32
34
35 private static function getFactoryInstance(): ilLPStatusFactory
36 {
37 if (!self::$instance) {
38 self::$instance = new self();
39 }
40 return self::$instance;
41 }
42
43 private function __construct()
44 {
45 global $DIC;
46
47 $this->logger = $DIC->logger()->trac();
48 }
49
50 private function getLogger(): ilLogger
51 {
52 return $this->logger;
53 }
54
55 public static function _getClassById(
56 int $a_obj_id,
57 ?int $a_mode = null
58 ): string {
59 if ($a_mode === null) {
60 $olp = ilObjectLP::getInstance($a_obj_id);
61 $a_mode = $olp->getCurrentMode();
62
63 // please keep the cache in this if-block, otherwise default values
64 if (isset(self::$class_by_obj_id[$a_obj_id])) {
65 return self::$class_by_obj_id[$a_obj_id];
66 }
67 }
68
70
71 if (array_key_exists($a_mode, $map)) {
72 $class = $map[$a_mode];
73
74 // undefined? try object lp directly
75 if ($class === null) {
76 $olp = ilObjectLP::getInstance($a_obj_id);
77 $mode = $olp->getCurrentMode();
79 return self::_getClassById($a_obj_id, $mode);
80 }
81 } else {
82 self::$class_by_obj_id[$a_obj_id] = $class;
83 return $class;
84 }
85 }
86
87 $factory = self::getFactoryInstance();
88 $message = 'Unknown LP mode given: ' . $a_mode;
89 $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
91 }
92
93 public static function _getClassByIdAndType(
94 int $a_obj_id,
95 string $a_type
96 ): string {
97 // id is ignored in the moment
98 switch ($a_type) {
99 case 'event':
100 return 'ilLPStatusEvent';
101
102 default:
103 $factory = self::getFactoryInstance();
104 $message = 'Unknown LP type given: ' . $a_type;
105 $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
107 }
108 }
109
110 public static function _getInstance(
111 int $a_obj_id,
112 ?int $a_mode = null
113 ): ilLPStatus {
114 if ($a_mode === null) {
115 $olp = ilObjectLP::getInstance($a_obj_id);
116 $a_mode = $olp->getCurrentMode();
117 }
118
120
121 if (array_key_exists($a_mode, $map)) {
122 $class = $map[$a_mode];
123
124 // undefined? try object lp directly
125 if ($class === null) {
126 $olp = ilObjectLP::getInstance($a_obj_id);
127 $mode = $olp->getCurrentMode();
129 return self::_getInstance($a_obj_id, $mode);
130 }
131 } else {
132 return new $class($a_obj_id);
133 }
134 }
135
136 $factory = self::getFactoryInstance();
137 $message = 'Unknown LP mode given: ' . $a_mode;
138 $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
140 }
141}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilLPStatusFactory Creates status class instances for learning progress modes of an object.
static _getInstance(int $a_obj_id, ?int $a_mode=null)
static _getClassByIdAndType(int $a_obj_id, string $a_type)
static _getClassById(int $a_obj_id, ?int $a_mode=null)
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
Component logger with individual log levels by component id.
static getInstance(int $obj_id)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31