ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDclFieldFactory Class Reference

Class ilDclFieldFactory This Class handles the creation of all field-classes. More...

+ Collaboration diagram for ilDclFieldFactory:

Static Public Member Functions

static getRecordFieldInstance (ilDclBaseFieldModel $field, ilDclBaseRecordModel $record)
 Creates a RecordField instance and loads the field and record representation. More...
 
static getFieldClass ($datatype, $class_pattern)
 Concatenates Classname from datatype and pattern. More...
 
static getFieldClassFile ($datatype, $class_pattern)
 Get Filename from datatype and pattern. More...
 
static getFieldRepresentationInstance (ilDclBaseFieldModel $field)
 Returns FieldRepresentation from BaseFieldModel. More...
 
static getRecordRepresentationInstance (ilDclBaseRecordFieldModel $record_field)
 Get RecordRepresentation from RecordFieldModel. More...
 
static getFieldModelInstance ($field_id, $datatype=null)
 Get FieldModel from field-id and datatype. More...
 
static getFieldModelInstanceByClass (ilDclBaseFieldModel $field, $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, $class_pattern)
 
static getClassPathByInstance (ilDclBaseFieldModel $field, $class_pattern)
 
static parseDatatypeTitle ($title)
 Parse string to FieldClass format Replaces _ with camelcase-notation. More...
 
static getRecordModelInstance ($record_id)
 Creates a RecordModel instance. More...
 
static getPluginNameFromFieldModel (ilDclBaseFieldModel $object)
 Get plugin-name from FieldModel. More...
 

Static Public Attributes

static $field_base_path_patter = "./Modules/DataCollection/classes/Fields/%s/"
 
static $default_prefix = "ilDcl"
 
static $record_field_class_patter = "%sRecordFieldModel"
 
static $field_class_patter = "%sFieldModel"
 
static $record_class_patter = "%sRecordModel"
 
static $record_representation_class_pattern = "%sRecordRepresentation"
 
static $field_representation_class_pattern = "%sFieldRepresentation"
 

Static Protected Attributes

static $record_field_cache = array()
 
static $field_class_cache = array()
 
static $field_representation_cache = array()
 
static $record_representation_cache = array()
 
static $field_model_cache = array()
 
static $field_type_cache = array()
 
static $class_path_cache = array()
 

Detailed Description

Class ilDclFieldFactory This Class handles the creation of all field-classes.

Author
Michael Herren mh@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

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

Member Function Documentation

◆ getClassByInstance()

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

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

330 {
331 $fieldtype = self::getFieldTypeByInstance($field);
332
333 return self::getFieldClass($fieldtype, $class_pattern);
334 }
static getFieldClass($datatype, $class_pattern)
Concatenates Classname from datatype and pattern.
static getFieldTypeByInstance(ilDclBaseFieldModel $field)

References getFieldClass(), and getFieldTypeByInstance().

Referenced by getFieldModelInstanceByClass(), getFieldRepresentationInstance(), getRecordFieldInstance(), and getRecordRepresentationInstance().

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

◆ getClassPathByInstance()

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

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

350 {
351 $datatype = $field->getDatatype();
352
353 if ($field->getId() != null && !empty(self::$class_path_cache[$field->getId()][$class_pattern])) {
354 return self::$class_path_cache[$field->getId()][$class_pattern];
355 }
356
357 if ($datatype->getId() == ilDclDatatype::INPUTFORMAT_PLUGIN) {
360 if ($plugin_data == null) {
361 throw new ilDclException("Something went wrong by initializing the FieldHook-Plugin '"
362 . $field->getProperty(ilDclBaseFieldModel::PROP_PLUGIN_HOOK_NAME) . "' on Component '"
363 . ilDclFieldTypePlugin::COMPONENT_NAME . "' with slot '" . ilDclFieldTypePlugin::SLOT_ID . "' on field: "
364 . $field->getTitle());
365 }
366
367 $class_path = $plugin_data->getDirectory() . "/classes/";
368 } else {
369 $class_path = sprintf(self::$field_base_path_patter, ucfirst(self::parseDatatypeTitle($datatype->getTitle())));
370 }
371 } else {
372 $class_path = sprintf(self::$field_base_path_patter, ucfirst(self::parseDatatypeTitle($datatype->getTitle())));
373 }
374
375 $return = $class_path . self::getFieldClassFile(self::getFieldTypeByInstance($field), $class_pattern);
376
377 if($field->getId() != null) {
378 self::$class_path_cache[$field->getId()][$class_pattern] = $return;
379 }
380
381 return $return;
382 }
sprintf('%.4f', $callTime)
const IL_COMP_MODULE
hasProperty($key)
Checks if a certain property for a field is set.
getProperty($key)
Returns a certain property of a field.
Class ilDclException.
static getFieldClassFile($datatype, $class_pattern)
Get Filename from datatype and pattern.
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get plugin object.

References ilDclFieldTypePlugin\COMPONENT_NAME, ilDclBaseFieldModel\getDatatype(), getFieldClassFile(), ilDclBaseFieldModel\getId(), ilPlugin\getPluginObject(), ilDclBaseFieldModel\getProperty(), ilDclBaseFieldModel\getTitle(), ilDclBaseFieldModel\hasProperty(), IL_COMP_MODULE, ilDclDatatype\INPUTFORMAT_PLUGIN, ilDclBaseFieldModel\PROP_PLUGIN_HOOK_NAME, ilDclFieldTypePlugin\SLOT_ID, and sprintf.

Referenced by getFieldModelInstanceByClass(), getFieldRepresentationInstance(), getRecordFieldInstance(), and getRecordRepresentationInstance().

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

◆ getFieldClass()

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

Concatenates Classname from datatype and pattern.

Parameters
$datatype
$class_pattern
Returns
string

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

99 {
100 if (!empty(self::$field_class_cache[$datatype . $class_pattern])) {
101 return self::$field_class_cache[$datatype . $class_pattern];
102 }
103
104 $fieldtype = $datatype;
105
106 $class = sprintf($class_pattern, $fieldtype);
107 self::$field_class_cache[$datatype . $class_pattern] = $class;
108
109 return $class;
110 }

References sprintf.

Referenced by getClassByInstance(), getFieldClassFile(), getFieldModelInstanceByClass(), and getRecordRepresentationInstance().

+ Here is the caller graph for this function:

◆ getFieldClassFile()

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

Get Filename from datatype and pattern.

Parameters
$datatype
$class_pattern
Returns
string

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

121 {
122 return "class." . self::getFieldClass($datatype, $class_pattern) . ".php";
123 }

References getFieldClass().

Referenced by getClassPathByInstance().

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

◆ getFieldModelInstance()

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

Get FieldModel from field-id and datatype.

Parameters
$field_id
null$datatype
Returns
mixed
Exceptions
ilDclException

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

222 {
223 $base = new ilDclBaseFieldModel($field_id);
224 if ($datatype != null) {
225 $base->setDatatypeId($datatype);
226 }
227
228 $ilDclBaseFieldModel = self::getFieldModelInstanceByClass($base, $field_id);
229
230 return $ilDclBaseFieldModel;
231 }
Class ilDclBaseFieldModel.
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...

References getFieldModelInstanceByClass().

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

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

◆ getFieldModelInstanceByClass()

static ilDclFieldFactory::getFieldModelInstanceByClass ( ilDclBaseFieldModel  $field,
  $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.

Parameters
ilDclBaseFieldModel$field
null$field_id
Returns
ilDclBaseFieldModel
Exceptions
ilDclException

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

250 {
251 if ($field->getId() != null && !empty(self::$field_model_cache[$field->getId()])) {
252 return self::$field_model_cache[$field->getId()];
253 }
254
255 $path_type = self::getClassPathByInstance($field, self::$field_class_patter);
256
257 if (file_exists($path_type)) {
258 require_once($path_type);
259 $class = self::getClassByInstance($field, self::$field_class_patter);
260 } else {
261 $class = self::getFieldClass(self::$default_prefix . "Base", self::$field_class_patter);
262 }
263
264 if ($field_id) {
265 $instance = new $class($field_id);
266 } else {
267 $instance = new $class();
268 }
269
270 if ($instance == null) {
271 throw new ilDclException("Could not create FieldModel of " . $class);
272 }
273
274 if($field->getId() != null) {
275 self::$field_model_cache[$field->getId()] = $instance;
276 }
277
278 return $instance;
279 }
static getClassByInstance(ilDclBaseFieldModel $field, $class_pattern)
static getClassPathByInstance(ilDclBaseFieldModel $field, $class_pattern)

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

Referenced by ilDclCache\buildFieldFromRecord(), ilDclFieldEditGUI\checkInput(), and getFieldModelInstance().

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

◆ getFieldRepresentationInstance()

static ilDclFieldFactory::getFieldRepresentationInstance ( ilDclBaseFieldModel  $field)
static

Returns FieldRepresentation from BaseFieldModel.

Parameters
ilDclBaseFieldModel$field
Returns
ilDclBaseFieldRepresentation
Exceptions
ilDclException

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

140 {
141 // when the datatype overview is generated no field-models are available, so an empty instance is used => no caching there
142 if ($field->getId() != null && !empty(self::$field_representation_cache[$field->getId()])) {
143 return self::$field_representation_cache[$field->getId()];
144 }
145
146 $class_path = self::getClassPathByInstance($field, self::$field_representation_class_pattern);
147
148 $instance = null;
149 if (file_exists($class_path)) {
150 require_once($class_path);
151 $class = self::getClassByInstance($field, self::$field_representation_class_pattern);
152 $instance = new $class($field);
153 } else {
154 throw new ilDclException("Path for FieldRepresentation with file " . $class_path . " does not exists!");
155 }
156
157 if ($instance == null) {
158 throw new ilDclException("Could not create FieldRepresentation of " . $class . " with file " . $class_path);
159 }
160
161 if($field->getId() != null) {
162 self::$field_representation_cache[$field->getId()] = $instance;
163 }
164
165 return $instance;
166 }

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

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

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

◆ getFieldTypeByInstance()

static ilDclFieldFactory::getFieldTypeByInstance ( ilDclBaseFieldModel  $field)
static
Parameters
ilDclBaseFieldModel$field
Returns
string

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

294 {
295 $datatype = $field->getDatatype();
296
297 if (!empty(self::$field_type_cache[$datatype->getId()])) {
298 if($datatype->getId() == ilDclDatatype::INPUTFORMAT_PLUGIN) {
299 if(!empty(self::$field_type_cache[$datatype->getId()][$field->getId()])) {
300 return self::$field_type_cache[$datatype->getId()][$field->getId()];
301 }
302 } else {
303 return self::$field_type_cache[$datatype->getId()];
304 }
305 }
306
307 if ($datatype->getId() == ilDclDatatype::INPUTFORMAT_PLUGIN) {
310 $fieldtype = $plugin_data->getPluginClassPrefix() . ucfirst($plugin_data->getPluginName());
311 } else {
312 $fieldtype = self::$default_prefix . ucfirst(self::parseDatatypeTitle($datatype->getTitle()));
313 }
314 self::$field_type_cache[$datatype->getId()][$field->getId()] = $fieldtype;
315 } else {
316 $fieldtype = self::$default_prefix . ucfirst(self::parseDatatypeTitle($datatype->getTitle()));
317 self::$field_type_cache[$datatype->getId()] = $fieldtype;
318 }
319
320 return $fieldtype;
321 }

References ilDclFieldTypePlugin\COMPONENT_NAME, ilDclBaseFieldModel\getDatatype(), ilDclBaseFieldModel\getId(), ilPlugin\getPluginObject(), ilDclBaseFieldModel\getProperty(), ilDclBaseFieldModel\hasProperty(), IL_COMP_MODULE, ilDclDatatype\INPUTFORMAT_PLUGIN, ilDclBaseFieldModel\PROP_PLUGIN_HOOK_NAME, and ilDclFieldTypePlugin\SLOT_ID.

Referenced by getClassByInstance().

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

◆ getPluginNameFromFieldModel()

static ilDclFieldFactory::getPluginNameFromFieldModel ( ilDclBaseFieldModel  $object)
static

Get plugin-name from FieldModel.

Parameters
ilDclBaseFieldModel$object
Returns
string

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

425 {
426 $class_name = get_class($object);
427 $class_name = substr($class_name, 2, - (strlen(self::$field_class_patter) - 2));
428
429 return $class_name;
430 }

Referenced by ilDclBaseFieldRepresentation\addFieldCreationForm().

+ Here is the caller graph for this function:

◆ getRecordFieldInstance()

static ilDclFieldFactory::getRecordFieldInstance ( ilDclBaseFieldModel  $field,
ilDclBaseRecordModel  $record 
)
static

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

Parameters
ilDclBaseFieldModel$field
ilDclBaseRecordModel$record
Returns
mixed
Exceptions
ilDclException

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

59 {
60 if (!empty(self::$record_field_cache[$field->getId()][$record->getId()])) {
61 return self::$record_field_cache[$field->getId()][$record->getId()];
62 }
63
64 $path = self::getClassPathByInstance($field, self::$record_field_class_patter);
65 if (file_exists($path)) {
66 require_once($path);
67 $class = self::getClassByInstance($field, self::$record_field_class_patter);
68 $instance = new $class($record, $field);
69 if ($instance instanceof ilDclBaseRecordFieldModel) {
70 if (!$instance->getFieldRepresentation()) {
71 $instance->setFieldRepresentation(self::getFieldRepresentationInstance($field));
72 }
73
74 if (!$instance->getRecordRepresentation()) {
75 $instance->setRecordRepresentation(self::getRecordRepresentationInstance($instance));
76 }
77 self::$record_field_cache[$field->getId()][$record->getId()] = $instance;
78
79 return $instance;
80 }
81 }
82 }
$path
Definition: aliased.php:25

References $path, getClassByInstance(), getClassPathByInstance(), ilDclBaseFieldModel\getId(), and ilDclBaseRecordModel\getId().

Referenced by ilDclCache\getRecordFieldCache().

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

◆ getRecordModelInstance()

static ilDclFieldFactory::getRecordModelInstance (   $record_id)
static

Creates a RecordModel instance.

Parameters
$record_id
Returns
ilDclBaseRecordModel

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

413 {
414 return new ilDclBaseRecordModel($record_id);
415 }
Class ilDclBaseRecordModel.

Referenced by ilDclCache\getRecordCache().

+ Here is the caller graph for this function:

◆ getRecordRepresentationInstance()

static ilDclFieldFactory::getRecordRepresentationInstance ( ilDclBaseRecordFieldModel  $record_field)
static

Get RecordRepresentation from RecordFieldModel.

Parameters
ilDclBaseRecordFieldModel$record_field
Returns
ilDclBaseRecordRepresentation
Exceptions
ilDclException

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

183 {
184 // there are some field types which have no recordFieldModel object (e.g rating) => no caching
185 if ($record_field->getId() != null && !empty(self::$record_representation_cache[$record_field->getId()])) {
186 return self::$record_representation_cache[$record_field->getId()];
187 }
188
189 $class_path = self::getClassPathByInstance($record_field->getField(), self::$record_representation_class_pattern);
190 $instance = null;
191
192 if (file_exists($class_path)) {
193 require_once($class_path);
194 $class = self::getClassByInstance($record_field->getField(), self::$record_representation_class_pattern);
195 } else {
196 $class = self::getFieldClass(self::$default_prefix . "Base", self::$record_representation_class_pattern);
197 }
198
199 $instance = new $class($record_field);
200
201 if ($instance == null) {
202 throw new ilDclException("Could not create RecordRepresentation of " . $class_path . " " . $record_field->getField()->getDatatype()->getTitle());
203 }
204
205 if($record_field->getId() != null) {
206 self::$record_representation_cache[$record_field->getId()] = $instance;
207 }
208
209 return $instance;
210 }

References getClassByInstance(), getClassPathByInstance(), ilDclBaseRecordFieldModel\getField(), getFieldClass(), and 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 (   $title)
static

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

Parameters
$title
Returns
string

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

393 {
394 $parts = explode("_", $title);
395 $func = function ($value) {
396 return ucfirst($value);
397 };
398
399 $parts = array_map($func, $parts);
400 $title = implode("", $parts);
401
402 return $title;
403 }

References $title.

Field Documentation

◆ $class_path_cache

ilDclFieldFactory::$class_path_cache = array()
staticprotected

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

◆ $default_prefix

ilDclFieldFactory::$default_prefix = "ilDcl"
static

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

◆ $field_base_path_patter

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

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

◆ $field_class_cache

ilDclFieldFactory::$field_class_cache = array()
staticprotected

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

◆ $field_class_patter

ilDclFieldFactory::$field_class_patter = "%sFieldModel"
static

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

◆ $field_model_cache

ilDclFieldFactory::$field_model_cache = array()
staticprotected

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

◆ $field_representation_cache

ilDclFieldFactory::$field_representation_cache = array()
staticprotected

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

◆ $field_representation_class_pattern

ilDclFieldFactory::$field_representation_class_pattern = "%sFieldRepresentation"
static

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

◆ $field_type_cache

ilDclFieldFactory::$field_type_cache = array()
staticprotected

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

◆ $record_class_patter

ilDclFieldFactory::$record_class_patter = "%sRecordModel"
static

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

◆ $record_field_cache

ilDclFieldFactory::$record_field_cache = array()
staticprotected

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

◆ $record_field_class_patter

ilDclFieldFactory::$record_field_class_patter = "%sRecordFieldModel"
static

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

◆ $record_representation_cache

ilDclFieldFactory::$record_representation_cache = array()
staticprotected

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

◆ $record_representation_class_pattern

ilDclFieldFactory::$record_representation_class_pattern = "%sRecordRepresentation"
static

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


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