ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilAdvancedMDFieldDefinitionSelectMulti.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  {
37  return self::TYPE_SELECT_MULTI;
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) .
80  self::XML_SEPARATOR;
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 form bridge base class.
getOptionsInLanguageAsArray(string $language, bool $default_as_fallback=true)
translateLegacyImportValueFromXML(string $value)
On import from <7 options are not given by index but by their label.
ADT base class.
Definition: class.ilADT.php:25
importNewSelectOptions(bool $multi, ilPropertyFormGUI $a_form, string $language='')
static _getInstanceByRecordId(int $a_record_id)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
ADT search bridge base class.
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
ADT definition base class.