ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDFieldDefinitionSelectMulti.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected const XML_SEPARATOR = "~|~";
29
30 public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search): string
31 {
32 return (string) $a_adt_search->getADT()->getSelections()[0];
33 }
34
35 public function getType(): int
36 {
38 }
39
40 protected function initADTDefinition(): ilADTDefinition
41 {
42 $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("MultiEnum");
43 $def->setNumeric(false);
44
45 $def->setOptions($this->getOptionsInLanguageAsArray($this->language));
46 return $def;
47 }
48
49 public function importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language = ''): void
50 {
51 $this->importNewSelectOptions(true, $a_form, $language);
52 }
53
54 public function getValueForXML(ilADT $element): string
55 {
56 $record = ilAdvancedMDRecord::_getInstanceByRecordId($this->getRecordID());
57 if (!$record->getParentObject()) {
58 return $this->implodeValuesForXML((array) $element->getSelections());
59 }
65 $index = 1;
66 $selections = [];
67 foreach ($this->options()->getOptions() as $option) {
68 if (in_array($option->optionID(), (array) $element->getSelections())) {
69 $selections[] = $index;
70 }
71 $index++;
72 }
73 return $this->implodeValuesForXML($selections);
74 }
75
76 protected function implodeValuesForXML(array $values): string
77 {
78 return self::XML_SEPARATOR .
79 implode(self::XML_SEPARATOR, $values) .
81 }
82
83 public function importValueFromXML(string $a_cdata): void
84 {
85 $values = [];
86 foreach (explode(self::XML_SEPARATOR, trim($a_cdata, self::XML_SEPARATOR)) as $value) {
87 $value = $this->translateLegacyImportValueFromXML($value);
88 $values[] = $value;
89 }
90 $this->getADT()->setSelections($values);
91 }
92
93 public function prepareElementForEditor(ilADTFormBridge $a_bridge): void
94 {
95 assert($a_bridge instanceof ilADTMultiEnumFormBridge);
96
97 $a_bridge->setAutoSort(false);
98 }
99}
ADT definition base class.
ADT form bridge base class.
ADT search bridge base class.
ADT base class.
Definition: class.ilADT.php:26
prepareElementForEditor(ilADTFormBridge $a_bridge)
Prepare editor form elements.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
getOptionsInLanguageAsArray(string $language, bool $default_as_fallback=true)
importNewSelectOptions(bool $multi, ilPropertyFormGUI $a_form, string $language='')
translateLegacyImportValueFromXML(string $value)
On import from <7 options are not given by index but by their label.
static _getInstanceByRecordId(int $a_record_id)
This class represents a property form user interface.