ILIAS  release_8 Revision v8.24
ilDclFieldFactory Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ 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 = "./Modules/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 = array()
 
static array $field_class_cache = array()
 
static array $field_representation_cache = array()
 
static array $record_representation_cache = array()
 
static array $field_model_cache = array()
 
static array $field_type_cache = array()
 
static array $class_path_cache = array()
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Member Function Documentation

◆ getClassByInstance()

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

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

238 : string
239 {
240 $fieldtype = self::getFieldTypeByInstance($field);
241
242 return self::getFieldClass($fieldtype, $class_pattern);
243 }
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 250 of file class.ilDclFieldFactory.php.

250 : string
251 {
252 global $DIC;
253 $datatype = $field->getDatatype();
254
255 if ($field->getId() != null && !empty(self::$class_path_cache[$field->getId()][$class_pattern])) {
256 return self::$class_path_cache[$field->getId()][$class_pattern];
257 }
258
259 if (ilDclFieldTypePlugin::isPluginDatatype($datatype->getTitle())) {
260 $plugin_id = ilDclFieldTypePlugin::getPluginId($datatype->getTitle());
261 if ($DIC["component.repository"]->hasActivatedPlugin($plugin_id)) {
262 $class_path = $DIC["component.repository"]->getPluginById($plugin_id)->getPath() . '/classes/';
263 } else {
264 return '';
265 }
266 } else {
267 $class_path = sprintf(
268 self::$field_base_path_patter,
269 ucfirst(self::parseDatatypeTitle($datatype->getTitle()))
270 );
271 }
272
273 $return = $class_path . self::getFieldClassFile(self::getFieldTypeByInstance($field), $class_pattern);
274
275 if ($field->getId() != null) {
276 self::$class_path_cache[$field->getId()][$class_pattern] = $return;
277 }
278
279 return $return;
280 }
static getFieldClassFile(string $datatype, string $class_pattern)
static isPluginDatatype(string $datatype)
static getPluginId(string $datatype)
global $DIC
Definition: feed.php:28

References $DIC, ilDclBaseFieldModel\getDatatype(), ilDclBaseFieldModel\getId(), ilDclFieldTypePlugin\getPluginId(), 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 68 of file class.ilDclFieldFactory.php.

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

Referenced by getFieldClassFile().

+ Here is the caller graph for this function:

◆ getFieldClassFile()

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

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

82 : string
83 {
84 return "class." . self::getFieldClass($datatype, $class_pattern) . ".php";
85 }

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 160 of file class.ilDclFieldFactory.php.

161 {
162 $base = new ilDclBaseFieldModel($field_id);
163 if ($datatype != null) {
164 $base->setDatatypeId($datatype);
165 }
166
167 $ilDclBaseFieldModel = self::getFieldModelInstanceByClass($base, $field_id);
168
169 return $ilDclBaseFieldModel;
170 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
$base
Definition: index.php:4

References $base.

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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getClassByInstance(ilDclBaseFieldModel $field, string $class_pattern)
static getClassPathByInstance(ilDclBaseFieldModel $field, string $class_pattern)

References ilDclBaseFieldModel\getId().

Referenced by ilDclCache\buildFieldFromRecord(), ilDclFieldEditGUI\checkInput(), 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 89 of file class.ilDclFieldFactory.php.

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

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

Referenced by ilDclSelectionFieldModel\getConfirmationGUI(), ilDclCache\getFieldRepresentation(), ilDclTableViewEditFieldsTableGUI\getStandardFilterHTML(), ilDclFieldEditGUI\initForm(), ilDclBaseFieldModel\storePropertiesFromForm(), and ilDclSelectionFieldModel\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 }
231 } else {
232 $fieldtype = self::$default_prefix . ucfirst(self::parseDatatypeTitle($datatype->getTitle()));
233 }
234 self::$field_type_cache[$datatype->getId()] = $fieldtype;
235 return $fieldtype;
236 }

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

+ Here is the call graph for this function:

◆ getPluginNameFromFieldModel()

static ilDclFieldFactory::getPluginNameFromFieldModel ( ilDclBaseFieldModel  $object)
static

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

304 : string
305 {
306 $class_name = get_class($object);
307 $class_name = substr($class_name, 2, -(strlen(self::$field_class_patter) - 2));
308
309 return $class_name;
310 }

◆ 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 36 of file class.ilDclFieldFactory.php.

37 {
38 if (!empty(self::$record_field_cache[$field->getId()][$record->getId()])) {
39 return self::$record_field_cache[$field->getId()][$record->getId()];
40 }
41
42 $path = self::getClassPathByInstance($field, self::$record_field_class_patter);
43 if (file_exists($path)) {
44 $class = self::getClassByInstance($field, self::$record_field_class_patter);
45 $instance = new $class($record, $field);
46 if ($instance instanceof ilDclBaseRecordFieldModel) {
47 if (!$instance->getFieldRepresentation()) {
48 $instance->setFieldRepresentation(self::getFieldRepresentationInstance($field));
49 }
50
51 if (!$instance->getRecordRepresentation()) {
52 $instance->setRecordRepresentation(self::getRecordRepresentationInstance($instance));
53 }
54 self::$record_field_cache[$field->getId()][$record->getId()] = $instance;
55
56 return $instance;
57 }
58 }
59
60 throw new RuntimeException("file not found " . $path);
61 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32

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 299 of file class.ilDclFieldFactory.php.

300 {
301 return new ilDclBaseRecordModel($record_id);
302 }

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 123 of file class.ilDclFieldFactory.php.

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

References ilDclBaseRecordFieldModel\getId().

+ Here is the call graph for this function:

◆ parseDatatypeTitle()

static ilDclFieldFactory::parseDatatypeTitle ( string  $title)
static

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

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

286 : string
287 {
288 $parts = explode("_", $title);
289 $func = function ($value) {
290 return ucfirst($value);
291 };
292
293 $parts = array_map($func, $parts);
294 $title = implode("", $parts);
295
296 return $title;
297 }
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64

References $parts.

Field Documentation

◆ $class_path_cache

array ilDclFieldFactory::$class_path_cache = array()
staticprotected

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

◆ $default_prefix

string ilDclFieldFactory::$default_prefix = "ilDcl"
static

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

◆ $field_base_path_patter

string ilDclFieldFactory::$field_base_path_patter = "./Modules/DataCollection/classes/Fields/%s/"
static

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

◆ $field_class_cache

array ilDclFieldFactory::$field_class_cache = array()
staticprotected

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

◆ $field_class_patter

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

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

◆ $field_model_cache

array ilDclFieldFactory::$field_model_cache = array()
staticprotected

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

◆ $field_representation_cache

array ilDclFieldFactory::$field_representation_cache = array()
staticprotected

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

◆ $field_representation_class_pattern

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

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

◆ $field_type_cache

array ilDclFieldFactory::$field_type_cache = array()
staticprotected

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

◆ $record_field_cache

array ilDclFieldFactory::$record_field_cache = array()
staticprotected

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

◆ $record_field_class_patter

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

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

◆ $record_representation_cache

array ilDclFieldFactory::$record_representation_cache = array()
staticprotected

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

◆ $record_representation_class_pattern

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

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


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