ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
24  public static function getInstance()
25  {
26  if (self::$instance === null) {
27  self::$instance = new self;
28  }
29  return self::$instance;
30  }
31 
37  public function getValidTypes()
38  {
39  return array(
40  "Float", "Integer", "Location", "Text", "Boolean",
41  "MultiText", "Date", "DateTime", "Enum", "MultiEnum", "Group",
42  'ExternalLink','InternalLink'
43  );
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  $class = "ilADT" . $a_type . $a_class;
69  $file = "Services/ADT/classes/Types/" . $a_type . "/class." . $class . ".php";
70  if (file_exists($file)) {
71  require_once $file;
72  return $class;
73  }
74  }
75 
76  throw new Exception("ilADTFactory unknown type: " . $a_type . ' -> ' . $file);
77  }
78 
87  {
88  $class = $this->initTypeClass($a_type, "Definition");
89  return new $class();
90  }
91 
99  public function getInstanceByDefinition(ilADTDefinition $a_def)
100  {
101  if (!method_exists($a_def, "getADTInstance")) {
102  $class = $this->initTypeClass($a_def->getType());
103  return new $class($a_def);
104  } else {
105  return $a_def->getADTInstance();
106  }
107  }
108 
109 
110  //
111  // bridges
112  //
113 
121  public function getFormBridgeForInstance(ilADT $a_adt)
122  {
123  $class = $this->initTypeClass($a_adt->getType(), "FormBridge");
124  return new $class($a_adt);
125  }
126 
134  public function getDBBridgeForInstance(ilADT $a_adt)
135  {
136  $class = $this->initTypeClass($a_adt->getType(), "DBBridge");
137  return new $class($a_adt);
138  }
139 
147  public function getPresentationBridgeForInstance(ilADT $a_adt)
148  {
149  $class = $this->initTypeClass($a_adt->getType(), "PresentationBridge");
150  return new $class($a_adt);
151  }
152 
161  public function getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, $a_range = true, $a_multi = true)
162  {
163  if ($a_range) {
164  try {
165  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeRange");
166  return new $class($a_adt_def);
167  } catch (Exception $e) {
168  }
169  }
170 
171  // multi enum search (single) == enum search (multi)
172  if (!$a_multi &&
173  $a_adt_def->getType() == "MultiEnum") {
174  $class = $this->initTypeClass("Enum", "SearchBridgeMulti");
175  return new $class($a_adt_def);
176  }
177 
178  if ($a_multi) {
179  try {
180  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeMulti");
181  return new $class($a_adt_def);
182  } catch (Exception $e) {
183  }
184  }
185  $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeSingle");
186  return new $class($a_adt_def);
187  }
188 
189 
196  public function getActiveRecordBridgeForInstance(ilADT $a_adt)
197  {
198  $class = $this->initTypeClass($a_adt->getType(), "ActiveRecordBridge");
199  return new $class($a_adt);
200  }
201 
202 
203  //
204  // active records
205  //
206 
213  public static function getActiveRecordInstance(ilADTGroupDBBridge $a_properties)
214  {
215  require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecord.php";
216  return new ilADTActiveRecord($a_properties);
217  }
218 
222  public static function initActiveRecordByType()
223  {
224  require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php";
225  }
226 
233  public static function getActiveRecordByTypeInstance(ilADTGroupDBBridge $a_properties)
234  {
235  self::initActiveRecordByType();
236  return new ilADTActiveRecordByType($a_properties);
237  }
238 }
initTypeClass($a_type, $a_class=null)
Init type-specific class.
getType()
Get type (from class/instance)
Definition: class.ilADT.php:53
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:92
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.