ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilDclCopyFieldRepresentation.php
Go to the documentation of this file.
1 <?php
2 
20 {
21  private const VALID_TYPES = [
26  ];
27 
31  public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI
32  {
33  if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
34  $input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
35  } else {
36  $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
37  }
38 
39  $this->setupInputField($input, $this->getField());
40 
41  $options = [];
42  if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
43  $options[''] = $this->lng->txt('dcl_please_select');
44  }
45 
46  $value = null;
47  $copy_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE);
48  $copy_field = ilDclCache::getFieldCache($copy_id);
49  if ($copy_field->getTableId() !== 0) {
50  $copy_table = ilDclCache::getTableCache($copy_field->getTableId());
51  foreach ($copy_table->getRecords() as $record) {
52  $option = $record->getRecordField($copy_field->getId())->getPlainText();
53  if (!in_array($option, $options)) {
54  $options[$option] = $option;
55  }
56  }
57  } else {
58  $input->setAlert($this->lng->txt('dcl_origin_not_found'));
59  }
60 
61  if ($record_id !== null) {
62  $value = ilDclCache::getRecordCache($record_id)->getRecordFieldValue($this->getField()->getId());
63  if ($value !== '' && !array_key_exists($value, $options)) {
64  $options[$value] = $value . ' ' . $this->lng->txt('dcl_deprecated_copy');
65  }
66  }
67 
68  $input->setOptions($options);
69 
70  return $input;
71  }
72 
73  public function addFilterInputFieldToTable(ilTable2GUI $table)
74  {
75  $input = $table->addFilterItemByMetaType(
76  "filter_" . $this->getField()->getId(),
78  false,
79  $this->getField()->getId()
80  );
81  $input->setSubmitFormOnEnter(true);
82 
83  $this->setupFilterInputField($input);
84 
85  return $this->getFilterInputFieldValue($input);
86  }
87 
88  public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool
89  {
90  $pass = parent::passThroughFilter($record, $filter);
91 
92  $value = $record->getRecordFieldValue($this->getField()->getId());
93  if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) {
94  $pass = true;
95  }
96 
97  return $pass;
98  }
99 
100  protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption
101  {
102  $datetype_title = $this->getField()->getPresentationTitle();
103  $opt = new ilRadioOption($this->getField()->getPresentationTitle(), $this->getField()->getDatatypeId());
104  $opt->setInfo($this->getField()->getPresentationDescription());
105 
106  $options = [];
107  $tables = $dcl->getTables();
108  foreach ($tables as $table) {
109  foreach ($table->getRecordFields() as $field) {
110  if (in_array($field->getDatatypeId(), self::VALID_TYPES)) {
111  $options[$field->getId()] = $table->getTitle() . ' -> ' . $field->getTitle();
112  }
113  }
114  }
115 
116  $prop_table_selection = new ilSelectInputGUI(
117  $this->lng->txt('dcl_copy_title'),
119  );
120  $prop_table_selection->setOptions($options);
121  $opt->addSubItem($prop_table_selection);
122 
123  $prop_multi_select = new ilDclCheckboxInputGUI(
124  $this->lng->txt('dcl_multiple_selection'),
126  );
127  $opt->addSubItem($prop_multi_select);
128 
129  return $opt;
130  }
131 }
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.