ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTLocalizedText.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
13  private $translations = [];
14 
18  public function getTextForLanguage(string $language)
19  {
20  if (strlen($this->getTranslations()[$language])) {
21  return $this->getTranslations()[$language];
22  }
23  return $this->getText();
24  }
25 
29  public function getTranslations()
30  {
31  return $this->translations;
32  }
33 
38  public function setTranslation(string $language, string $translation)
39  {
40  $this->translations[$language] = $translation;
41  }
42 
46  protected function isValidDefinition(ilADTDefinition $a_def)
47  {
48  return $a_def instanceof ilADTLocalizedTextDefinition;
49  }
50 
54  public function equals(ilADT $adt)
55  {
56  if (!$this->getDefinition()->isComparableTo($adt)) {
57  return false;
58  }
59  if (count($this->getTranslations()) != count($adt->getTranslations())) {
60  return false;
61  }
62  foreach ($adt->getTranslations() as $key => $value) {
63  if (!isset($this->getTranslations()[$key])) {
64  return false;
65  }
66  if (!strcmp($this->getTranslations()[$key], $value)) {
67  return false;
68  }
69  }
70  return true;
71  }
72 
76  public function isLarger(ilADT $a_adt)
77  {
78  }
79 
83  public function isSmaller(ilADT $a_adt)
84  {
85  }
86 
90  public function isNull()
91  {
92  return !$this->getLength() && !count($this->getTranslations());
93  }
94 
98  public function getCheckSum()
99  {
100  return md5(serialize($this->getTranslations()));
101  }
102 
106  public function exportStdClass()
107  {
108  if (!$this->isNull()) {
109  $obj = new stdClass();
110  $obj->translations = $this->getTranslations();
111  return $obj;
112  }
113  }
114 
118  public function importStdClass($a_std)
119  {
120  if (is_object($a_std)) {
121  $this->translations = $a_std->translations;
122  }
123  }
124 }
isValidDefinition(ilADTDefinition $a_def)
ADT base class.
Definition: class.ilADT.php:11
Class ilADTLocalizedText.
setTranslation(string $language, string $translation)
getTextForLanguage(string $language)
ADT definition base class.
getDefinition()
Get definition.
Definition: class.ilADT.php:97