ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilADTLocalizedTextFormBridge.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
6 
12 {
16  protected function isValidADT(ilADT $a_adt): bool
17  {
18  return $a_adt instanceof ilADTLocalizedText;
19  }
20 
24  public function addToForm(): void
25  {
26  $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
27  $multilingual_value_support = $this->getADT()->getCopyOfDefinition()->getMultilingualValueSupport();
28 
29  if (
30  !count($active_languages) ||
31  !$multilingual_value_support
32  ) {
33 
34  $languages = $this->getADT()->getTranslations();
35  $text = $languages[$this->getADT()->getCopyOfDefinition()->getDefaultLanguage()] ?? '';
36  $this->addElementToForm(
37  $this->getTitle(),
38  $this->getElementId() . '_' . $this->getADT()->getCopyOfDefinition()->getDefaultLanguage(),
39  $text,
40  false,
41  ''
42  );
43  return;
44  }
45  $is_translation = null;
46  foreach ($active_languages as $active_language) {
47  if (strcmp($active_language, $this->getADT()->getCopyOfDefinition()->getDefaultLanguage()) === 0) {
48  $is_translation = false;
49  } else {
50  $is_translation = true;
51  }
52 
53  $languages = $this->getADT()->getTranslations();
54 
55  $text = '';
56 
57  if (array_key_exists($active_language, $languages)) {
58  $text = $languages[$active_language];
59  }
60 
61  $this->addElementToForm(
62  $this->getTitle(),
63  $this->getElementId() . '_' . $active_language,
64  $text,
65  $is_translation,
66  $active_language
67  );
68  }
69  }
70 
74  public function importFromPost(): void
75  {
76  $multilingual_value_support = $this->getADT()->getCopyOfDefinition()->getMultilingualValueSupport();
77  if (
78  !$this->getADT()->getCopyOfDefinition()->supportsTranslations() ||
79  !$multilingual_value_support
80  ) {
81  $language = $this->getADT()->getCopyOfDefinition()->getDefaultLanguage();
82  $this->getADT()->setTranslation(
83  $language,
84  $this->getForm()->getInput($this->getElementId() . '_' . $language)
85  );
86  $this->getADT()->setText($this->getForm()->getInput($this->getElementId() . '_' . $language));
87  $input_item = $this->getForm()->getItemByPostVar($this->getElementId() . '_' . $language);
88  $input_item->setValue($this->getADT()->getTextForLanguage($language));
89  return;
90  }
91  $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
92  foreach ($active_languages as $language) {
93  $this->getADT()->setTranslation(
94  $language,
95  $this->getForm()->getInput($this->getElementId() . '_' . $language)
96  );
97  $this->getADT()->setText($this->getForm()->getInput($this->getElementId() . '_' . $language));
98  $input_item = $this->getForm()->getItemByPostVar($this->getElementId() . '_' . $language);
99  $input_item->setValue((string) $this->getADT()->getTranslations()[$language]);
100  }
101  }
102 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ADT base class.
Definition: class.ilADT.php:11
Class ilADTLocalizedText.
Class ilADTLocalizedTextDBBridge.
$text
Definition: xapiexit.php:21
addElementToForm(string $title, string $element_id, string $value, bool $is_translation=false, string $language='')