ILIAS  release_7 Revision v7.30-3-g800a261c036
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) {
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 }
65 $key = "{$identification->serialize()}|{$lng}";
69 if ($item = self::find($key)) {
70 return $item->getTranslation();
71 }
72
73 return "";
74 }
75
76
83 {
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 (!isset($default_language)) {
99 $default_language = $DIC->language()->getDefaultLanguage() ? $DIC->language()->getDefaultLanguage() : "en";
100 }
101
102 return $default_language;
103 }
104
105
115 protected $id;
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 {
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}
An exception for terminatinating execution or to throw for unit testing.
Class CachedActiveRecord.
static find($primary_key, array $add_constructor_args=array())
@inheritDoc
Class ilGlobalCache.
static getInstance($component)
Class ilMMItemTranslationStorage.
static hasDefaultTranslation(IdentificationInterface $identification)
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
static storeTranslation(IdentificationInterface $identification, string $language_key, string $translation)
global $DIC
Definition: goto.php:24
$lng