ILIAS  release_7 Revision v7.30-3-g800a261c036
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 public const TYPE_LOCALIZED_TEXT = 'LocalizedText';
9
10 protected static $instance; // [ilADTFactory]
11
17 protected function __construct()
18 {
19 }
20
26 public static function getInstance()
27 {
28 if (self::$instance === null) {
29 self::$instance = new self;
30 }
31 return self::$instance;
32 }
33
39 public function getValidTypes()
40 {
41 return array(
42 "Float", "Integer", "Location", "Text", "Boolean",
43 "MultiText", "Date", "DateTime", "Enum", "MultiEnum", "Group",
44 'ExternalLink','InternalLink', self::TYPE_LOCALIZED_TEXT
45 );
46 }
47
54 public function isValidType($a_type)
55 {
56 return in_array((string) $a_type, $this->getValidTypes());
57 }
58
67 public function initTypeClass($a_type, $a_class = null)
68 {
69 if ($this->isValidType($a_type)) {
70 $class = "ilADT" . $a_type . $a_class;
71 $file = "Services/ADT/classes/Types/" . $a_type . "/class." . $class . ".php";
72 if (file_exists($file)) {
73 require_once $file;
74 return $class;
75 }
76 }
77
78 throw new Exception("ilADTFactory unknown type: " . $a_type . ' -> ' . $file);
79 }
80
88 public function getDefinitionInstanceByType($a_type)
89 {
90 $class = $this->initTypeClass($a_type, "Definition");
91 return new $class();
92 }
93
102 {
103 if (!method_exists($a_def, "getADTInstance")) {
104 $class = $this->initTypeClass($a_def->getType());
105 return new $class($a_def);
106 } else {
107 return $a_def->getADTInstance();
108 }
109 }
110
111
112 //
113 // bridges
114 //
115
123 public function getFormBridgeForInstance(ilADT $a_adt)
124 {
125 $class = $this->initTypeClass($a_adt->getType(), "FormBridge");
126 return new $class($a_adt);
127 }
128
136 public function getDBBridgeForInstance(ilADT $a_adt)
137 {
138 $class = $this->initTypeClass($a_adt->getType(), "DBBridge");
139 return new $class($a_adt);
140 }
141
150 {
151 $class = $this->initTypeClass($a_adt->getType(), "PresentationBridge");
152 return new $class($a_adt);
153 }
154
163 public function getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, $a_range = true, $a_multi = true)
164 {
165 if ($a_range) {
166 try {
167 $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeRange");
168 return new $class($a_adt_def);
169 } catch (Exception $e) {
170 }
171 }
172
173 // multi enum search (single) == enum search (multi)
174 if (!$a_multi &&
175 $a_adt_def->getType() == "MultiEnum") {
176 $class = $this->initTypeClass("Enum", "SearchBridgeMulti");
177 return new $class($a_adt_def);
178 }
179
180 if ($a_multi) {
181 try {
182 if ($a_adt_def->getType() == 'MultiEnum') {
183 $class = $this->initTypeClass('Enum','SearchBridgeMulti');
184 return new $class($a_adt_def);
185 }
186 $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeMulti");
187 return new $class($a_adt_def);
188 } catch (Exception $e) {
189 }
190 }
191 $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeSingle");
192 return new $class($a_adt_def);
193 }
194
195
203 {
204 $class = $this->initTypeClass($a_adt->getType(), "ActiveRecordBridge");
205 return new $class($a_adt);
206 }
207
208
209 //
210 // active records
211 //
212
219 public static function getActiveRecordInstance(ilADTGroupDBBridge $a_properties)
220 {
221 require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecord.php";
222 return new ilADTActiveRecord($a_properties);
223 }
224
228 public static function initActiveRecordByType()
229 {
230 require_once "Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php";
231 }
232
239 public static function getActiveRecordByTypeInstance(ilADTGroupDBBridge $a_properties)
240 {
242 return new ilADTActiveRecordByType($a_properties);
243 }
244}
An exception for terminatinating execution or to throw for unit testing.
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:53