ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilDclFieldFactory Class Reference
+ Collaboration diagram for ilDclFieldFactory:

Static Public Member Functions

static getRecordFieldInstance (object $field, object $record)
 Creates a RecordField instance and loads the field and record representation. More...
 
static getFieldClass (string $datatype, string $class_pattern)
 Concatenates Classname from datatype and pattern. More...
 
static getFieldClassFile (string $datatype, string $class_pattern)
 
static getFieldRepresentationInstance (ilDclBaseFieldModel $field)
 
static getRecordRepresentationInstance (ilDclBaseRecordFieldModel $record_field)
 Get RecordRepresentation from RecordFieldModel. More...
 
static getFieldModelInstance (int $field_id, ?int $datatype=null)
 Get FieldModel from field-id and datatype. More...
 
static getFieldModelInstanceByClass (ilDclBaseFieldModel $field, ?int $field_id=null)
 Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldModel with the necessary class. More...
 
static getFieldTypeByInstance (ilDclBaseFieldModel $field)
 
static getClassByInstance (ilDclBaseFieldModel $field, string $class_pattern)
 
static getClassPathByInstance (ilDclBaseFieldModel $field, string $class_pattern)
 
static parseDatatypeTitle (string $title)
 Parse string to FieldClass format Replaces _ with camelcase-notation. More...
 
static getRecordModelInstance (?int $record_id)
 
static getPluginNameFromFieldModel (ilDclBaseFieldModel $object)
 

Static Public Attributes

static string $field_base_path_patter = ILIAS_ABSOLUTE_PATH . "/components/ILIAS/DataCollection/classes/Fields/%s/"
 
static string $default_prefix = "ilDcl"
 
static string $record_field_class_patter = "%sRecordFieldModel"
 
static string $field_class_patter = "%sFieldModel"
 
static string $record_representation_class_pattern = "%sRecordRepresentation"
 
static string $field_representation_class_pattern = "%sFieldRepresentation"
 

Static Protected Attributes

static array $record_field_cache = []
 
static array $field_class_cache = []
 
static array $field_representation_cache = []
 
static array $record_representation_cache = []
 
static array $field_model_cache = []
 
static array $field_type_cache = []
 
static array $class_path_cache = []
 

Detailed Description

Definition at line 21 of file class.ilDclFieldFactory.php.

Member Function Documentation

◆ getClassByInstance()

static ilDclFieldFactory::getClassByInstance ( ilDclBaseFieldModel  $field,
string  $class_pattern 
)
static

Definition at line 243 of file class.ilDclFieldFactory.php.

243 : string
244 {
245 $fieldtype = self::getFieldTypeByInstance($field);
246
247 return self::getFieldClass($fieldtype, $class_pattern);
248 }
static getFieldClass(string $datatype, string $class_pattern)
Concatenates Classname from datatype and pattern.
static getFieldTypeByInstance(ilDclBaseFieldModel $field)

Referenced by getFieldRepresentationInstance(), and getRecordFieldInstance().

+ Here is the caller graph for this function:

◆ getClassPathByInstance()

static ilDclFieldFactory::getClassPathByInstance ( ilDclBaseFieldModel  $field,
string  $class_pattern 
)
static
Exceptions
ilDclException

Definition at line 255 of file class.ilDclFieldFactory.php.

255 : string
256 {
257 global $DIC;
258 $datatype = $field->getDatatype();
259
260 if ($field->getId() != null && !empty(self::$class_path_cache[$field->getId()][$class_pattern])) {
261 return self::$class_path_cache[$field->getId()][$class_pattern];
262 }
263
264 if (ilDclFieldTypePlugin::isPluginDatatype($datatype->getTitle())) {
265 $plugin_id = ilDclFieldTypePlugin::getPluginId($datatype->getTitle());
266 if ($DIC["component.repository"]->hasActivatedPlugin($plugin_id)) {
267 $class_path = $DIC["component.repository"]->getPluginById($plugin_id)->getPath() . '/classes/';
268 } else {
269 return '';
270 }
272 // This is for legacy reasons. The fileupload field was replaced with ilDclDatatype::INPUTFORMAT_FILE in
273 // ILIAS 9, but must be available for one more release, since there might be records with this field type
274 // which have not et been migrated.
275 $class_path = sprintf(
276 self::$field_base_path_patter,
277 ucfirst(self::parseDatatypeTitle('Fileupload'))
278 );
279
280 $class_name = sprintf(
281 'class.' . self::$default_prefix . '%s.php',
282 sprintf(
283 $class_pattern,
284 ucfirst('Fileupload'),
285 )
286 );
287
288 $return = $class_path . $class_name;
289 if ($field->getId() != null) {
290 self::$class_path_cache[$field->getId()][$class_pattern] = $return;
291 }
292
293 return $return;
294 } else {
295 $class_path = sprintf(
296 self::$field_base_path_patter,
297 ucfirst(self::parseDatatypeTitle($datatype->getTitle()))
298 );
299 }
300
301 $return = $class_path . self::getFieldClassFile(self::getFieldTypeByInstance($field), $class_pattern);
302
303 if ($field->getId() != null) {
304 self::$class_path_cache[$field->getId()][$class_pattern] = $return;
305 }
306
307 return $return;
308 }
static getFieldClassFile(string $datatype, string $class_pattern)
static isPluginDatatype(string $datatype)
static getPluginId(string $datatype)
global $DIC
Definition: shib_login.php:26

References $DIC, ilDclBaseFieldModel\getDatatype(), ilDclBaseFieldModel\getDatatypeId(), ilDclBaseFieldModel\getId(), ilDclFieldTypePlugin\getPluginId(), ilDclDatatype\INPUTFORMAT_FILEUPLOAD, and ilDclFieldTypePlugin\isPluginDatatype().

Referenced by getFieldRepresentationInstance(), and getRecordFieldInstance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldClass()

static ilDclFieldFactory::getFieldClass ( string  $datatype,
string  $class_pattern 
)
static

Concatenates Classname from datatype and pattern.

Definition at line 72 of file class.ilDclFieldFactory.php.

72 : string
73 {
74 if (!empty(self::$field_class_cache[$datatype . $class_pattern])) {
75 return self::$field_class_cache[$datatype . $class_pattern];
76 }
77
78 $fieldtype = $datatype;
79
80 $class = sprintf($class_pattern, $fieldtype);
81 self::$field_class_cache[$datatype . $class_pattern] = $class;
82
83 return $class;
84 }

Referenced by getFieldClassFile().

+ Here is the caller graph for this function:

◆ getFieldClassFile()

static ilDclFieldFactory::getFieldClassFile ( string  $datatype,
string  $class_pattern 
)
static

Definition at line 86 of file class.ilDclFieldFactory.php.

86 : string
87 {
88 return "class." . self::getFieldClass($datatype, $class_pattern) . ".php";
89 }

References getFieldClass().

+ Here is the call graph for this function:

◆ getFieldModelInstance()

static ilDclFieldFactory::getFieldModelInstance ( int  $field_id,
?int  $datatype = null 
)
static

Get FieldModel from field-id and datatype.

Exceptions
ilDclException

Definition at line 162 of file class.ilDclFieldFactory.php.

163 {
164 $base = new ilDclBaseFieldModel($field_id);
165 if ($datatype != null) {
166 $base->setDatatypeId($datatype);
167 }
168
169 return self::getFieldModelInstanceByClass($base, $field_id);
170 }
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, ?int $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...

Referenced by ilDclFieldEditGUI\__construct(), and ilDclCache\getFieldCache().

+ Here is the caller graph for this function:

◆ getFieldModelInstanceByClass()

static ilDclFieldFactory::getFieldModelInstanceByClass ( ilDclBaseFieldModel  $field,
?int  $field_id = null 
)
static

Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldModel with the necessary class.

Exceptions
ilDclException

Definition at line 179 of file class.ilDclFieldFactory.php.

183 if ($field->getId() != null && !empty(self::$field_model_cache[$field->getId()])) {
184 return self::$field_model_cache[$field->getId()];
185 }
186
187 $path_type = self::getClassPathByInstance($field, self::$field_class_patter);
188
189 if (file_exists($path_type)) {
190 $class = self::getClassByInstance($field, self::$field_class_patter);
191 } else {
192 $class = self::getFieldClass(self::$default_prefix . "Base", self::$field_class_patter);
193 }
194
195 if ($field_id) {
196 $instance = new $class($field_id);
197 } else {
198 $instance = new $class();
199 }
200
201 if ($instance == null) {
202 throw new ilDclException("Could not create FieldModel of " . $class);
203 }
204 $instance->setDatatypeId($field->getDatatypeId());
205
206 if ($field->getId() != null) {
207 self::$field_model_cache[$field->getId()] = $instance;
208 }
209
210 return $instance;
211 }
static getClassByInstance(ilDclBaseFieldModel $field, string $class_pattern)
static getClassPathByInstance(ilDclBaseFieldModel $field, string $class_pattern)

References ilDclBaseFieldModel\getId().

Referenced by ilDclCache\buildFieldFromRecord(), and ilDclFieldEditGUI\initForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldRepresentationInstance()

static ilDclFieldFactory::getFieldRepresentationInstance ( ilDclBaseFieldModel  $field)
static

Definition at line 93 of file class.ilDclFieldFactory.php.

94 {
95 // when the datatype overview is generated no field-models are available, so an empty instance is used => no caching there
96 if (!empty($field->getId()) && !empty(self::$field_representation_cache[$field->getId()])) {
97 return self::$field_representation_cache[$field->getId()];
98 }
99
100 $class_path = self::getClassPathByInstance($field, self::$field_representation_class_pattern);
101
102 if (file_exists($class_path)) {
103 $class = self::getClassByInstance($field, self::$field_representation_class_pattern);
104 $instance = new $class($field);
105 } else {
106 throw new ilDclException("Path for FieldRepresentation with file " . $class_path . " does not exists!");
107 }
108
109 if ($instance == null) {
110 throw new ilDclException("Could not create FieldRepresentation of " . $class . " with file " . $class_path);
111 }
112
113 if ($field->getId() != null) {
114 self::$field_representation_cache[$field->getId()] = $instance;
115 }
116
117 return $instance;
118 }

References getClassByInstance(), getClassPathByInstance(), and ilDclBaseFieldModel\getId().

Referenced by ilDclCache\getFieldRepresentation(), ilDclTableViewEditFieldsTableGUI\getStandardFilterHTML(), ilDclFieldEditGUI\initForm(), and ilDclBaseFieldModel\storePropertiesFromForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldTypeByInstance()

static ilDclFieldFactory::getFieldTypeByInstance ( ilDclBaseFieldModel  $field)
static

Definition at line 215 of file class.ilDclFieldFactory.php.

215 : string
216 {
217 global $DIC;
218 $datatype = $field->getDatatype();
219
220 if (!empty(self::$field_type_cache[$datatype->getId()])) {
221 return self::$field_type_cache[$datatype->getId()];
222 }
223
224 if (ilDclFieldTypePlugin::isPluginDatatype($datatype->getTitle())) {
225 $plugin_id = ilDclFieldTypePlugin::getPluginId($datatype->getTitle());
226 if ($DIC["component.repository"]->hasActivatedPlugin($plugin_id)) {
227 $fieldtype = 'il' . $DIC["component.repository"]->getPluginById($plugin_id)->getName();
228 } else {
229 $fieldtype = '';
230 }
232 // This is for legacy reasons. The fileupload field was replaced with ilDclDatatype::INPUTFORMAT_FILE in
233 // ILIAS 9, but must be available for one more release, since there might be records with this field type
234 // which have not et been migrated.
235 $fieldtype = self::$default_prefix . ucfirst('Fileupload');
236 } else {
237 $fieldtype = self::$default_prefix . ucfirst(self::parseDatatypeTitle($datatype->getTitle()));
238 }
239 self::$field_type_cache[$datatype->getId()] = $fieldtype;
240 return $fieldtype;
241 }

References $DIC, ilDclBaseFieldModel\getDatatype(), ilDclBaseFieldModel\getDatatypeId(), ilDclFieldTypePlugin\getPluginId(), ilDclDatatype\INPUTFORMAT_FILEUPLOAD, and ilDclFieldTypePlugin\isPluginDatatype().

+ Here is the call graph for this function:

◆ getPluginNameFromFieldModel()

static ilDclFieldFactory::getPluginNameFromFieldModel ( ilDclBaseFieldModel  $object)
static

Definition at line 330 of file class.ilDclFieldFactory.php.

330 : string
331 {
332 $class_name = get_class($object);
333 return substr($class_name, 2, -(strlen(self::$field_class_patter) - 2));
334 }

◆ getRecordFieldInstance()

static ilDclFieldFactory::getRecordFieldInstance ( object  $field,
object  $record 
)
static

Creates a RecordField instance and loads the field and record representation.

Parameters
object | ilDclBaseFieldModel$field
object | ilDclBaseRecordModel$record
Exceptions
ilDclException
Exception

Definition at line 38 of file class.ilDclFieldFactory.php.

39 {
40 if (!empty(self::$record_field_cache[$field->getId()][$record->getId()])) {
41 return self::$record_field_cache[$field->getId()][$record->getId()];
42 }
43
44 $path = self::getClassPathByInstance($field, self::$record_field_class_patter);
45 if (file_exists($path)) {
46 $class = self::getClassByInstance($field, self::$record_field_class_patter);
47 $instance = new $class($record, $field);
48 if ($instance instanceof ilDclBaseRecordFieldModel) {
49 if (!$instance->getFieldRepresentation()) {
50 $instance->setFieldRepresentation(self::getFieldRepresentationInstance($field));
51 }
52
53 if (!$instance->getRecordRepresentation()) {
54 $instance->setRecordRepresentation(self::getRecordRepresentationInstance($instance));
55 }
56 self::$record_field_cache[$field->getId()][$record->getId()] = $instance;
57
58 return $instance;
59 }
60
61 throw new RuntimeException("instance is no base field " . $instance->getField()->getTitle());
62 }
63
64 throw new RuntimeException("file not found " . $path);
65 }
$path
Definition: ltiservices.php:30

References $path, getClassByInstance(), and getClassPathByInstance().

Referenced by ilDclCache\getRecordFieldCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecordModelInstance()

static ilDclFieldFactory::getRecordModelInstance ( ?int  $record_id)
static

Definition at line 325 of file class.ilDclFieldFactory.php.

326 {
327 return new ilDclBaseRecordModel($record_id);
328 }

Referenced by ilDclCache\getRecordCache().

+ Here is the caller graph for this function:

◆ getRecordRepresentationInstance()

static ilDclFieldFactory::getRecordRepresentationInstance ( ilDclBaseRecordFieldModel  $record_field)
static

Get RecordRepresentation from RecordFieldModel.

Exceptions
ilDclException

Definition at line 126 of file class.ilDclFieldFactory.php.

129 // there are some field types which have no recordFieldModel object (e.g rating) => no caching
130 if ($record_field->getId() != null && !empty(self::$record_representation_cache[$record_field->getId()])) {
131 return self::$record_representation_cache[$record_field->getId()];
132 }
133
134 $class_path = self::getClassPathByInstance(
135 $record_field->getField(),
136 self::$record_representation_class_pattern
137 );
138
139 if (file_exists($class_path)) {
140 $class = self::getClassByInstance($record_field->getField(), self::$record_representation_class_pattern);
141 } else {
142 $class = self::getFieldClass(self::$default_prefix . "Base", self::$record_representation_class_pattern);
143 }
144
145 $instance = new $class($record_field);
146
147 if ($instance == null) {
148 throw new ilDclException("Could not create RecordRepresentation of " . $class_path . " " . $record_field->getField()->getDatatype()->getTitle());
149 }
150
151 if ($record_field->getId() != null) {
152 self::$record_representation_cache[$record_field->getId()] = $instance;
153 }
154
155 return $instance;
156 }

References ilDclBaseRecordFieldModel\getId().

Referenced by ilDclCache\getRecordRepresentation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseDatatypeTitle()

static ilDclFieldFactory::parseDatatypeTitle ( string  $title)
static

Parse string to FieldClass format Replaces _ with camelcase-notation.

Definition at line 314 of file class.ilDclFieldFactory.php.

314 : string
315 {
316 $parts = explode("_", $title);
317 $func = function ($value) {
318 return ucfirst($value);
319 };
320
321 $parts = array_map($func, $parts);
322 return implode("", $parts);
323 }
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61

References $parts.

Field Documentation

◆ $class_path_cache

array ilDclFieldFactory::$class_path_cache = []
staticprotected

Definition at line 250 of file class.ilDclFieldFactory.php.

◆ $default_prefix

string ilDclFieldFactory::$default_prefix = "ilDcl"
static

Definition at line 24 of file class.ilDclFieldFactory.php.

◆ $field_base_path_patter

string ilDclFieldFactory::$field_base_path_patter = ILIAS_ABSOLUTE_PATH . "/components/ILIAS/DataCollection/classes/Fields/%s/"
static

Definition at line 23 of file class.ilDclFieldFactory.php.

◆ $field_class_cache

array ilDclFieldFactory::$field_class_cache = []
staticprotected

Definition at line 67 of file class.ilDclFieldFactory.php.

◆ $field_class_patter

string ilDclFieldFactory::$field_class_patter = "%sFieldModel"
static

Definition at line 26 of file class.ilDclFieldFactory.php.

◆ $field_model_cache

array ilDclFieldFactory::$field_model_cache = []
staticprotected

Definition at line 172 of file class.ilDclFieldFactory.php.

◆ $field_representation_cache

array ilDclFieldFactory::$field_representation_cache = []
staticprotected

Definition at line 91 of file class.ilDclFieldFactory.php.

◆ $field_representation_class_pattern

string ilDclFieldFactory::$field_representation_class_pattern = "%sFieldRepresentation"
static

Definition at line 28 of file class.ilDclFieldFactory.php.

◆ $field_type_cache

array ilDclFieldFactory::$field_type_cache = []
staticprotected

Definition at line 213 of file class.ilDclFieldFactory.php.

◆ $record_field_cache

array ilDclFieldFactory::$record_field_cache = []
staticprotected

Definition at line 29 of file class.ilDclFieldFactory.php.

◆ $record_field_class_patter

string ilDclFieldFactory::$record_field_class_patter = "%sRecordFieldModel"
static

Definition at line 25 of file class.ilDclFieldFactory.php.

◆ $record_representation_cache

array ilDclFieldFactory::$record_representation_cache = []
staticprotected

Definition at line 120 of file class.ilDclFieldFactory.php.

◆ $record_representation_class_pattern

string ilDclFieldFactory::$record_representation_class_pattern = "%sRecordRepresentation"
static

Definition at line 27 of file class.ilDclFieldFactory.php.


The documentation for this class was generated from the following file: