ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclReferenceFieldRepresentation.php
Go to the documentation of this file.
1<?php
2
10{
11 const REFERENCE_SEPARATOR = " -> ";
12
13
14 public function getInputField(ilPropertyFormGUI $form, $record_id = 0)
15 {
16 if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
17 $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
18 } else {
19 $input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
20 $input->setWidth(100);
21 $input->setWidthUnit('%');
22 }
23
24 $this->setupInputField($input, $this->getField());
25
26 $fieldref = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
27
28 $reffield = ilDclCache::getFieldCache($fieldref);
29 $options = array();
30 if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
31 $options[""] = $this->lng->txt('dcl_please_select');
32 }
33 $reftable = ilDclCache::getTableCache($reffield->getTableId());
34 foreach ($reftable->getRecords() as $record) {
35 // If the referenced field is MOB or FILE, we display the filename in the dropdown
36 switch ($reffield->getDatatypeId()) {
38 $file_obj = new ilObjFile($record->getRecordFieldValue($fieldref), false);
39 $options[$record->getId()] = $file_obj->getFileName();
40 break;
42 $media_obj = new ilObjMediaObject($record->getRecordFieldValue($fieldref), false);
43 $options[$record->getId()] = $media_obj->getTitle();
44 break;
46 $options[$record->getId()] = strtotime($record->getRecordFieldSingleHTML($fieldref));
47 // TT #0019091: options2 are the actual values, options the timestamp for sorting
48 $options2[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref);
49 break;
51 $value = $record->getRecordFieldValue($fieldref);
52 if ($record->getRecordField($fieldref)->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) {
53 if (!is_array($value)) {
54 $value = array('title' => '', 'link' => $value);
55 }
56 $value = $value['title'] ? $value['title'] : $value['link'];
57 }
58 $options[$record->getId()] = $value;
59 break;
61 $options[$record->getId()] = $record->getRecordFieldRepresentationValue($fieldref);
62 break;
63 default:
64 $options[$record->getId()] = $record->getRecordFieldExportValue($fieldref);
65 break;
66 }
67 }
68 asort($options);
69
70 // TT #0019091: restore the actual values after sorting with timestamp
71 if ($reffield->getDatatypeId() == ilDclDatatype::INPUTFORMAT_DATETIME) {
72 foreach ($options as $key => $opt) {
73 $options[$key] = $options2[$key];
74 }
75 // the option 'please select' messes with the order, therefore we reset it
76 unset($options[""]);
77 $options = array("" => $this->lng->txt('dcl_please_select')) + $options;
78 }
79
80 $input->setOptions($options);
81
82 if (ilObjDataCollectionAccess::hasPermissionToAddRecord($_GET['ref_id'], $reftable->getId())) {
83 $input->addCustomAttribute('data-ref="1"');
84 $input->addCustomAttribute('data-ref-table-id="' . $reftable->getId() . '"');
85 $input->addCustomAttribute('data-ref-field-id="' . $reffield->getId() . '"');
86 }
87
88 return $input;
89 }
90
91
93 {
94 $input = $table->addFilterItemByMetaType("filter_" . $this->getField()->getId(), ilTable2GUI::FILTER_SELECT, false, $this->getField()->getId());
95 $ref_field_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
96 $ref_field = ilDclCache::getFieldCache($ref_field_id);
97 $ref_table = ilDclCache::getTableCache($ref_field->getTableId());
98 $options = array();
99 foreach ($ref_table->getRecords() as $record) {
100 $options[$record->getId()] = $record->getRecordFieldPlainText($ref_field_id);
101 }
102 // Sort by values ASC
103 asort($options);
104 $options = array('' => $this->lng->txt('dcl_all_entries'))
105 + $options
106 + array('none' => $this->lng->txt('dcl_no_entry'));
107 $input->setOptions($options);
108
109 $this->setupFilterInputField($input);
110
111 return $this->getFilterInputFieldValue($input);
112 }
113
114
115 public function passThroughFilter(ilDclBaseRecordModel $record, $filter)
116 {
117 $value = $record->getRecordFieldValue($this->getField()->getId());
118
119 $pass = false;
120 if ($filter && $this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE) && is_array($value) && in_array($filter, $value)) {
121 $pass = true;
122 }
123 if (!$filter || $filter == $value) {
124 $pass = true;
125 }
126
127 return $pass;
128 }
129
130
134 public function buildFieldCreationInput(ilObjDataCollection $dcl, $mode = 'create')
135 {
136 $opt = parent::buildFieldCreationInput($dcl, $mode);
137
138 $options = array();
139 // Get Tables
140 $tables = $dcl->getTables();
141 foreach ($tables as $table) {
142 foreach ($table->getRecordFields() as $field) {
143 //referencing references may lead to endless loops.
144 if ($field->getDatatypeId() != ilDclDatatype::INPUTFORMAT_REFERENCE) {
145 $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
146 }
147 }
148 }
149 $prop_table_selection = new ilSelectInputGUI($this->lng->txt('dcl_reference_title'), 'prop_' . ilDclBaseFieldModel::PROP_REFERENCE);
150 $prop_table_selection->setOptions($options);
151
152 $opt->addSubItem($prop_table_selection);
153
154 $prop_ref_link = new ilDclCheckboxInputGUI($this->lng->txt('dcl_reference_link'), 'prop_' . ilDclBaseFieldModel::PROP_REFERENCE_LINK);
155 $prop_ref_link->setInfo($this->lng->txt('dcl_reference_link_info'));
156 $opt->addSubItem($prop_ref_link);
157
158 $prop_multi_select = new ilDclCheckboxInputGUI($this->lng->txt('dcl_multiple_selection'), 'prop_' . ilDclBaseFieldModel::PROP_N_REFERENCE);
159 $opt->addSubItem($prop_multi_select);
160
161 return $opt;
162 }
163}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldRepresentation.
setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field)
Sets basic settings on field-input.
setupFilterInputField(ilFormPropertyGUI $input)
Set basic settings for filter-input-gui.
Class ilDclBaseRecordModel.
getRecordFieldValue($field_id)
Get Field Value.
static getTableCache($table_id=0)
static getFieldCache($field_id=0)
Class ilDclCheckboxInputGUI.
passThroughFilter(ilDclBaseRecordModel $record, $filter)
Checks if a filter affects a record.
getInputField(ilPropertyFormGUI $form, $record_id=0)
Returns field-input.
addFilterInputFieldToTable(ilTable2GUI $table)
Add filter input to TableGUI.
buildFieldCreationInput(ilObjDataCollection $dcl, $mode='create')
@inheritDoc
This class represents a multi selection list property in a property form.
static hasPermissionToAddRecord($ref_id, $table_id)
Class ilObjDataCollection.
Class ilObjFile.
Class ilObjMediaObject.
This class represents a property form user interface.
This class represents a selection list property in a property form.
Class ilTable2GUI.
addFilterItemByMetaType($id, $type=self::FILTER_TEXT, $a_optional=false, $caption=null)
Add filter by standard type.