ILIAS  release_8 Revision v8.24
class.ilADTLocalizedText.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private array $translations = [];
28
29 public function getTextForLanguage(string $language): string
30 {
31 if (array_key_exists($language, $this->getTranslations()) && strlen($this->getTranslations()[$language])) {
32 return $this->getTranslations()[$language];
33 }
34 return (string) $this->getText();
35 }
36
40 public function getTranslations(): array
41 {
43 }
44
45 public function setTranslation(string $language, string $translation): void
46 {
47 $this->translations[$language] = $translation;
48 }
49
53 protected function isValidDefinition(ilADTDefinition $a_def): bool
54 {
55 return $a_def instanceof ilADTLocalizedTextDefinition;
56 }
57
61 public function equals(ilADT $a_adt): ?bool
62 {
63 if (!$this->getDefinition()->isComparableTo($a_adt)) {
64 return null;
65 }
66 if ($this->getTranslations() != count($a_adt->getTranslations())) {
67 return false;
68 }
69 foreach ($a_adt->getTranslations() as $key => $value) {
70 if (!isset($this->getTranslations()[$key])) {
71 return false;
72 }
73 if (!strcmp($this->getTranslations()[$key], $value)) {
74 return false;
75 }
76 }
77 return true;
78 }
79
83 public function isLarger(ilADT $a_adt): ?bool
84 {
85 return null;
86 }
87
91 public function isSmaller(ilADT $a_adt): ?bool
92 {
93 return null;
94 }
95
99 public function isNull(): bool
100 {
101 $has_translation = false;
102 foreach ($this->getTranslations() as $translation) {
103 if ($translation !== '') {
104 $has_translation = true;
105 break;
106 }
107 }
108 return !$this->getLength() && !$has_translation;
109 }
110
114 public function getCheckSum(): ?string
115 {
116 if (!$this->isNull()) {
117 return md5(serialize($this->getTranslations()));
118 }
119 return null;
120 }
121
125 public function exportStdClass(): ?stdClass
126 {
127 if (!$this->isNull()) {
128 $obj = new stdClass();
129 $obj->translations = $this->getTranslations();
130 return $obj;
131 }
132 return null;
133 }
134
138 public function importStdClass(?stdClass $a_std): void
139 {
140 if (is_object($a_std)) {
141 $this->translations = $a_std->translations;
142 }
143 }
144}
ADT definition base class.
Class ilADTLocalizedText.
isLarger(ilADT $a_adt)
@inheritDoc
importStdClass(?stdClass $a_std)
@inheritDoc
getTextForLanguage(string $language)
setTranslation(string $language, string $translation)
isSmaller(ilADT $a_adt)
@inheritDoc
isValidDefinition(ilADTDefinition $a_def)
@inheritDoc
equals(ilADT $a_adt)
@inheritDoc
string $value
ADT base class.
Definition: class.ilADT.php:12
getDefinition()
Get definition.
Definition: class.ilADT.php:92
string $key
Consumer key/client ID value.
Definition: System.php:193