ILIAS  release_8 Revision v8.24
class.ilDclReferenceFieldRepresentation.php
Go to the documentation of this file.
1<?php
2
20{
21 public const REFERENCE_SEPARATOR = " -> ";
22
28 public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI
29 {
30 if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
31 $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
32 } else {
33 $input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
34 $input->setWidth(100);
35 $input->setWidthUnit('%');
36 }
37
38 $this->setupInputField($input, $this->getField());
39
40 $fieldref = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
41
42 $reffield = ilDclCache::getFieldCache($fieldref);
43 $options = [];
44 if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
45 $options[""] = $this->lng->txt('dcl_please_select');
46 }
47 $reftable = ilDclCache::getTableCache($reffield->getTableId());
48 foreach ($reftable->getRecords() as $record) {
49 // If the referenced field is MOB or FILE, we display the filename in the dropdown
50 switch ($reffield->getDatatypeId()) {
52 $field_value = $record->getRecordFieldValue($fieldref);
53 if ($field_value) {
54 $file_obj = new ilObjFile($field_value, false);
55 $options[$record->getId()] = $file_obj->getFileName();
56 }
57 break;
59 $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref));
60 $options[$record->getId()] = $media_obj->getTitle();
61 break;
63 $options[$record->getId()] = strtotime($record->getRecordFieldSingleHTML($fieldref));
64 // TT #0019091: options2 are the actual values, options the timestamp for sorting
65 $options2[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref);
66 break;
68 $value = $record->getRecordFieldValue($fieldref);
69 if ($record->getRecordField($fieldref)->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
70 if (!is_array($value)) {
71 $value = ['title' => '', 'link' => $value];
72 }
73 $value = $value['title'] ?: $value['link'];
74 }
75 $options[$record->getId()] = $value;
76 break;
78 $options[$record->getId()] = $record->getRecordFieldRepresentationValue($fieldref);
79 break;
80 default:
81 $options[$record->getId()] = $record->getRecordFieldExportValue($fieldref);
82 break;
83 }
84 }
85 asort($options, SORT_NATURAL | SORT_FLAG_CASE);
86
87 // TT #0019091: restore the actual values after sorting with timestamp
88 if ($reffield->getDatatypeId() == ilDclDatatype::INPUTFORMAT_DATETIME) {
89 foreach ($options as $key => $opt) {
90 if ($key != "") {
91 $options[$key] = $options2[$key];
92 }
93 }
94 // the option 'please select' messes with the order, therefore we reset it
95 unset($options[""]);
96 $options = ["" => $this->lng->txt('dcl_please_select')] + $options;
97 }
98
99 $input->setOptions($options);
100
101 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
102
104 $input->addCustomAttribute('data-ref="1"');
105 $input->addCustomAttribute('data-ref-table-id="' . $reftable->getId() . '"');
106 $input->addCustomAttribute('data-ref-field-id="' . $reffield->getId() . '"');
107 }
108
109 return $input;
110 }
111
116 {
117 $input = $table->addFilterItemByMetaType(
118 "filter_" . $this->getField()->getId(),
120 false,
121 $this->getField()->getId()
122 );
123 $ref_field_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
124 $ref_field = ilDclCache::getFieldCache($ref_field_id);
125 $ref_table = ilDclCache::getTableCache($ref_field->getTableId());
126 $options = [];
127 foreach ($ref_table->getRecords() as $record) {
128 $options[$record->getId()] = $record->getRecordFieldPlainText($ref_field_id);
129 }
130 // Sort by values ASC
131 asort($options);
132 $options = ['' => $this->lng->txt('dcl_all_entries')]
133 + $options
134 + ['none' => $this->lng->txt('dcl_no_entry')];
135 $input->setOptions($options);
136
137 $this->setupFilterInputField($input);
138
139 return $this->getFilterInputFieldValue($input);
140 }
141
145 public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool
146 {
147 $value = $record->getRecordFieldValue($this->getField()->getId());
148
149 $pass = false;
150 if ($filter && $this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE) && is_array($value) && in_array(
151 $filter,
152 $value
153 )) {
154 $pass = true;
155 }
156 if (!$filter || $filter == $value) {
157 $pass = true;
158 }
159
160 return $pass;
161 }
162
163 protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption
164 {
165 $opt = parent::buildFieldCreationInput($dcl, $mode);
166
167 $options = [];
168 // Get Tables
169 $tables = $dcl->getTables();
170 foreach ($tables as $table) {
171 foreach ($table->getRecordFields() as $field) {
172 //referencing references may lead to endless loops.
174 $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
175 }
176 }
177 }
178 $prop_table_selection = new ilSelectInputGUI(
179 $this->lng->txt('dcl_reference_title'),
181 );
182 $prop_table_selection->setOptions($options);
183
184 $opt->addSubItem($prop_table_selection);
185
186 $prop_ref_link = new ilDclCheckboxInputGUI(
187 $this->lng->txt('dcl_reference_link'),
189 );
190 $prop_ref_link->setInfo($this->lng->txt('dcl_reference_link_info'));
191 $opt->addSubItem($prop_ref_link);
192
193 $prop_multi_select = new ilDclCheckboxInputGUI(
194 $this->lng->txt('dcl_multiple_selection'),
196 );
197 $opt->addSubItem($prop_multi_select);
198
199 return $opt;
200 }
201}
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 getFieldCache(int $field_id=0)
static getTableCache(int $table_id=null)
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...
passThroughFilter(ilDclBaseRecordModel $record, $filter)
getInputField(ilPropertyFormGUI $form, ?int $record_id=null)
buildFieldCreationInput(ilObjDataCollection $dcl, string $mode='create')
Build the creation-input-field.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static hasPermissionToAddRecord(int $ref_id, int $table_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFile.
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 class represents a selection list property in a property form.
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.
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
string $key
Consumer key/client ID value.
Definition: System.php:193