ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
18  }
19 
25  public static function getInstance()
26  {
27  if(self::$instance === null)
28  {
29  self::$instance = new self;
30  }
31  return self::$instance;
32  }
33 
39  public function getValidTypes()
40  {
41  return array("Float", "Integer", "Location", "Text", "Boolean",
42  "MultiText", "Date", "DateTime", "Enum", "MultiEnum", "Group");
43  }
44 
51  public function isValidType($a_type)
52  {
53  return in_array((string)$a_type, $this->getValidTypes());
54  }
55 
64  public function initTypeClass($a_type, $a_class = null)
65  {
66  if($this->isValidType($a_type))
67  {
68  $class = "ilADT".$a_type.$a_class;
69  $file = "Services/ADT/classes/Types/".$a_type."/class.".$class.".php";
70  if(file_exists($file))
71  {
72  require_once $file;
73  return $class;
74  }
75  }
76 
77  throw new Exception("ilADTFactory unknown type");
78  }
79 
88  {
89  $class = $this->initTypeClass($a_type, "Definition");
90  return new $class();
91  }
92 
100  public function getInstanceByDefinition(ilADTDefinition $a_def)
101  {
102  if(!method_exists($a_def, "getADTInstance"))
103  {
104  $class = $this->initTypeClass($a_def->getType());
105  return new $class($a_def);
106  }
107  else
108  {
109  return $a_def->getADTInstance();
110  }
111  }
112 
113 
114  //
115  // bridges
116  //
117 
125  public function getFormBridgeForInstance(ilADT $a_adt)
126  {
127  $class = $this->initTypeClass($a_adt->getType(), "FormBridge");
128  return new $class($a_adt);
129  }
130 
138  public function getDBBridgeForInstance(ilADT $a_adt)
139  {
140  $class = $this->initTypeClass($a_adt->getType(), "DBBridge");
141  return new $class($a_adt);
142  }
143 
151  public function getPresentationBridgeForInstance(ilADT $a_adt)
152  {
153  $class = $this->initTypeClass($a_adt->getType(), "PresentationBridge");
154  return new $class($a_adt);
155  }
156 
165  public function getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, $a_range = true, $a_multi = true)
166  {
167  if($a_range)
168  {
169  try
170  {
171  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeRange");
172  return new $class($a_adt_def);
173  }
174  catch(Exception $e)
175  {
176 
177  }
178  }
179 
180  // multi enum search (single) == enum search (multi)
181  if(!$a_multi &&
182  $a_adt_def->getType() == "MultiEnum")
183  {
184  $class = $this->initTypeClass("Enum", "SearchBridgeMulti");
185  return new $class($a_adt_def);
186  }
187 
188  if($a_multi)
189  {
190  try
191  {
192  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeMulti");
193  return new $class($a_adt_def);
194  }
195  catch(Exception $e)
196  {
197 
198  }
199  }
200  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeSingle");
201  return new $class($a_adt_def);
202  }
203 
204 
211  public function getActiveRecordBridgeForInstance(ilADT $a_adt)
212  {
213  $class = $this->initTypeClass($a_adt->getType(), "ActiveRecordBridge");
214  return new $class($a_adt);
215  }
216 
217 
218  //
219  // active records
220  //
221 
228  public static function getActiveRecordInstance(ilADTGroupDBBridge $a_properties)
229  {
230  require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecord.php";
231  return new ilADTActiveRecord($a_properties);
232  }
233 
237  public static function initActiveRecordByType()
238  {
239  require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php";
240  }
241 
248  public static function getActiveRecordByTypeInstance(ilADTGroupDBBridge $a_properties)
249  {
250  self::initActiveRecordByType();
251  return new ilADTActiveRecordByType($a_properties);
252  }
253 }
254 
255 ?>
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.
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
$a_type
Definition: workflow.php:93
getActiveRecordBridgeForInstance(ilADT $a_adt)
Get active record instance for ADT.
Create styles array
The data for the language used.
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)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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.