ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  } else {
37  $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
38  }
39 
40  $this->setupInputField($input, $this->getField());
41 
42  $options = [];
43  if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
44  $options[''] = $this->lng->txt('dcl_please_select');
45  }
46 
47  $value = null;
48  $copy_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
49  $copy_field = ilDclCache::getFieldCache($copy_id);
50  if ($copy_field->getTableId() !== 0) {
51  $copy_table = ilDclCache::getTableCache($copy_field->getTableId());
52  foreach ($copy_table->getRecords() as $record) {
53  $option = $record->getRecordField($copy_field->getId())->getPlainText();
54  if (!in_array($option, $options)) {
55  $options[$option] = $option;
56  }
57  }
58  } else {
59  $input->setAlert($this->lng->txt('dcl_origin_not_found'));
60  }
61 
62  if ($record_id !== null) {
63  $value = ilDclCache::getRecordCache($record_id)->getRecordFieldValue($this->getField()->getId());
64  if ($value !== '' && !array_key_exists($value, $options)) {
65  $options[$value] = $value . ' ' . $this->lng->txt('dcl_deprecated_copy');
66  }
67  }
68 
69  $input->setOptions($options);
70 
71  return $input;
72  }
73 
74  public function addFilterInputFieldToTable(ilTable2GUI $table)
75  {
76  $input = $table->addFilterItemByMetaType(
77  "filter_" . $this->getField()->getId(),
79  false,
80  $this->getField()->getId()
81  );
82  $input->setSubmitFormOnEnter(true);
83 
84  $this->setupFilterInputField($input);
85 
86  return $this->getFilterInputFieldValue($input);
87  }
88 
89  public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool
90  {
91  $pass = parent::passThroughFilter($record, $filter);
92 
93  $value = $record->getRecordFieldValue($this->getField()->getId());
94  if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) {
95  $pass = true;
96  }
97 
98  return $pass;
99  }
100 
101  protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption
102  {
103  $datetype_title = $this->getField()->getPresentationTitle();
104  $opt = new ilRadioOption($this->getField()->getPresentationTitle(), $this->getField()->getDatatypeId());
105  $opt->setInfo($this->getField()->getPresentationDescription());
106 
107  $options = [];
108  $tables = $dcl->getTables();
109  foreach ($tables as $table) {
110  foreach ($table->getRecordFields() as $field) {
111  if (in_array($field->getDatatypeId(), self::VALID_TYPES)) {
112  $options[$field->getId()] = $table->getTitle() . ' -> ' . $field->getTitle();
113  }
114  }
115  }
116 
117  $prop_table_selection = new ilSelectInputGUI(
118  $this->lng->txt('dcl_copy_title'),
120  );
121  $prop_table_selection->setOptions($options);
122  $opt->addSubItem($prop_table_selection);
123 
124  $prop_multi_select = new ilDclCheckboxInputGUI(
125  $this->lng->txt('dcl_multiple_selection'),
127  );
128  $opt->addSubItem($prop_multi_select);
129 
130  return $opt;
131  }
132 }
This class represents an option in a radio group.
This class represents a selection list property in a property form.
static getFieldCache(int $field_id=0)
getRecordFieldValue(?string $field_id)
Get Field Value.
setOptions(array $a_options)
passThroughFilter(ilDclBaseRecordModel $record, $filter)
setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field)
Sets basic settings on field-input.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a multi selection list property in a property form.
addFilterItemByMetaType(string $id, int $type=self::FILTER_TEXT, bool $a_optional=false, string $caption="")
Add filter by standard type.
static getTableCache(?int $table_id=null)
setupFilterInputField(?ilTableFilterItem $input)
Set basic settings for filter-input-gui.
buildFieldCreationInput(ilObjDataCollection $dcl, string $mode='create')
static getRecordCache(?int $record_id)
getInputField(ilPropertyFormGUI $form, ?int $record_id=null)
getDatatypeId()
Get datatype_id.