ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMMItemTranslationStorage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
36 {
37 if ($translation === "-") {
38 return new self();
39 }
40 $language_identification = "{$identification->serialize()}|$language_key";
41 $mt = ilMMItemTranslationStorage::find($language_identification);
42 if (!$mt instanceof ilMMItemTranslationStorage) {
44 $mt->setId($language_identification);
45 $mt->setIdentification($identification->serialize());
46 $mt->create();
47 }
48
49 $mt->setTranslation($translation);
50 $mt->setLanguageKey($language_key);
51 $mt->update();
52
53 return $mt;
54 }
55
62 {
63 return self::storeTranslation($identification, self::getDefaultLanguage(), $translation);
64 }
65
70 public static function getDefaultTranslation(IdentificationInterface $identification): string
71 {
72 if (!self::hasDefaultTranslation($identification)) {
73 return "";
74 }
76 $key = "{$identification->serialize()}|$lng";
80 if (($item = self::find($key)) !== null) {
81 return $item->getTranslation();
82 }
83
84 return "";
85 }
86
92 {
94 $key = "{$identification->serialize()}|$lng";
95
96 return self::find($key) instanceof self;
97 }
98
102 public static function getDefaultLanguage(): string
103 {
104 static $default_language;
105 global $DIC;
106 if (!isset($default_language)) {
107 $default_language = $DIC->language()->getDefaultLanguage() ?: "en";
108 }
109
110 return $default_language;
111 }
112
120 protected ?string $id = null;
126 protected string $identification = '';
132 protected string $translation = '';
138 protected string $language_key = '';
142 protected string $connector_container_name = "il_mm_translation";
143
147 public function getId(): string
148 {
149 return $this->id;
150 }
151
155 public function setId(string $id): void
156 {
157 $this->id = $id;
158 }
159
163 public function getIdentification(): string
164 {
166 }
167
171 public function setIdentification(string $identification): void
172 {
173 $this->identification = $identification;
174 }
175
179 public function getTranslation(): string
180 {
181 return $this->translation;
182 }
183
187 public function setTranslation(string $translation): void
188 {
189 $this->translation = $translation;
190 }
191
195 public function getLanguageKey(): string
196 {
197 return $this->language_key;
198 }
199
203 public function setLanguageKey(string $language_key): void
204 {
205 $this->language_key = $language_key;
206 }
207}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilMMItemTranslationStorage.
static hasDefaultTranslation(IdentificationInterface $identification)
string $translation
@con_has_field true @con_fieldtype text @con_length 4000
string $id
@con_is_primary true @con_is_unique true @con_has_field true @con_fieldtype text @con_length 64
string $identification
@con_has_field true @con_fieldtype text @con_length 256
static storeDefaultTranslation(IdentificationInterface $identification, string $translation)
static storeTranslation(IdentificationInterface $identification, string $language_key, string $translation)
string $language_key
@con_has_field true @con_fieldtype text @con_length 8
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26