ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTFactory.php
Go to the documentation of this file.
1 <?php
2 
3 require_once "Services/ADT/classes/class.ilADT.php";
4 require_once "Services/ADT/classes/class.ilADTDefinition.php";
5 
7 {
8  protected static $instance; // [ilADTFactory]
9 
15  protected function __construct()
16  {
17  // #15666 - generic fix in 5.1+, but float/location needs this
18  setlocale(LC_NUMERIC, 'C');
19  }
20 
26  public static function getInstance()
27  {
28  if(self::$instance === null)
29  {
30  self::$instance = new self;
31  }
32  return self::$instance;
33  }
34 
40  public function getValidTypes()
41  {
42  return array("Float", "Integer", "Location", "Text", "Boolean",
43  "MultiText", "Date", "DateTime", "Enum", "MultiEnum", "Group");
44  }
45 
52  public function isValidType($a_type)
53  {
54  return in_array((string)$a_type, $this->getValidTypes());
55  }
56 
65  public function initTypeClass($a_type, $a_class = null)
66  {
67  if($this->isValidType($a_type))
68  {
69  $class = "ilADT".$a_type.$a_class;
70  $file = "Services/ADT/classes/Types/".$a_type."/class.".$class.".php";
71  if(file_exists($file))
72  {
73  require_once $file;
74  return $class;
75  }
76  }
77 
78  throw new Exception("ilADTFactory unknown type");
79  }
80 
88  public function getDefinitionInstanceByType($a_type)
89  {
90  $class = $this->initTypeClass($a_type, "Definition");
91  return new $class();
92  }
93 
101  public function getInstanceByDefinition(ilADTDefinition $a_def)
102  {
103  if(!method_exists($a_def, "getADTInstance"))
104  {
105  $class = $this->initTypeClass($a_def->getType());
106  return new $class($a_def);
107  }
108  else
109  {
110  return $a_def->getADTInstance();
111  }
112  }
113 
114 
115  //
116  // bridges
117  //
118 
126  public function getFormBridgeForInstance(ilADT $a_adt)
127  {
128  $class = $this->initTypeClass($a_adt->getType(), "FormBridge");
129  return new $class($a_adt);
130  }
131 
139  public function getDBBridgeForInstance(ilADT $a_adt)
140  {
141  $class = $this->initTypeClass($a_adt->getType(), "DBBridge");
142  return new $class($a_adt);
143  }
144 
152  public function getPresentationBridgeForInstance(ilADT $a_adt)
153  {
154  $class = $this->initTypeClass($a_adt->getType(), "PresentationBridge");
155  return new $class($a_adt);
156  }
157 
166  public function getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, $a_range = true, $a_multi = true)
167  {
168  if($a_range)
169  {
170  try
171  {
172  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeRange");
173  return new $class($a_adt_def);
174  }
175  catch(Exception $e)
176  {
177 
178  }
179  }
180 
181  // multi enum search (single) == enum search (multi)
182  if(!$a_multi &&
183  $a_adt_def->getType() == "MultiEnum")
184  {
185  $class = $this->initTypeClass("Enum", "SearchBridgeMulti");
186  return new $class($a_adt_def);
187  }
188 
189  if($a_multi)
190  {
191  try
192  {
193  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeMulti");
194  return new $class($a_adt_def);
195  }
196  catch(Exception $e)
197  {
198 
199  }
200  }
201  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeSingle");
202  return new $class($a_adt_def);
203  }
204 
205 
212  public function getActiveRecordBridgeForInstance(ilADT $a_adt)
213  {
214  $class = $this->initTypeClass($a_adt->getType(), "ActiveRecordBridge");
215  return new $class($a_adt);
216  }
217 
218 
219  //
220  // active records
221  //
222 
229  public static function getActiveRecordInstance(ilADTGroupDBBridge $a_properties)
230  {
231  require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecord.php";
232  return new ilADTActiveRecord($a_properties);
233  }
234 
238  public static function initActiveRecordByType()
239  {
240  require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php";
241  }
242 
249  public static function getActiveRecordByTypeInstance(ilADTGroupDBBridge $a_properties)
250  {
251  self::initActiveRecordByType();
252  return new ilADTActiveRecordByType($a_properties);
253  }
254 }
255 
256 ?>
initTypeClass($a_type, $a_class=null)
Init type-specific class.
getType()
Get type (from class/instance)
Definition: class.ilADT.php:51
getDBBridgeForInstance(ilADT $a_adt)
Get DB bridge instance for ADT.
print $file
ADT Active Record by type helper class.
static getActiveRecordInstance(ilADTGroupDBBridge $a_properties)
Get active record instance.
static initActiveRecordByType()
Init active record by type.
getDefinitionInstanceByType($a_type)
Get instance of ADT definition.
getValidTypes()
Get all ADT types.
isValidType($a_type)
Check if given type is valid.
static getInstance()
Get singleton.
__construct()
Constructor.
ADT base class.
Definition: class.ilADT.php:11
getActiveRecordBridgeForInstance(ilADT $a_adt)
Get active record instance for ADT.
ADT Active Record helper class.
getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, $a_range=true, $a_multi=true)
Get search bridge instance for ADT definition.
getFormBridgeForInstance(ilADT $a_adt)
Get form bridge instance for ADT.
getInstanceByDefinition(ilADTDefinition $a_def)
Get instance of ADT.
getType()
Get type (from class/instance)
getPresentationBridgeForInstance(ilADT $a_adt)
Get presentation bridge instance for ADT.
ADT definition base class.
static getActiveRecordByTypeInstance(ilADTGroupDBBridge $a_properties)
Get active record by type instance.