ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilADTFactory.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/class.ilADT.php";
4require_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
87 public function getDefinitionInstanceByType($a_type)
88 {
89 $class = $this->initTypeClass($a_type, "Definition");
90 return new $class();
91 }
92
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
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
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 {
251 return new ilADTActiveRecordByType($a_properties);
252 }
253}
254
255?>
print $file
ADT Active Record by type helper class.
ADT Active Record helper class.
ADT definition base class.
getType()
Get type (from class/instance)
static getInstance()
Get singleton.
getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, $a_range=true, $a_multi=true)
Get search bridge instance for ADT definition.
getDBBridgeForInstance(ilADT $a_adt)
Get DB bridge instance for ADT.
getValidTypes()
Get all ADT types.
static getActiveRecordByTypeInstance(ilADTGroupDBBridge $a_properties)
Get active record by type instance.
static getActiveRecordInstance(ilADTGroupDBBridge $a_properties)
Get active record instance.
getPresentationBridgeForInstance(ilADT $a_adt)
Get presentation bridge instance for ADT.
getFormBridgeForInstance(ilADT $a_adt)
Get form bridge instance for ADT.
__construct()
Constructor.
initTypeClass($a_type, $a_class=null)
Init type-specific class.
static initActiveRecordByType()
Init active record by type.
getDefinitionInstanceByType($a_type)
Get instance of ADT definition.
getActiveRecordBridgeForInstance(ilADT $a_adt)
Get active record instance for ADT.
isValidType($a_type)
Check if given type is valid.
getInstanceByDefinition(ilADTDefinition $a_def)
Get instance of ADT.
ADT base class.
Definition: class.ilADT.php:12
getType()
Get type (from class/instance)
Definition: class.ilADT.php:51