ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjectTranslation Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilObjectTranslation:

Public Member Functions

 setObjId (int $val)
 
 getObjId ()
 
 setMasterLanguage (string $val)
 
 getMasterLanguage ()
 
 setLanguages (array $val)
 
 getLanguages ()
 
 setFallbackLanguage (string $val)
 
 getFallbackLanguage ()
 
 addLanguage (string $lang, string $title, string $description, bool $default, bool $force=false)
 
 getDefaultTitle ()
 
 setDefaultTitle (string $title)
 
 getDefaultDescription ()
 
 setDefaultDescription (string $description)
 
 getDefaultLanguage ()
 
 removeLanguage (string $lang)
 
 getContentActivated ()
 
 read ()
 
 delete ()
 
 deactivateContentTranslation ()
 
 save ()
 
 copy (int $obj_id)
 Copy multilingual settings. More...
 
 getEffectiveContentLang (string $lang, string $parent_type)
 Get effective language for given language. More...
 

Static Public Member Functions

static getInstance (int $obj_id)
 

Protected Member Functions

 setContentActivated (bool $val)
 

Protected Attributes

ilDBInterface $db
 
int $obj_id
 
string $master_lang = ""
 
array $languages = []
 
bool $content_activated = false
 
string $fallback_language = ""
 

Static Protected Attributes

static array $instances = []
 

Private Member Functions

 __construct (int $obj_id)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class handles translation mode for an object.

Objects may not use any translations at all

  • use translations for title/description only or
  • use translation for (the page editing) content, too.

Currently, supported by container objects and ILIAS learning modules.

Content master lang vs. default language

  • If no translation mode for the content is active no master lang will be set and no record in table obj_content_master_lng will be saved. For the title/descriptions the default will be marked by field lang_default in table object_translation.
  • If translation for content is activated a master language must be set (since consent may already exist the language of this content is defined through setting the master language (in obj_content_master_lng). Modules that use this mode will not get informed about this, so they can not internally assign existing content to the master lang
  • If translation for content is activated additionally a fallback language can be defined. Users will be presented their language, if content available otherwise the fallback language, if content is available, otherwise the master language
Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e

Definition at line 47 of file class.ilObjectTranslation.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectTranslation::__construct ( int  $obj_id)
private

Definition at line 62 of file class.ilObjectTranslation.php.

References $DIC, read(), and setObjId().

63  {
64  global $DIC;
65  $this->db = $DIC->database();
66 
67  $this->setObjId($obj_id);
68 
69  if ($obj_id <= 0) {
70  throw new ilObjectException("ilObjectTranslation: No object ID passed.");
71  }
72 
73  $this->read();
74  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addLanguage()

ilObjectTranslation::addLanguage ( string  $lang,
string  $title,
string  $description,
bool  $default,
bool  $force = false 
)

Definition at line 131 of file class.ilObjectTranslation.php.

References $lang.

Referenced by read().

137  : void {
138  if ($lang !== "" && (!isset($this->languages[$lang]) || $force)) {
139  if ($default) {
140  foreach ($this->languages as $l) {
141  $l->setDefault(false);
142  }
143  }
144  $this->languages[$lang] = new ilObjectTranslationLanguage(
145  $lang,
146  $title,
147  $description,
148  $default
149  );
150  }
151  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lang
Definition: xapiexit.php:26
+ Here is the caller graph for this function:

◆ copy()

ilObjectTranslation::copy ( int  $obj_id)

Copy multilingual settings.

Definition at line 345 of file class.ilObjectTranslation.php.

References getFallbackLanguage(), getLanguages(), and getMasterLanguage().

346  {
347  $target_ml = new ilObjectTranslation($obj_id);
348  $target_ml->setMasterLanguage($this->getMasterLanguage());
349  $target_ml->setFallbackLanguage($this->getFallbackLanguage());
350  $target_ml->setLanguages($this->getLanguages());
351  $target_ml->save();
352  return $target_ml;
353  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ deactivateContentTranslation()

ilObjectTranslation::deactivateContentTranslation ( )

Definition at line 292 of file class.ilObjectTranslation.php.

292  : void
293  {
294  $this->db->manipulate(
295  "DELETE FROM obj_content_master_lng " .
296  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
297  );
298  }

◆ delete()

ilObjectTranslation::delete ( )

Definition at line 280 of file class.ilObjectTranslation.php.

280  : void
281  {
282  $this->db->manipulate(
283  "DELETE FROM obj_content_master_lng " .
284  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
285  );
286  $this->db->manipulate(
287  "DELETE FROM object_translation " .
288  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
289  );
290  }

◆ getContentActivated()

ilObjectTranslation::getContentActivated ( )

Definition at line 246 of file class.ilObjectTranslation.php.

References $content_activated.

Referenced by getEffectiveContentLang().

246  : bool
247  {
249  }
+ Here is the caller graph for this function:

◆ getDefaultDescription()

ilObjectTranslation::getDefaultDescription ( )

Definition at line 187 of file class.ilObjectTranslation.php.

References ilObject\_lookupDescription(), getFallbackLanguage(), and getObjId().

Referenced by ilObjStudyProgrammeSettingsGUI\getEditSection().

187  : string
188  {
189  if ($this->getFallbackLanguage() !== ''
190  && array_key_exists($this->fallback_language, $this->languages)) {
191  return $this->languages[$this->getFallbackLanguage()]->getDescription();
192  }
193  foreach ($this->languages as $l) {
194  if ($l->isDefault()) {
195  return $l->getDescription();
196  }
197  }
198  if (count($this->languages) == 0) {
199  return ilObject::_lookupDescription($this->getObjId());
200  }
201  return '';
202  }
static _lookupDescription(int $obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultLanguage()

ilObjectTranslation::getDefaultLanguage ( )

Definition at line 221 of file class.ilObjectTranslation.php.

References getFallbackLanguage().

Referenced by ilObjStudyProgrammeSettingsGUI\getEditSection().

221  : string
222  {
223  if ($this->getFallbackLanguage() !== "") {
224  return $this->getFallbackLanguage();
225  }
226  foreach ($this->languages as $l) {
227  if ($l->isDefault()) {
228  return $l->getLanguageCode();
229  }
230  }
231  return "";
232  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultTitle()

ilObjectTranslation::getDefaultTitle ( )

Definition at line 153 of file class.ilObjectTranslation.php.

References $fallback_language, ilObject\_lookupTitle(), and getObjId().

Referenced by ilObject\appendCopyInfoToTranslations(), and ilObjStudyProgrammeSettingsGUI\getEditSection().

153  : string
154  {
155  if ($this->fallback_language !== ""
156  && array_key_exists($this->fallback_language, $this->languages)) {
157  return $this->languages[$this->fallback_language]->getTitle();
158  } else {
159  foreach ($this->languages as $l) {
160  if ($l->isDefault()) {
161  return $l->getTitle();
162  }
163  }
164  }
165  if (count($this->languages) == 0) {
166  return ilObject::_lookupTitle($this->getObjId());
167  }
168  return '';
169  }
static _lookupTitle(int $obj_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEffectiveContentLang()

ilObjectTranslation::getEffectiveContentLang ( string  $lang,
string  $parent_type 
)

Get effective language for given language.

This checks if

  • multilingual is activated and
  • the given language is part of the available translations If not a "-" is returned (master language).
Parameters
string$langlanguage
string$parent_typepage parent type
Returns
string effective language ("-" for master)

Definition at line 366 of file class.ilObjectTranslation.php.

References $lang, ilPageObject\_exists(), getContentActivated(), getFallbackLanguage(), getLanguages(), getMasterLanguage(), and getObjId().

366  : string
367  {
368  $langs = $this->getLanguages();
369  $page_lang_key = ($lang == $this->getMasterLanguage())
370  ? "-"
371  : $lang;
372  if ($this->getContentActivated() &&
373  isset($langs[$lang]) &&
374  ilPageObject::_exists($parent_type, $this->getObjId(), $page_lang_key)) {
375  if ($lang == $this->getMasterLanguage()) {
376  return "-";
377  }
378  return $lang;
379  }
380  if ($this->getContentActivated() &&
381  isset($langs[$this->getFallbackLanguage()]) &&
382  ilPageObject::_exists($parent_type, $this->getObjId(), $this->getFallbackLanguage())) {
383  return $this->getFallbackLanguage();
384  }
385  return "-";
386  }
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
$lang
Definition: xapiexit.php:26
+ Here is the call graph for this function:

◆ getFallbackLanguage()

ilObjectTranslation::getFallbackLanguage ( )

◆ getInstance()

static ilObjectTranslation::getInstance ( int  $obj_id)
static

Definition at line 76 of file class.ilObjectTranslation.php.

References $obj_id.

Referenced by ilPageMultiLangGUI\__construct(), ilLMPresentationStatus\__construct(), ILIAS\LearningModule\Export\LMHtmlExport\__construct(), ilObjectTranslationGUI\__construct(), ilLMContentRendererGUI\__construct(), ilContainer\_exportContainerSettings(), ilStructureObject\_getPresentationTitle(), ilLMPageObject\_getPresentationTitle(), ilObject\appendCopyInfo(), ilObject\appendCopyInfoToTranslations(), ilObjContentObjectGUI\checkCtrlPath(), ilContainer\create(), ilObjContentPage\doCloneObject(), ilObjItemGroup\doCloneObject(), ilObjItemGroup\doCreate(), ilObjContentObject\doMDUpdateListener(), ilObjItemGroup\doUpdate(), ilObjMediaPoolGUI\executeCommand(), ilObjContentObjectGUI\export(), ilObjMediaPoolGUI\export(), ilObjContentObjectGUI\exportHTML(), ilContentPagePageCommandForwarder\forward(), ilContainerGUI\getContainerPageHTML(), ilObjectDataSet\getDependencies(), ilObjMediaPoolGUI\getEditFormCustomValues(), ILIAS\COPage\Editor\Components\Page\PageQueryActionHandler\getMultiLangActions(), ilObjContentObjectGUI\getMultiLangHeader(), ILIAS\COPage\Editor\Components\Page\PageQueryActionHandler\getMultiLangInfo(), ilObjContentPageListGUI\getProperties(), ilObjContentObjectGUI\getPropertiesFormValues(), ilObjContentObject\getPublicExportFiles(), ilLMImportGUI\importTranslation(), ilLMPresentationGUI\initByRequest(), ilMediaPoolImportGUI\initTranslationImportForm(), ilLMImportGUI\initTranslationImportForm(), ilObjContentPage\initTranslationService(), ilContainer\read(), ilObjContentObjectGUI\saveProperties(), ilObjMediaPoolGUI\updateCustom(), and ilObjContentObject\validatePages().

77  {
78  if (!isset(self::$instances[$obj_id])) {
79  self::$instances[$obj_id] = new ilObjectTranslation($obj_id);
80  }
81 
82  return self::$instances[$obj_id];
83  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ getLanguages()

ilObjectTranslation::getLanguages ( )
Returns
array array of language codes

Definition at line 116 of file class.ilObjectTranslation.php.

References $languages.

Referenced by ilObject\appendCopyInfoToTranslations(), copy(), getEffectiveContentLang(), ilLMPresentationStatus\getLMPresentationTitle(), ILIAS\LearningModule\Export\LMHtmlExport\initDirectories(), and save().

116  : array
117  {
118  return $this->languages;
119  }
+ Here is the caller graph for this function:

◆ getMasterLanguage()

ilObjectTranslation::getMasterLanguage ( )

Definition at line 100 of file class.ilObjectTranslation.php.

References $master_lang.

Referenced by copy(), getEffectiveContentLang(), removeLanguage(), and save().

100  : string
101  {
102  return $this->master_lang;
103  }
+ Here is the caller graph for this function:

◆ getObjId()

ilObjectTranslation::getObjId ( )

Definition at line 90 of file class.ilObjectTranslation.php.

References $obj_id.

Referenced by getDefaultDescription(), getDefaultTitle(), getEffectiveContentLang(), read(), and save().

90  : int
91  {
92  return $this->obj_id;
93  }
+ Here is the caller graph for this function:

◆ read()

ilObjectTranslation::read ( )

Definition at line 251 of file class.ilObjectTranslation.php.

References addLanguage(), getObjId(), setContentActivated(), setFallbackLanguage(), setLanguages(), and setMasterLanguage().

Referenced by __construct().

251  : void
252  {
253  $sql =
254  "SELECT obj_id, master_lang, fallback_lang" . PHP_EOL
255  . "FROM obj_content_master_lng" . PHP_EOL
256  . "WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer") . PHP_EOL
257  ;
258  $result = $this->db->query($sql);
259  if ($row = $this->db->fetchAssoc($result)) {
260  $this->setMasterLanguage($row["master_lang"]);
261  $this->setFallbackLanguage($row["fallback_lang"] ?? '');
262  $this->setContentActivated(true);
263  } else {
264  $this->setContentActivated(false);
265  }
266 
267  $this->setLanguages([]);
268 
269  $sql =
270  "SELECT title, description, lang_code, lang_default" . PHP_EOL
271  . "FROM object_translation" . PHP_EOL
272  . "WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer") . PHP_EOL
273  ;
274  $result = $this->db->query($sql);
275  while ($row = $this->db->fetchAssoc($result)) {
276  $this->addLanguage($row["lang_code"], (string) $row["title"], (string) $row["description"], (bool) $row["lang_default"]);
277  }
278  }
addLanguage(string $lang, string $title, string $description, bool $default, bool $force=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeLanguage()

ilObjectTranslation::removeLanguage ( string  $lang)

Definition at line 234 of file class.ilObjectTranslation.php.

References getMasterLanguage().

234  : void
235  {
236  if ($lang != $this->getMasterLanguage()) {
237  unset($this->languages[$lang]);
238  }
239  }
$lang
Definition: xapiexit.php:26
+ Here is the call graph for this function:

◆ save()

ilObjectTranslation::save ( )

Definition at line 300 of file class.ilObjectTranslation.php.

References getFallbackLanguage(), getLanguages(), getMasterLanguage(), and getObjId().

300  : void
301  {
302  $this->delete();
303 
304  if ($this->getMasterLanguage() != "") {
305  $values = [
306  "obj_id" => ["integer", $this->getObjId()],
307  "master_lang" => ["text", $this->getMasterLanguage()],
308  "fallback_lang" => ["text", $this->getFallbackLanguage()]
309  ];
310 
311  $this->db->insert("obj_content_master_lng", $values);
312  // ensure that an entry for the master language exists and is the default
313  if (!isset($this->languages[$this->getMasterLanguage()])) {
314  $this->languages[$this->getMasterLanguage()] = new ilObjectTranslationLanguage(
315  "",
316  "",
317  $this->getMasterLanguage(),
318  true
319  );
320  }
321  foreach ($this->languages as $trans) {
322  if ($trans->getLanguageCode() === $this->getMasterLanguage()) {
323  $trans->setDefault(true);
324  } else {
325  $trans->setDefault(false);
326  }
327  }
328  }
329 
330  foreach ($this->getLanguages() as $trans) {
331  $values = [
332  "obj_id" => ["integer", $this->getObjId()],
333  "title" => ["text", $trans->getTitle()],
334  "description" => ["text", $trans->getDescription()],
335  "lang_code" => ["text", $trans->getLanguageCode()],
336  "lang_default" => ["integer", $trans->isDefault()],
337  ];
338  $this->db->insert("object_translation", $values);
339  }
340  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ setContentActivated()

ilObjectTranslation::setContentActivated ( bool  $val)
protected

Definition at line 241 of file class.ilObjectTranslation.php.

Referenced by read().

241  : void
242  {
243  $this->content_activated = $val;
244  }
+ Here is the caller graph for this function:

◆ setDefaultDescription()

ilObjectTranslation::setDefaultDescription ( string  $description)

Definition at line 204 of file class.ilObjectTranslation.php.

References getFallbackLanguage().

204  : void
205  {
206  if ($this->getFallbackLanguage() !== ''
207  && isset($this->languages[$this->getFallbackLanguage()])) {
208  $this->languages[$this->getFallbackLanguage()]
209  ->setDescription($description);
210  return;
211  }
212 
213  foreach ($this->languages as $l) {
214  if ($l->isDefault()) {
215  $l->setDescription($description);
216  return;
217  }
218  }
219  }
+ Here is the call graph for this function:

◆ setDefaultTitle()

ilObjectTranslation::setDefaultTitle ( string  $title)

Definition at line 171 of file class.ilObjectTranslation.php.

References getFallbackLanguage().

171  : void
172  {
173  if ($this->getFallbackLanguage() !== ''
174  && isset($this->languages[$this->getFallbackLanguage()])) {
175  $this->languages[$this->getFallbackLanguage()]->setTitle($title);
176  return;
177  }
178 
179  foreach ($this->languages as $l) {
180  if ($l->isDefault()) {
181  $l->setTitle($title);
182  return;
183  }
184  }
185  }
+ Here is the call graph for this function:

◆ setFallbackLanguage()

ilObjectTranslation::setFallbackLanguage ( string  $val)

Definition at line 121 of file class.ilObjectTranslation.php.

Referenced by read().

121  : void
122  {
123  $this->fallback_language = $val;
124  }
+ Here is the caller graph for this function:

◆ setLanguages()

ilObjectTranslation::setLanguages ( array  $val)
Parameters
array$valarray of language codes

Definition at line 108 of file class.ilObjectTranslation.php.

Referenced by ilObject\appendCopyInfoToTranslations(), and read().

108  : void
109  {
110  $this->languages = $val;
111  }
+ Here is the caller graph for this function:

◆ setMasterLanguage()

ilObjectTranslation::setMasterLanguage ( string  $val)

Definition at line 95 of file class.ilObjectTranslation.php.

Referenced by read().

95  : void
96  {
97  $this->master_lang = $val;
98  }
+ Here is the caller graph for this function:

◆ setObjId()

ilObjectTranslation::setObjId ( int  $val)

Definition at line 85 of file class.ilObjectTranslation.php.

Referenced by __construct().

85  : void
86  {
87  $this->obj_id = $val;
88  }
+ Here is the caller graph for this function:

Field Documentation

◆ $content_activated

bool ilObjectTranslation::$content_activated = false
protected

Definition at line 59 of file class.ilObjectTranslation.php.

Referenced by getContentActivated().

◆ $db

ilDBInterface ilObjectTranslation::$db
protected

Definition at line 51 of file class.ilObjectTranslation.php.

◆ $fallback_language

string ilObjectTranslation::$fallback_language = ""
protected

Definition at line 60 of file class.ilObjectTranslation.php.

Referenced by getDefaultTitle(), and getFallbackLanguage().

◆ $instances

array ilObjectTranslation::$instances = []
staticprotected

Definition at line 49 of file class.ilObjectTranslation.php.

◆ $languages

array ilObjectTranslation::$languages = []
protected

Definition at line 58 of file class.ilObjectTranslation.php.

Referenced by getLanguages().

◆ $master_lang

string ilObjectTranslation::$master_lang = ""
protected

Definition at line 54 of file class.ilObjectTranslation.php.

Referenced by getMasterLanguage().

◆ $obj_id

int ilObjectTranslation::$obj_id
protected

Definition at line 52 of file class.ilObjectTranslation.php.

Referenced by getInstance(), and getObjId().


The documentation for this class was generated from the following file: