ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclCopyFieldRepresentation.php
Go to the documentation of this file.
1<?php
2
20{
21 private const VALID_TYPES = [
27 ];
28
32 public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI
33 {
34 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
35 $input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
36 $input->setWidth(100);
37 $input->setWidthUnit('%');
38 } else {
39 $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
40 }
41
42 $this->setupInputField($input, $this->getField());
43
44 $options = [];
45 if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
46 $options[''] = $this->lng->txt('dcl_please_select');
47 }
48
49 $value = null;
50 $copy_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
51 $copy_field = ilDclCache::getFieldCache($copy_id);
52 if ($copy_field->getTableId() !== 0) {
53 $copy_table = ilDclCache::getTableCache($copy_field->getTableId());
54 foreach ($copy_table->getRecords() as $record) {
55 $option = $record->getRecordField($copy_field->getId())->getPlainText();
56 if (!in_array($option, $options)) {
57 $options[$option] = $option;
58 }
59 }
60 } else {
61 $input->setAlert($this->lng->txt('dcl_origin_not_found'));
62 }
63
64 if ($record_id !== null) {
65 $value = ilDclCache::getRecordCache($record_id)->getRecordFieldValue($this->getField()->getId());
66 if ($value !== '' && !array_key_exists($value, $options)) {
67 $options = [$value => $value . ' ' . $this->lng->txt('dcl_deprecated_copy')] + $options;
68 }
69 }
70
71 $input->setOptions($options);
72 if ($input instanceof ilMultiSelectInputGUI) {
73 $input->setHeight(32 * min(5, max(1, count($options))));
74 }
75
76 return $input;
77 }
78
80 {
81 $input = $table->addFilterItemByMetaType(
82 "filter_" . $this->getField()->getId(),
84 false,
85 $this->getField()->getId()
86 );
87 $input->setSubmitFormOnEnter(true);
88
89 $this->setupFilterInputField($input);
90
91 return $this->getFilterInputFieldValue($input);
92 }
93
94 public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool
95 {
96 $pass = parent::passThroughFilter($record, $filter);
97
98 $value = $record->getRecordFieldValue($this->getField()->getId());
99 if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) {
100 $pass = true;
101 }
102
103 return $pass;
104 }
105
106 protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption
107 {
108 $datetype_title = $this->getField()->getPresentationTitle();
109 $opt = new ilRadioOption($this->getField()->getPresentationTitle(), $this->getField()->getDatatypeId());
110 $opt->setInfo($this->getField()->getPresentationDescription());
111
112 $options = [];
113 $tables = $dcl->getTables();
114 foreach ($tables as $table) {
115 foreach ($table->getRecordFields() as $field) {
116 if (in_array($field->getDatatypeId(), self::VALID_TYPES)) {
117 $options[$field->getId()] = $table->getTitle() . ' -> ' . $field->getTitle();
118 }
119 }
120 }
121
122 $prop_table_selection = new ilSelectInputGUI(
123 $this->lng->txt('dcl_copy_title'),
125 );
126 $prop_table_selection->setOptions($options);
127 $opt->addSubItem($prop_table_selection);
128
129 $prop_multi_select = new ilDclCheckboxInputGUI(
130 $this->lng->txt('dcl_multiple_selection'),
132 );
133 $opt->addSubItem($prop_multi_select);
134
135 return $opt;
136 }
137}
setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field)
Sets basic settings on field-input.
setupFilterInputField(?ilTableFilterItem $input)
Set basic settings for filter-input-gui.
getRecordFieldValue(?string $field_id)
Get Field Value.
static getRecordCache(?int $record_id)
static getTableCache(?int $table_id=null)
static getFieldCache(int $field_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getInputField(ilPropertyFormGUI $form, ?int $record_id=null)
addFilterInputFieldToTable(ilTable2GUI $table)
Add filter input to TableGUI.
buildFieldCreationInput(ilObjDataCollection $dcl, string $mode='create')
Build the creation-input-field.
passThroughFilter(ilDclBaseRecordModel $record, $filter)
Checks if a filter affects a record.
This class represents a property in a property form.
This class represents a multi selection list property in a property form.
This class represents a property form user interface.
This class represents an option in a radio group.
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.