ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilObjectTranslation Class Reference

Class handles translation mode for an object. More...

+ Collaboration diagram for ilObjectTranslation:

Public Member Functions

 setObjId ($a_val)
 Set object id. More...
 
 getObjId ()
 Get object id. More...
 
 setMasterLanguage ($a_val)
 Set master language. More...
 
 getMasterLanguage ()
 Get master language. More...
 
 setLanguages (array $a_val)
 Set languages. More...
 
 getLanguages ()
 Get languages. More...
 
 setFallbackLanguage ($a_val)
 Set fallback language. More...
 
 getFallbackLanguage ()
 Get fallback language. More...
 
 addLanguage ($a_lang, $a_title, $a_description, $a_default, $a_force=false)
 Add language. More...
 
 getDefaultTitle ()
 Get default title. More...
 
 setDefaultTitle ($a_title)
 Set default title. More...
 
 getDefaultDescription ()
 Get default description. More...
 
 setDefaultDescription ($a_description)
 Set default description. More...
 
 getDefaultLanguage ()
 Get default language. More...
 
 removeLanguage ($a_lang)
 Remove language. More...
 
 getContentActivated ()
 Get activated for content. More...
 
 read ()
 Read. More...
 
 delete ()
 Delete. More...
 
 deactivateContentTranslation ()
 Deactivate content translation. More...
 
 save ()
 Save. More...
 
 copy ($a_obj_id)
 Copy multilinguality settings. More...
 
 getEffectiveContentLang ($a_lang, $a_parent_type)
 Get effective language for given language. More...
 

Static Public Member Functions

static getInstance ($a_obj_id)
 Get instance. More...
 

Protected Member Functions

 setContentActivated ($a_val)
 Set activated for content. More...
 

Protected Attributes

 $db
 
 $obj_id
 
 $master_lang
 
 $languages = array()
 
 $content_activated = false
 
 $fallback_language = ""
 

Static Protected Attributes

static $instances = array()
 

Private Member Functions

 __construct ($a_obj_id)
 Constructor. More...
 

Detailed Description

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 concent 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
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilObjectTranslation::__construct (   $a_obj_id)
private

Constructor.

Parameters
int$a_obj_idobject id
Exceptions
ilObjectException

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

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

50  {
51  global $DIC;
52 
53  $ilDB = $DIC->database();
54 
55  $this->db = $ilDB;
56 
57  $this->setObjId($a_obj_id);
58 
59  if ($this->getObjId() <= 0) {
60  include_once("./Services/Object/exceptions/class.ilObjectException.php");
61  throw new ilObjectException("ilObjectTranslation: No object ID passed.");
62  }
63 
64  $this->read();
65  }
Base exception class for object service.
setObjId($a_val)
Set object id.
global $DIC
Definition: goto.php:24
global $ilDB
+ Here is the call graph for this function:

Member Function Documentation

◆ addLanguage()

ilObjectTranslation::addLanguage (   $a_lang,
  $a_title,
  $a_description,
  $a_default,
  $a_force = false 
)

Add language.

Parameters
string$a_langlanguage
string$a_titletitle
string$a_descriptiondescription
bool$a_defaultdefault language?

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

Referenced by read().

171  {
172  if ($a_lang != "" && (!isset($this->languages[$a_lang]) || $a_force)) {
173  if ($a_default) {
174  foreach ($this->languages as $k => $l) {
175  $this->languages[$k]["lang_default"] = false;
176  }
177  }
178  $this->languages[$a_lang] = array("lang_code" => $a_lang, "lang_default" => $a_default,
179  "title" => $a_title, "description" => $a_description);
180  }
181  }
+ Here is the caller graph for this function:

◆ copy()

ilObjectTranslation::copy (   $a_obj_id)

Copy multilinguality settings.

Parameters
string$a_target_parent_typeparent object type
int$a_target_parent_idparent object id
Returns
ilObjectTranslation target multilang object

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

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

414  {
415  $target_ml = new ilObjectTranslation($a_obj_id);
416  $target_ml->setMasterLanguage($this->getMasterLanguage());
417  $target_ml->setFallbackLanguage($this->getFallbackLanguage());
418  $target_ml->setLanguages($this->getLanguages());
419  $target_ml->save();
420  return $target_ml;
421  }
getMasterLanguage()
Get master language.
getFallbackLanguage()
Get fallback language.
Class handles translation mode for an object.
+ Here is the call graph for this function:

◆ deactivateContentTranslation()

ilObjectTranslation::deactivateContentTranslation ( )

Deactivate content translation.

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

360  {
361  $this->db->manipulate(
362  "DELETE FROM obj_content_master_lng " .
363  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
364  );
365  }

◆ delete()

ilObjectTranslation::delete ( )

Delete.

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

345  {
346  $this->db->manipulate(
347  "DELETE FROM obj_content_master_lng " .
348  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
349  );
350  $this->db->manipulate(
351  "DELETE FROM object_translation " .
352  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
353  );
354  }

◆ getContentActivated()

ilObjectTranslation::getContentActivated ( )

Get activated for content.

Returns
bool activated for content?

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

References $content_activated.

Referenced by getEffectiveContentLang().

+ Here is the caller graph for this function:

◆ getDefaultDescription()

ilObjectTranslation::getDefaultDescription ( )

Get default description.

Returns
string description of default language

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

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

Referenced by ilObjStudyProgrammeSettingsGUI\getEditSection().

229  {
230  if ($this->getFallbackLanguage() != "") {
231  return $this->languages[$this->getFallbackLanguage()]["description"];
232  }
233  foreach ($this->languages as $l) {
234  if ($l["lang_default"]) {
235  return $l["description"];
236  }
237  }
238  if (count($this->languages) == 0) {
239  return ilObject::_lookupDescription($this->getObjId());
240  }
241  return "";
242  }
static _lookupDescription($a_id)
lookup object description
getFallbackLanguage()
Get fallback language.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultLanguage()

ilObjectTranslation::getDefaultLanguage ( )

Get default language.

Returns
string default language

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

References getFallbackLanguage().

Referenced by ilObjStudyProgrammeSettingsGUI\getEditSection().

268  {
269  if ($this->getFallbackLanguage() != "") {
270  return $this->getFallbackLanguage();
271  }
272  foreach ($this->languages as $l) {
273  if ($l["lang_default"]) {
274  return $l["lang_code"];
275  }
276  }
277  return "";
278  }
getFallbackLanguage()
Get fallback language.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultTitle()

ilObjectTranslation::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

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

Referenced by ilObjStudyProgrammeSettingsGUI\getEditSection().

189  {
190  if ($this->getFallbackLanguage() != "") {
191  return $this->languages[$this->getFallbackLanguage()]["title"];
192  } else {
193  foreach ($this->languages as $l) {
194  if ($l["lang_default"]) {
195  return $l["title"];
196  }
197  }
198  }
199  if (count($this->languages) == 0) {
200  return ilObject::_lookupTitle($this->getObjId());
201  }
202  return "";
203  }
static _lookupTitle($a_id)
lookup object title
getFallbackLanguage()
Get fallback language.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEffectiveContentLang()

ilObjectTranslation::getEffectiveContentLang (   $a_lang,
  $a_parent_type 
)

Get effective language for given language.

This checks if

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

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

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

435  {
436  $langs = $this->getLanguages();
437  $page_lang_key = ($a_lang == $this->getMasterLanguage())
438  ? "-"
439  : $a_lang;
440  if ($this->getContentActivated() &&
441  isset($langs[$a_lang]) &&
442  ilPageObject::_exists($a_parent_type, $this->getObjId(), $page_lang_key)) {
443  if ($a_lang == $this->getMasterLanguage()) {
444  return "-";
445  }
446  return $a_lang;
447  }
448  if ($this->getContentActivated() &&
449  isset($langs[$this->getFallbackLanguage()]) &&
450  ilPageObject::_exists($a_parent_type, $this->getObjId(), $this->getFallbackLanguage())) {
451  return $this->getFallbackLanguage();
452  }
453  return "-";
454  }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
getMasterLanguage()
Get master language.
getContentActivated()
Get activated for content.
getFallbackLanguage()
Get fallback language.
+ Here is the call graph for this function:

◆ getFallbackLanguage()

ilObjectTranslation::getFallbackLanguage ( )

Get fallback language.

Returns
string

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

References $fallback_language.

Referenced by copy(), getDefaultDescription(), getDefaultLanguage(), getDefaultTitle(), getEffectiveContentLang(), setDefaultDescription(), and setDefaultTitle().

+ Here is the caller graph for this function:

◆ getInstance()

static ilObjectTranslation::getInstance (   $a_obj_id)
static

Get instance.

Parameters
integer$a_obj_id(repository) object id
Returns
ilObjectTranslation translation object

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

Referenced by ilLMPresentationStatus\__construct(), ilPageMultiLangGUI\__construct(), ilObjectTranslationGUI\__construct(), ILIAS\LearningModule\Export\LMHtmlExport\__construct(), ilLMContentRendererGUI\__construct(), ilContainer\__construct(), ilContainer\_exportContainerSettings(), ilStructureObject\_getPresentationTitle(), ilLMPageObject\_getPresentationTitle(), ilObjContentObject\cloneObject(), ilContainer\create(), ilObjMediaPoolGUI\executeCommand(), ilObjContentObjectGUI\executeCommand(), ilObjContentObjectGUI\export(), ilObjMediaPoolGUI\export(), ilObjContentObjectGUI\exportHTML(), ilContentPagePageCommandForwarder\forward(), ilContainerGUI\getContainerPageHTML(), ILIAS\COPage\Editor\Components\Page\PageQueryActionHandler\getMultiLangActions(), ilObjContentObjectGUI\getMultiLangHeader(), ILIAS\COPage\Editor\Components\Page\PageQueryActionHandler\getMultiLangInfo(), ilObjContentPageListGUI\getProperties(), ilObjContentObjectGUI\getPropertiesFormValues(), ilObjContentObject\getPublicExportFiles(), ilObjectDataSet\importRecord(), ilLMImportGUI\importTranslation(), ilMediaPoolImportGUI\importTranslation(), ilLMPresentationGUI\initByRequest(), ilMediaPoolImportGUI\initTranslationImportForm(), ilLMImportGUI\initTranslationImportForm(), ilObjContentPage\initTranslationService(), ilObjContentObject\MDUpdateListener(), ilContainer\read(), ilObjContentObjectGUI\saveProperties(), and ilObjContentPage\writeStyleSheetId().

74  {
75  if (!isset(self::$instances[$a_obj_id])) {
76  self::$instances[$a_obj_id] = new ilObjectTranslation($a_obj_id);
77  }
78 
79  return self::$instances[$a_obj_id];
80  }
Class handles translation mode for an object.
+ Here is the caller graph for this function:

◆ getLanguages()

ilObjectTranslation::getLanguages ( )

Get languages.

Returns
array array of language codes

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

References $languages.

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

139  {
140  return $this->languages;
141  }
+ Here is the caller graph for this function:

◆ getMasterLanguage()

ilObjectTranslation::getMasterLanguage ( )

Get master language.

Returns
string master language

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

References $master_lang.

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

119  {
120  return $this->master_lang;
121  }
+ Here is the caller graph for this function:

◆ getObjId()

ilObjectTranslation::getObjId ( )

Get object id.

Returns
int object id

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

References $obj_id.

Referenced by __construct(), getDefaultDescription(), getDefaultTitle(), and getEffectiveContentLang().

99  {
100  return $this->obj_id;
101  }
+ Here is the caller graph for this function:

◆ read()

ilObjectTranslation::read ( )

Read.

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

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

Referenced by __construct().

318  {
319  $set = $this->db->query(
320  "SELECT * FROM obj_content_master_lng " .
321  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
322  );
323  if ($rec = $this->db->fetchAssoc($set)) {
324  $this->setMasterLanguage($rec["master_lang"]);
325  $this->setFallbackLanguage($rec["fallback_lang"]);
326  $this->setContentActivated(true);
327  } else {
328  $this->setContentActivated(false);
329  }
330 
331  $this->setLanguages(array());
332  $set = $this->db->query(
333  "SELECT * FROM object_translation " .
334  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
335  );
336  while ($rec = $this->db->fetchAssoc($set)) {
337  $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
338  }
339  }
setLanguages(array $a_val)
Set languages.
addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force=false)
Add language.
setContentActivated($a_val)
Set activated for content.
setFallbackLanguage($a_val)
Set fallback language.
setMasterLanguage($a_val)
Set master language.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeLanguage()

ilObjectTranslation::removeLanguage (   $a_lang)

Remove language.

Parameters
string$a_langlanguage code

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

References getMasterLanguage().

287  {
288  if ($a_lang != $this->getMasterLanguage()) {
289  unset($this->languages[$a_lang]);
290  }
291  }
getMasterLanguage()
Get master language.
+ Here is the call graph for this function:

◆ save()

ilObjectTranslation::save ( )

Save.

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

References getLanguages(), and getMasterLanguage().

371  {
372  $this->delete();
373 
374  if ($this->getMasterLanguage() != "") {
375  $this->db->manipulate("INSERT INTO obj_content_master_lng " .
376  "(obj_id, master_lang, fallback_lang) VALUES (" .
377  $this->db->quote($this->getObjId(), "integer") . "," .
378  $this->db->quote($this->getMasterLanguage(), "text") . "," .
379  $this->db->quote($this->getFallbackLanguage(), "text") .
380  ")");
381  // ensure that an entry for the master language exists and is the default
382  if (!isset($this->languages[$this->getMasterLanguage()])) {
383  $this->languages[$this->getMasterLanguage()] = array("title" => "",
384  "description" => "", "lang_code" => $this->getMasterLanguage(), "lang_default" => 1);
385  }
386  foreach ($this->languages as $l => $trans) {
387  if ($l == $this->getMasterLanguage()) {
388  $this->languages[$l]["lang_default"] = 1;
389  } else {
390  $this->languages[$l]["lang_default"] = 0;
391  }
392  }
393  }
394  foreach ($this->getLanguages() as $l => $trans) {
395  $this->db->manipulate($t = "INSERT INTO object_translation " .
396  "(obj_id, title, description, lang_code, lang_default) VALUES (" .
397  $this->db->quote($this->getObjId(), "integer") . "," .
398  $this->db->quote($trans["title"], "text") . "," .
399  $this->db->quote($trans["description"], "text") . "," .
400  $this->db->quote($l, "text") . "," .
401  $this->db->quote($trans["lang_default"], "integer") .
402  ")");
403  }
404  }
getMasterLanguage()
Get master language.
+ Here is the call graph for this function:

◆ setContentActivated()

ilObjectTranslation::setContentActivated (   $a_val)
protected

Set activated for content.

Parameters
bool$a_valactivated for content?

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

Referenced by read().

300  {
301  $this->content_activated = $a_val;
302  }
+ Here is the caller graph for this function:

◆ setDefaultDescription()

ilObjectTranslation::setDefaultDescription (   $a_description)

Set default description.

Parameters
string$a_descriptiondescription

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

References getFallbackLanguage().

250  {
251  if ($this->getFallbackLanguage() != "") {
252  $this->languages[$this->getFallbackLanguage()]["description"] = $a_description;
253  } else {
254  foreach ($this->languages as $k => $l) {
255  if ($l["lang_default"]) {
256  $this->languages[$k]["description"] = $a_description;
257  }
258  }
259  }
260  }
getFallbackLanguage()
Get fallback language.
+ Here is the call graph for this function:

◆ setDefaultTitle()

ilObjectTranslation::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

References getFallbackLanguage().

211  {
212  if ($this->getFallbackLanguage() != "") {
213  $this->languages[$this->getFallbackLanguage()]["title"] = $a_title;
214  } else {
215  foreach ($this->languages as $k => $l) {
216  if ($l["lang_default"]) {
217  $this->languages[$k]["title"] = $a_title;
218  }
219  }
220  }
221  }
getFallbackLanguage()
Get fallback language.
+ Here is the call graph for this function:

◆ setFallbackLanguage()

ilObjectTranslation::setFallbackLanguage (   $a_val)

Set fallback language.

Parameters
string$a_val

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

Referenced by read().

148  {
149  $this->fallback_language = $a_val;
150  }
+ Here is the caller graph for this function:

◆ setLanguages()

ilObjectTranslation::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

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

Referenced by read().

129  {
130  $this->languages = $a_val;
131  }
+ Here is the caller graph for this function:

◆ setMasterLanguage()

ilObjectTranslation::setMasterLanguage (   $a_val)

Set master language.

Parameters
string$a_valmaster language

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

Referenced by read().

109  {
110  $this->master_lang = $a_val;
111  }
+ Here is the caller graph for this function:

◆ setObjId()

ilObjectTranslation::setObjId (   $a_val)

Set object id.

Parameters
int$a_valobject id

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

Referenced by __construct().

89  {
90  $this->obj_id = $a_val;
91  }
+ Here is the caller graph for this function:

Field Documentation

◆ $content_activated

ilObjectTranslation::$content_activated = false
protected

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

Referenced by getContentActivated().

◆ $db

ilObjectTranslation::$db
protected

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

◆ $fallback_language

ilObjectTranslation::$fallback_language = ""
protected

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

Referenced by getFallbackLanguage().

◆ $instances

ilObjectTranslation::$instances = array()
staticprotected

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

◆ $languages

ilObjectTranslation::$languages = array()
protected

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

Referenced by getLanguages().

◆ $master_lang

ilObjectTranslation::$master_lang
protected

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

Referenced by getMasterLanguage().

◆ $obj_id

ilObjectTranslation::$obj_id
protected

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

Referenced by getObjId().


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