19 declare(strict_types=1);
40 if (!empty(self::$record_field_cache[$field->getId()][$record->getId()])) {
41 return self::$record_field_cache[$field->getId()][$record->getId()];
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);
49 if (!$instance->getFieldRepresentation()) {
50 $instance->setFieldRepresentation(self::getFieldRepresentationInstance($field));
53 if (!$instance->getRecordRepresentation()) {
54 $instance->setRecordRepresentation(self::getRecordRepresentationInstance($instance));
56 self::$record_field_cache[$field->getId()][$record->getId()] = $instance;
70 public static function getFieldClass(
string $datatype,
string $class_pattern): string
72 if (!empty(self::$field_class_cache[$datatype . $class_pattern])) {
73 return self::$field_class_cache[$datatype . $class_pattern];
76 $fieldtype = $datatype;
78 $class = sprintf($class_pattern, $fieldtype);
79 self::$field_class_cache[$datatype . $class_pattern] = $class;
86 return "class." . self::getFieldClass($datatype, $class_pattern) .
".php";
94 if (!empty($field->
getId()) && !empty(self::$field_representation_cache[$field->
getId()])) {
95 return self::$field_representation_cache[$field->
getId()];
98 $class_path = self::getClassPathByInstance($field, self::$field_representation_class_pattern);
100 if (file_exists($class_path)) {
101 $class = self::getClassByInstance($field, self::$field_representation_class_pattern);
102 $instance =
new $class($field);
104 throw new ilDclException(
"Path for FieldRepresentation with file " . $class_path .
" does not exists!");
107 if ($instance ==
null) {
108 throw new ilDclException(
"Could not create FieldRepresentation of " . $class .
" with file " . $class_path);
112 self::$field_representation_cache[$field->
getId()] = $instance;
128 if ($record_field->
getId() !=
null && !empty(self::$record_representation_cache[$record_field->
getId()])) {
129 return self::$record_representation_cache[$record_field->
getId()];
132 $class_path = self::getClassPathByInstance(
134 self::$record_representation_class_pattern
137 if (file_exists($class_path)) {
138 $class = self::getClassByInstance($record_field->
getField(), self::$record_representation_class_pattern);
140 $class = self::getFieldClass(self::$default_prefix .
"Base", self::$record_representation_class_pattern);
143 $instance =
new $class($record_field);
145 if ($instance ==
null) {
146 throw new ilDclException(
"Could not create RecordRepresentation of " . $class_path .
" " . $record_field->
getField()->getDatatype()->getTitle());
150 self::$record_representation_cache[$record_field->
getId()] = $instance;
163 if ($datatype !=
null) {
164 $base->setDatatypeId($datatype);
167 return self::getFieldModelInstanceByClass($base, $field_id);
179 ?
int $field_id =
null 181 if ($field->
getId() !=
null && !empty(self::$field_model_cache[$field->
getId()])) {
182 return self::$field_model_cache[$field->
getId()];
185 $path_type = self::getClassPathByInstance($field, self::$field_class_patter);
187 if (file_exists($path_type)) {
188 $class = self::getClassByInstance($field, self::$field_class_patter);
190 $class = self::getFieldClass(self::$default_prefix .
"Base", self::$field_class_patter);
194 $instance =
new $class($field_id);
196 $instance =
new $class();
199 if ($instance ==
null) {
200 throw new ilDclException(
"Could not create FieldModel of " . $class);
205 self::$field_model_cache[$field->
getId()] = $instance;
218 if (!empty(self::$field_type_cache[$datatype->getId()])) {
219 return self::$field_type_cache[$datatype->getId()];
224 if ($DIC[
"component.repository"]->hasActivatedPlugin($plugin_id)) {
225 $fieldtype =
'il' . $DIC[
"component.repository"]->getPluginById($plugin_id)->getName();
233 $fieldtype = self::$default_prefix . ucfirst(
'Fileupload');
235 $fieldtype = self::$default_prefix . ucfirst(self::parseDatatypeTitle($datatype->getTitle()));
237 self::$field_type_cache[$datatype->getId()] = $fieldtype;
243 $fieldtype = self::getFieldTypeByInstance($field);
245 return self::getFieldClass($fieldtype, $class_pattern);
258 if ($field->
getId() !=
null && !empty(self::$class_path_cache[$field->
getId()][$class_pattern])) {
259 return self::$class_path_cache[$field->
getId()][$class_pattern];
264 if ($DIC[
"component.repository"]->hasActivatedPlugin($plugin_id)) {
265 $class_path = $DIC[
"component.repository"]->getPluginById($plugin_id)->getPath() .
'/classes/';
273 $class_path = sprintf(
274 self::$field_base_path_patter,
275 ucfirst(self::parseDatatypeTitle(
'Fileupload'))
278 $class_name = sprintf(
279 'class.' . self::$default_prefix .
'%s.php',
282 ucfirst(
'Fileupload'),
286 $return = $class_path . $class_name;
288 self::$class_path_cache[$field->
getId()][$class_pattern] = $return;
293 $class_path = sprintf(
294 self::$field_base_path_patter,
295 ucfirst(self::parseDatatypeTitle($datatype->getTitle()))
299 $return = $class_path . self::getFieldClassFile(self::getFieldTypeByInstance($field), $class_pattern);
302 self::$class_path_cache[$field->
getId()][$class_pattern] = $return;
314 $parts = explode(
"_", $title);
315 $func =
function ($value) {
316 return ucfirst($value);
320 return implode(
"",
$parts);
330 $class_name = get_class($object);
331 return substr($class_name, 2, -(strlen(self::$field_class_patter) - 2));
static array $record_representation_cache
static getFieldClass(string $datatype, string $class_pattern)
Concatenates Classname from datatype and pattern.
static array $class_path_cache
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
static getClassPathByInstance(ilDclBaseFieldModel $field, string $class_pattern)
static getFieldTypeByInstance(ilDclBaseFieldModel $field)
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
static getRecordModelInstance(?int $record_id)
static isPluginDatatype(string $datatype)
static array $field_type_cache
static array $field_class_cache
static getClassByInstance(ilDclBaseFieldModel $field, string $class_pattern)
static getPluginId(string $datatype)
static string $field_class_patter
static string $default_prefix
static string $field_base_path_patter
static string $record_representation_class_pattern
static array $record_field_cache
static parseDatatypeTitle(string $title)
Parse string to FieldClass format Replaces _ with camelcase-notation.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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...
static getFieldModelInstance(int $field_id, ?int $datatype=null)
Get FieldModel from field-id and datatype.
static getRecordFieldInstance(object $field, object $record)
Creates a RecordField instance and loads the field and record representation.
static getRecordRepresentationInstance(ilDclBaseRecordFieldModel $record_field)
Get RecordRepresentation from RecordFieldModel.
static array $field_representation_cache
static string $record_field_class_patter
static getFieldClassFile(string $datatype, string $class_pattern)
const INPUTFORMAT_FILEUPLOAD
static array $field_model_cache
static getPluginNameFromFieldModel(ilDclBaseFieldModel $object)
getDatatypeId()
Get datatype_id.
static string $field_representation_class_pattern