ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 include_once 'Services/Tracking/classes/class.ilLPObjSettings.php';
6 
20 {
21  static private $class_by_obj_id = array();
22 
23  static function _getClassById($a_obj_id, $a_mode = NULL)
24  {
25  if($a_mode === NULL)
26  {
27  include_once 'Services/Object/classes/class.ilObjectLP.php';
28  $olp = ilObjectLP::getInstance($a_obj_id);
29  $a_mode = $olp->getCurrentMode();
30 
31  // please keep the cache in this if-block, otherwise default values
32  // will not trigger the include_once calls
33  if (isset(self::$class_by_obj_id[$a_obj_id]))
34  {
35  return self::$class_by_obj_id[$a_obj_id];
36  }
37  }
38 
40 
41  if(array_key_exists($a_mode, $map))
42  {
43  $class = $map[$a_mode];
44 
45  // undefined? try object lp directly
46  if($class === null)
47  {
48  include_once 'Services/Object/classes/class.ilObjectLP.php';
49  $olp = ilObjectLP::getInstance($a_obj_id);
50  $mode = $olp->getCurrentMode();
52  {
53  return self::_getClassById($a_obj_id, $mode);
54  }
55  }
56  else
57  {
58  self::includeClass($class);
59  self::$class_by_obj_id[$a_obj_id] = $class;
60  return $class;
61  }
62  }
63 
64  // we probably can do better
65  echo "ilLPStatusFactory: unknown type ".$a_mode;
66  exit;
67  }
68 
69  protected static function includeClass($a_class)
70  {
71  $path = ($a_class == 'ilLPStatus')
72  ? 'Services/Tracking/classes/'
73  : 'Services/Tracking/classes/status/';
74  include_once $path.'class.'.$a_class.'.php';
75  }
76 
77  static function _getClassByIdAndType($a_obj_id,$a_type)
78  {
79  // id is ignored in the moment
80  switch($a_type)
81  {
82  case 'event':
83  self::includeClass('ilLPStatusEvent');
84  return 'ilLPStatusEvent';
85 
86  default:
87  echo "ilLPStatusFactory: unknown type: ".$a_type;
88  exit;
89  }
90  }
91 
92  static function _getInstance($a_obj_id, $a_mode = NULL)
93  {
94  if($a_mode === NULL)
95  {
96  include_once 'Services/Object/classes/class.ilObjectLP.php';
97  $olp = ilObjectLP::getInstance($a_obj_id);
98  $a_mode = $olp->getCurrentMode();
99  }
100 
102 
103  if(array_key_exists($a_mode, $map))
104  {
105  $class = $map[$a_mode];
106 
107  // undefined? try object lp directly
108  if($class === null)
109  {
110  include_once 'Services/Object/classes/class.ilObjectLP.php';
111  $olp = ilObjectLP::getInstance($a_obj_id);
112  $mode = $olp->getCurrentMode();
114  {
115  return self::_getInstance($a_obj_id, $mode);
116  }
117  }
118  else
119  {
120  self::includeClass($class);
121  return new $class($a_obj_id);
122  }
123  }
124 
125  // we probably can do better
126  echo "ilLPStatusFactory: unknown type ".$a_mode;
127  exit;
128  }
129 }
130 
131 ?>
$path
Definition: aliased.php:25
static includeClass($a_class)
static _getClassById($a_obj_id, $a_mode=NULL)
$a_type
Definition: workflow.php:93
Class ilLPStatusFactory Creates status class instances for learning progress modes of an object...
static _getClassByIdAndType($a_obj_id, $a_type)
static _getInstance($a_obj_id, $a_mode=NULL)
Create styles array
The data for the language used.
static getInstance($a_obj_id)