ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const TYPE_LOCALIZED_TEXT = 'LocalizedText';
27
28 protected static ?ilADTFactory $instance = null;
29
30 public static function getInstance(): ilADTFactory
31 {
32 if (self::$instance === null) {
33 self::$instance = new self();
34 }
35 return self::$instance;
36 }
37
42 public function getValidTypes(): array
43 {
44 return array(
45 "Float",
46 "Integer",
47 "Location",
48 "Text",
49 "Boolean",
50 "MultiText",
51 "Date",
52 "DateTime",
53 "Enum",
54 "MultiEnum",
55 "Group",
56 'ExternalLink',
57 'InternalLink',
58 self::TYPE_LOCALIZED_TEXT
59 );
60 }
61
62 public function isValidType(string $a_type): bool
63 {
64 return in_array($a_type, $this->getValidTypes());
65 }
66
67 public function initTypeClass(string $a_type, ?string $a_class = null): string
68 {
69 $class = '';
70 if ($this->isValidType($a_type)) {
71 $class = "ilADT" . $a_type . $a_class;
72 return $class;
73 }
74 throw new InvalidArgumentException("ilADTFactory unknown type: " . $a_type);
75 }
76
83 public function getDefinitionInstanceByType(string $a_type): ilADTDefinition
84 {
85 $class = $this->initTypeClass($a_type, "Definition");
86 return new $class();
87 }
88
96 {
97 if (!method_exists($a_def, "getADTInstance")) {
98 $class = $this->initTypeClass($a_def->getType());
99 return new $class($a_def);
100 } else {
101 return $a_def->getADTInstance();
102 }
103 }
104
112 {
113 $class = $this->initTypeClass($a_adt->getType(), "FormBridge");
114 return new $class($a_adt);
115 }
116
124 {
125 $class = $this->initTypeClass($a_adt->getType(), "DBBridge");
126 return new $class($a_adt);
127 }
128
136 {
137 $class = $this->initTypeClass($a_adt->getType(), "PresentationBridge");
138 return new $class($a_adt);
139 }
140
150 ilADTDefinition $a_adt_def,
151 bool $a_range = true,
152 bool $a_multi = true
154 if ($a_range) {
155 try {
156 $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeRange");
157 if (class_exists($class)) {
158 return new $class($a_adt_def);
159 }
160 } catch (Exception $e) {
161 }
162 }
163
164 // multi enum search (single) == enum search (multi)
165 if (!$a_multi &&
166 $a_adt_def->getType() == "MultiEnum") {
167 $class = $this->initTypeClass("Enum", "SearchBridgeMulti");
168 return new $class($a_adt_def);
169 }
170
171 if ($a_multi) {
172 try {
173 if ($a_adt_def->getType() == 'MultiEnum') {
174 $class = $this->initTypeClass('Enum', 'SearchBridgeMulti');
175 return new $class($a_adt_def);
176 }
177 $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeMulti");
178 return new $class($a_adt_def);
179 } catch (Exception $e) {
180 }
181 }
182 $class = $this->initTypeClass($a_adt_def->getType(), "SearchBridgeSingle");
183 return new $class($a_adt_def);
184 }
185
193 {
194 $class = $this->initTypeClass($a_adt->getType(), "ActiveRecordBridge");
195 return new $class($a_adt);
196 }
197
198
199 //
200 // active records
201 //
202
208 public static function getActiveRecordInstance(ilADTGroupDBBridge $a_properties): ilADTActiveRecord
209 {
210 return new ilADTActiveRecord($a_properties);
211 }
212
216 public static function initActiveRecordByType(): void
217 {
218 }
219
224 {
225 self::initActiveRecordByType();
226 return new ilADTActiveRecordByType($a_properties);
227 }
228}
ADT Active Record by type helper class This class expects a valid primary for all actions!
ADT Active Record helper class This class expects a valid primary for all actions!
ADT DB bridge base class.
ADT definition base class.
getType()
Get type (from class/instance)
Class ilADTFactory.
static getActiveRecordByTypeInstance(ilADTDBBridge $a_properties)
Get active record by type instance.
getSearchBridgeForDefinitionInstance(ilADTDefinition $a_adt_def, bool $a_range=true, bool $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 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.
isValidType(string $a_type)
initTypeClass(string $a_type, ?string $a_class=null)
getDefinitionInstanceByType(string $a_type)
Get instance of ADT definition.
static ilADTFactory $instance
static initActiveRecordByType()
Init active record by type.
getActiveRecordBridgeForInstance(ilADT $a_adt)
Get active record instance for ADT.
getInstanceByDefinition(ilADTDefinition $a_def)
Get instance of ADT.
ADT form bridge base class.
ADT presentation bridge base class.
ADT search bridge base class.
ADT base class.
Definition: class.ilADT.php:26
getType()
Get type (from class/instance)
Definition: class.ilADT.php:64
if(!file_exists('../ilias.ini.php'))