ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
class.ilADTLocalizedText.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  {
42  return $this->translations;
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 
58  public function reset(): void
59  {
60  parent::reset();
61  $this->translations = [];
62  }
63 
67  public function equals(ilADT $a_adt): ?bool
68  {
69  if (!$this->getDefinition()->isComparableTo($a_adt)) {
70  return null;
71  }
72  if ($this->getTranslations() != count($a_adt->getTranslations())) {
73  return false;
74  }
75  foreach ($a_adt->getTranslations() as $key => $value) {
76  if (!isset($this->getTranslations()[$key])) {
77  return false;
78  }
79  if (!strcmp($this->getTranslations()[$key], $value)) {
80  return false;
81  }
82  }
83  return true;
84  }
85 
89  public function isLarger(ilADT $a_adt): ?bool
90  {
91  return null;
92  }
93 
97  public function isSmaller(ilADT $a_adt): ?bool
98  {
99  return null;
100  }
101 
105  public function isNull(): bool
106  {
107  $has_translation = false;
108  foreach ($this->getTranslations() as $translation) {
109  if ($translation !== '') {
110  $has_translation = true;
111  break;
112  }
113  }
114  return !$this->getLength() && !$has_translation;
115  }
116 
120  public function getCheckSum(): ?string
121  {
122  if (!$this->isNull()) {
123  return md5(serialize($this->getTranslations()));
124  }
125  return null;
126  }
127 
131  public function exportStdClass(): ?stdClass
132  {
133  if (!$this->isNull()) {
134  $obj = new stdClass();
135  $obj->translations = $this->getTranslations();
136  return $obj;
137  }
138  return null;
139  }
140 
144  public function importStdClass(?stdClass $a_std): void
145  {
146  if (is_object($a_std)) {
147  $this->translations = $a_std->translations;
148  }
149  }
150 }
isValidDefinition(ilADTDefinition $a_def)
importStdClass(?stdClass $a_std)
ADT base class.
Definition: class.ilADT.php:25
Class ilADTLocalizedText.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setTranslation(string $language, string $translation)
getTextForLanguage(string $language)
ADT definition base class.
getDefinition()
Get definition.