ILIAS  release_8 Revision v8.23
class.ilLPStatusFactory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
5 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
15 {
16  private static ?self $instance = null;
17  private static array $class_by_obj_id = array();
18 
19  private ilLogger $logger;
20 
21  private static function getFactoryInstance(): ilLPStatusFactory
22  {
23  if (!self::$instance) {
24  self::$instance = new self();
25  }
26  return self::$instance;
27  }
28 
29  private function __construct()
30  {
31  global $DIC;
32 
33  $this->logger = $DIC->logger()->trac();
34  }
35 
36  private function getLogger(): ilLogger
37  {
38  return $this->logger;
39  }
40 
41  public static function _getClassById(
42  int $a_obj_id,
43  ?int $a_mode = null
44  ): string {
45  if ($a_mode === null) {
46  $olp = ilObjectLP::getInstance($a_obj_id);
47  $a_mode = $olp->getCurrentMode();
48 
49  // please keep the cache in this if-block, otherwise default values
50  if (isset(self::$class_by_obj_id[$a_obj_id])) {
51  return self::$class_by_obj_id[$a_obj_id];
52  }
53  }
54 
56 
57  if (array_key_exists($a_mode, $map)) {
58  $class = $map[$a_mode];
59 
60  // undefined? try object lp directly
61  if ($class === null) {
62  $olp = ilObjectLP::getInstance($a_obj_id);
63  $mode = $olp->getCurrentMode();
65  return self::_getClassById($a_obj_id, $mode);
66  }
67  } else {
68  self::$class_by_obj_id[$a_obj_id] = $class;
69  return $class;
70  }
71  }
72 
73  $factory = self::getFactoryInstance();
74  $message = 'Unknown LP mode given: ' . $a_mode;
75  $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
77  }
78 
79  public static function _getClassByIdAndType(
80  int $a_obj_id,
81  string $a_type
82  ): string {
83  // id is ignored in the moment
84  switch ($a_type) {
85  case 'event':
86  return 'ilLPStatusEvent';
87 
88  default:
89  $factory = self::getFactoryInstance();
90  $message = 'Unknown LP type given: ' . $a_type;
91  $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
93  }
94  }
95 
96  public static function _getInstance(
97  int $a_obj_id,
98  ?int $a_mode = null
99  ): ilLPStatus {
100  if ($a_mode === null) {
101  $olp = ilObjectLP::getInstance($a_obj_id);
102  $a_mode = $olp->getCurrentMode();
103  }
104 
106 
107  if (array_key_exists($a_mode, $map)) {
108  $class = $map[$a_mode];
109 
110  // undefined? try object lp directly
111  if ($class === null) {
112  $olp = ilObjectLP::getInstance($a_obj_id);
113  $mode = $olp->getCurrentMode();
114  if ($mode != ilLPObjSettings::LP_MODE_UNDEFINED) {
115  return self::_getInstance($a_obj_id, $mode);
116  }
117  } else {
118  return new $class($a_obj_id);
119  }
120  }
121 
122  $factory = self::getFactoryInstance();
123  $message = 'Unknown LP mode given: ' . $a_mode;
124  $factory->getLogger()->logStack(ilLogLevel::ERROR, $message);
126  }
127 }
global $DIC
Definition: feed.php:28
Class ilLPStatusFactory Creates status class instances for learning progress modes of an object...
static _getClassByIdAndType(int $a_obj_id, string $a_type)
static _getClassById(int $a_obj_id, ?int $a_mode=null)
static _getInstance(int $a_obj_id, ?int $a_mode=null)
$message
Definition: xapiexit.php:32
static getInstance(int $obj_id)
$factory
Definition: metadata.php:75