ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMMItemTranslationStorage.php
Go to the documentation of this file.
1 <?php
2 
4 
11 {
12 
21  {
22  if ($translation === "-") {
23  return new self();
24  }
25  $language_identification = "{$identification->serialize()}|$language_key";
26  $mt = ilMMItemTranslationStorage::find($language_identification);
27  if (!$mt instanceof ilMMItemTranslationStorage) {
28  $mt = new ilMMItemTranslationStorage();
29  $mt->setId($language_identification);
30  $mt->setIdentification($identification->serialize());
31  $mt->create();
32  }
33 
34  $mt->setTranslation($translation);
35  $mt->setLanguageKey($language_key);
36  $mt->update();
37 
38  return $mt;
39  }
40 
41 
49  {
50  return self::storeTranslation($identification, self::getDefaultLanguage(), $translation);
51  }
52 
53 
59  public static function getDefaultTranslation(IdentificationInterface $identification) : string
60  {
61  if (!self::hasDefaultTranslation($identification)) {
62  return "";
63  }
64  $lng = self::getDefaultLanguage();
65  $key = "{$identification->serialize()}|{$lng}";
69  if ($item = self::find($key)) {
70  return $item->getTranslation();
71  }
72 
73  return "";
74  }
75 
76 
82  public static function hasDefaultTranslation(IdentificationInterface $identification) : bool
83  {
84  $lng = self::getDefaultLanguage();
85  $key = "{$identification->serialize()}|{$lng}";
86 
87  return self::find($key) instanceof self;
88  }
89 
90 
94  public static function getDefaultLanguage() : string
95  {
96  static $default_language;
97  global $DIC;
98  if (!$default_language) {
99  $default_language = $DIC->language()->getDefaultLanguage() ? $DIC->language()->getDefaultLanguage() : "en";
100  }
101 
102  return $default_language;
103  }
104 
105 
115  protected $id;
123  protected $identification;
131  protected $translation = '';
139  protected $language_key = '';
143  protected $connector_container_name = "il_mm_translation";
144 
145 
149  public function getId() : string
150  {
151  return $this->id;
152  }
153 
154 
158  public function setId(string $id)
159  {
160  $this->id = $id;
161  }
162 
163 
167  public function getIdentification() : string
168  {
169  return $this->identification;
170  }
171 
172 
176  public function setIdentification(string $identification)
177  {
178  $this->identification = $identification;
179  }
180 
181 
185  public function getTranslation() : string
186  {
187  return $this->translation;
188  }
189 
190 
194  public function setTranslation(string $translation)
195  {
196  $this->translation = $translation;
197  }
198 
199 
203  public function getLanguageKey() : string
204  {
205  return $this->language_key;
206  }
207 
208 
212  public function setLanguageKey(string $language_key)
213  {
214  $this->language_key = $language_key;
215  }
216 
217 
221  public function getCache() : ilGlobalCache
222  {
224  }
225 }
static find($primary_key, array $add_constructor_args=array())
Class CachedActiveRecord.
global $DIC
Definition: saml.php:7
static getInstance($component)
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
$lng
static hasDefaultTranslation(IdentificationInterface $identification)
static storeTranslation(IdentificationInterface $identification, string $language_key, string $translation)
$key
Definition: croninfo.php:18
Class ilMMItemTranslationStorage.