ILIAS  release_8 Revision v8.24
class.ilDclFileuploadFieldRepresentation.php
Go to the documentation of this file.
1<?php
2
20{
21 public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFileInputGUI
22 {
23 $input = new ilFileInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
24 $input->setSuffixes($this->getField()->getSupportedExtensions());
25 $input->setAllowDeletion(true);
26
27 $this->requiredWorkaroundForInputField($input, $record_id);
28
29 return $input;
30 }
31
32 protected function requiredWorkaroundForInputField(ilFileInputGUI $input, ?int $record_id): void
33 {
34 if ($record_id) {
35 $record = ilDclCache::getRecordCache($record_id);
36 }
37
38 $this->setupInputField($input, $this->getField());
39
40 //WORKAROUND
41 // If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it.
42 if ($record_id && $record->getId()) {
43 $field_value = $record->getRecordFieldValue($this->getField()->getId());
44 if ($field_value) {
45 $input->setRequired(false);
46 }
47 }
48 // If this is an ajax request to return the form, input files are currently not supported
49 if ($this->ctrl->isAsynch()) {
50 $input->setDisabled(true);
51 }
52 }
53
59 {
60 $input = $table->addFilterItemByMetaType(
61 "filter_" . $this->getField()->getId(),
63 false,
64 $this->getField()->getId()
65 );
66 $input->setSubmitFormOnEnter(true);
67
68 $this->setupFilterInputField($input);
69
70 return $this->getFilterInputFieldValue($input);
71 }
72
76 public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool
77 {
78 $value = $record->getRecordFieldValue($this->getField()->getId());
79 $pass = false;
80 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value) != "file") {
81 $pass = true;
82 }
83
84 $file_obj = new ilObjFile($value, false);
85 $file_name = $file_obj->getTitle();
86 if (!$filter || strpos(strtolower($file_name), strtolower($filter)) !== false) {
87 $pass = true;
88 }
89
90 return $pass;
91 }
92
96 protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption
97 {
98 $opt = parent::buildFieldCreationInput($dcl, $mode);
99
100 $prop_filetype = new ilTextInputGUI(
101 $this->lng->txt('dcl_supported_filetypes'),
103 );
104 $prop_filetype->setInfo($this->lng->txt('dcl_supported_filetypes_desc'));
105
106 $opt->addSubItem($prop_filetype);
107
108 return $opt;
109 }
110}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field)
Sets basic settings on field-input.
setupFilterInputField(?ilTableFilterItem $input)
Set basic settings for filter-input-gui.
getRecordFieldValue(?int $field_id)
Get Field Value.
static getRecordCache(?int $record_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
passThroughFilter(ilDclBaseRecordModel $record, $filter)
requiredWorkaroundForInputField(ilFileInputGUI $input, ?int $record_id)
buildFieldCreationInput(ilObjDataCollection $dcl, string $mode='create')
@inheritDoc
getInputField(ilPropertyFormGUI $form, ?int $record_id=null)
Returns field-input.
This class represents a file property in a property form.
setRequired(bool $a_required)
setDisabled(bool $a_disabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFile.
static _lookupType(int $id, bool $reference=false)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
This class represents a text property in a property form.