ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDclSelectionFieldRepresentation.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
27 
28  protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption
29  {
30  $opt = parent::buildFieldCreationInput($dcl, $mode);
31 
32  $selection_options = $this->buildOptionsInput();
33  $opt->addSubItem($selection_options);
34 
35  $selection_type = new ilRadioGroupInputGUI(
36  $this->lng->txt('dcl_selection_type'),
37  'prop_' . $this->field::PROP_SELECTION_TYPE
38  );
39  $selection_type->setRequired(true);
40 
41  $options = [
45  ];
46 
47  foreach ($options as $option) {
48  $selection_type->addOption(new ilRadioOption($this->lng->txt('dcl_' . $option), $option));
49  }
50 
51  $opt->addSubItem($selection_type);
52 
53  $prop_unique = new ilDclCheckboxInputGUI(
54  $this->lng->txt('dcl_unique'),
56  );
57  $prop_unique->setInfo($this->lng->txt('dcl_unique_desc'));
58  $opt->addSubItem($prop_unique);
59 
60  return $opt;
61  }
62 
63  public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI
64  {
65  $options = [];
66  foreach (ilDclSelectionOption::getAllForField((int) $this->getField()->getId()) as $opt) {
67  $options[$opt->getOptId()] = $this->getField()->personalizeOptionValue($opt->getValue(), $this->user);
68  }
69  switch ($this->getField()->getProperty($this->field::PROP_SELECTION_TYPE)) {
71  $input = new ilMultiSelectInputGUI(
72  $this->getField()->getTitle(),
73  'field_' . $this->getField()->getId()
74  );
75  $input->setWidth(100);
76  $input->setWidthUnit('%');
77  $input->setHeight(32 * min(5, max(1, count($options))));
78 
79  $input->setOptions($options);
80  break;
82  $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
83  $input->setOptions(["" => $this->lng->txt('dcl_please_select')] + $options);
84  break;
86  default:
87  $input = new ilRadioGroupInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
88  foreach ($options as $key => $opt) {
89  $input->addOption(new ilRadioOption($opt, (string) $key));
90  }
91  $input->setValue((string) array_key_first($options));
92  break;
93  }
94  $this->setupInputField($input, $this->getField());
95 
96  return $input;
97  }
98 
99  public function addFilterInputFieldToTable(ilTable2GUI $table)
100  {
101  $input = $table->addFilterItemByMetaType(
102  "filter_" . $this->getField()->getId(),
104  false,
105  $this->getField()->getId()
106  );
107 
108  $options = ilDclSelectionOption::getAllForField((int) $this->getField()->getId());
109  $array = ['' => $this->lng->txt('dcl_all_entries')];
110  foreach ($options as $opt) {
111  $array[$opt->getOptId()] = $opt->getValue();
112  }
113 
114  $array['none'] = $this->lng->txt('dcl_no_entry');
115 
116  $input->setOptions($array);
117 
118  $this->setupFilterInputField($input);
119 
120  return $this->getFilterInputFieldValue($input);
121  }
122 
124  {
125  return $this->field;
126  }
127 
128  abstract protected function buildOptionsInput(): ilDclGenericMultiInputGUI;
129 }
This class represents an option in a radio group.
buildFieldCreationInput(ilObjDataCollection $dcl, string $mode='create')
This class represents a selection list property in a property form.
setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field)
Sets basic settings on field-input.
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.
This class represents a property in a property form.
getInputField(ilPropertyFormGUI $form, ?int $record_id=null)
getPropertyInputFieldId(string $property)
Return post-var for property-fields.
static getAllForField(int $field_id)
setupFilterInputField(?ilTableFilterItem $input)
Set basic settings for filter-input-gui.
setRequired(bool $a_required)