ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclFileuploadFieldRepresentation.php
Go to the documentation of this file.
1 <?php
2 require_once ('./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseFieldRepresentation.php');
3 
11 
15  public function getInputField(ilPropertyFormGUI $form, $record_id = 0) {
16  $input = new ilFileInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
17  $input->setSuffixes($this->getField()->getSupportedExtensions());
18  $input->setAllowDeletion(true);
19 
20  $this->requiredWorkaroundForInputField($input, $record_id);
21 
22  return $input;
23  }
24 
25  protected function requiredWorkaroundForInputField($input, $record_id) {
26  if ($record_id) {
27  $record = ilDclCache::getRecordCache($record_id);
28  }
29 
30  $this->setupInputField($input, $this->getField());
31 
32  //WORKAROUND
33  // 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.
34  if ($record_id && $record->getId()) {
35  $field_value = $record->getRecordFieldValue($this->getField()->getId());
36  if ($field_value) {
37  $input->setRequired(false);
38  }
39  }
40  // If this is an ajax request to return the form, input files are currently not supported
41  if ($this->ctrl->isAsynch()) {
42  $input->setDisabled(true);
43  }
44  }
45 
46 
50  public function addFilterInputFieldToTable(ilTable2GUI $table) {
51  $input = $table->addFilterItemByMetaType("filter_" . $this->getField()->getId(), ilTable2GUI::FILTER_TEXT, false, $this->getField()->getId());
52  $input->setSubmitFormOnEnter(true);
53 
54  $this->setupFilterInputField($input);
55 
56  return $this->getFilterInputFieldValue($input);
57  }
58 
59 
63  public function passThroughFilter(ilDclBaseRecordModel $record, $filter) {
64  $value = $record->getRecordFieldValue($this->getField()->getId());
65  $pass = false;
66  if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
67  $pass = true;
68  }
69 
70  $file_obj = new ilObjFile($value, false);
71  $file_name = $file_obj->getTitle();
72  if (!$filter || strpos(strtolower($file_name), strtolower($filter)) !== false) {
73  $pass = true;
74  }
75 
76  return $pass;
77  }
78 
82  public function buildFieldCreationInput(ilObjDataCollection $dcl, $mode = 'create') {
83  $opt = parent::buildFieldCreationInput($dcl, $mode);
84 
85  $prop_filetype = new ilTextInputGUI($this->lng->txt('dcl_supported_filetypes'), 'prop_'.ilDclBaseFieldModel::PROP_SUPPORTED_FILE_TYPES);
86  $prop_filetype->setInfo($this->lng->txt('dcl_supported_filetypes_desc'));
87 
88  $opt->addSubItem($prop_filetype);
89 
90  return $opt;
91  }
92 }
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=NULL)
Add filter by standard type.
This class represents a property form user interface.
This class represents a file property in a property form.
setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field)
Sets basic settings on field-input.
setInfo($a_info)
Set Information Text.
Class ilTable2GUI.
passThroughFilter(ilDclBaseRecordModel $record, $filter)
static getRecordCache($record_id=0)
Class ilObjFile.
This class represents a text property in a property form.
setupFilterInputField(ilFormPropertyGUI $input)
Set basic settings for filter-input-gui.
getInputField(ilPropertyFormGUI $form, $record_id=0)
Class ilDclBaseRecordModel.
static _lookupType($a_id, $a_reference=false)
getRecordFieldValue($field_id)
Get Field Value.
static _exists($a_id, $a_reference=false, $a_type=null)
buildFieldCreationInput(ilObjDataCollection $dcl, $mode='create')
Class ilDclBaseFieldRepresentation.
Class ilObjDataCollection.