ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
 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
 

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
Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 29 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 44 of file class.ilObjectTranslation.php.

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

45  {
46  global $DIC;
47 
48  $ilDB = $DIC->database();
49 
50  $this->db = $ilDB;
51 
52  $this->setObjId($a_obj_id);
53 
54  if ($this->getObjId() <= 0) {
55  include_once("./Services/Object/exceptions/class.ilObjectException.php");
56  throw new ilObjectException("ilObjectTranslation: No object ID passed.");
57  }
58 
59  $this->read();
60  }
global $DIC
Definition: saml.php:7
Base exception class for object service.
setObjId($a_val)
Set object id.
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 146 of file class.ilObjectTranslation.php.

References $l.

Referenced by read().

147  {
148  if ($a_lang != "" && (!isset($this->languages[$a_lang]) || $a_force)) {
149  if ($a_default) {
150  foreach ($this->languages as $k => $l) {
151  $this->languages[$k]["lang_default"] = false;
152  }
153  }
154  $this->languages[$a_lang] = array("lang_code" => $a_lang, "lang_default" => $a_default,
155  "title" => $a_title, "description" => $a_description);
156  }
157  }
global $l
Definition: afr.php:30
+ 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 371 of file class.ilObjectTranslation.php.

References getLanguages(), and getMasterLanguage().

372  {
373  $target_ml = new ilObjectTranslation($a_obj_id);
374  $target_ml->setMasterLanguage($this->getMasterLanguage());
375  $target_ml->setLanguages($this->getLanguages());
376  $target_ml->save();
377  return $target_ml;
378  }
getMasterLanguage()
Get master 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 316 of file class.ilObjectTranslation.php.

317  {
318  $this->db->manipulate(
319  "DELETE FROM obj_content_master_lng " .
320  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
321  );
322  }

◆ delete()

ilObjectTranslation::delete ( )

Delete.

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

302  {
303  $this->db->manipulate(
304  "DELETE FROM obj_content_master_lng " .
305  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
306  );
307  $this->db->manipulate(
308  "DELETE FROM object_translation " .
309  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
310  );
311  }

◆ getContentActivated()

ilObjectTranslation::getContentActivated ( )

Get activated for content.

Returns
bool activated for content?

Definition at line 267 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 196 of file class.ilObjectTranslation.php.

References $l, ilObject\_lookupDescription(), and getObjId().

197  {
198  foreach ($this->languages as $l) {
199  if ($l["lang_default"]) {
200  return $l["description"];
201  }
202  }
203  if (count($this->languages) == 0) {
204  return ilObject::_lookupDescription($this->getObjId());
205  }
206  return "";
207  }
static _lookupDescription($a_id)
lookup object description
global $l
Definition: afr.php:30
+ Here is the call graph for this function:

◆ getDefaultLanguage()

ilObjectTranslation::getDefaultLanguage ( )

Get default language.

Returns
string default language

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

References $l.

229  {
230  foreach ($this->languages as $l) {
231  if ($l["lang_default"]) {
232  return $l["lang_code"];
233  }
234  }
235  return "";
236  }
global $l
Definition: afr.php:30

◆ getDefaultTitle()

ilObjectTranslation::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

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

165  {
166  foreach ($this->languages as $l) {
167  if ($l["lang_default"]) {
168  return $l["title"];
169  }
170  }
171  if (count($this->languages) == 0) {
172  return ilObject::_lookupTitle($this->getObjId());
173  }
174  return "";
175  }
static _lookupTitle($a_id)
lookup object title
global $l
Definition: afr.php:30
+ Here is the call 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 391 of file class.ilObjectTranslation.php.

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

392  {
393  $langs = $this->getLanguages();
394  if ($this->getContentActivated() &&
395  isset($langs[$a_lang]) &&
396  ilPageObject::_exists($a_parent_type, $this->getObjId(), $a_lang)) {
397  return $a_lang;
398  }
399  return "-";
400  }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
getContentActivated()
Get activated for content.
+ Here is the call 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 68 of file class.ilObjectTranslation.php.

Referenced by ilPageMultiLangGUI\__construct(), ilObjectTranslationGUI\__construct(), ilLMPresentationGUI\__construct(), ilContainer\__construct(), ilContainer\_exportContainerSettings(), ilStructureObject\_getPresentationTitle(), ilLMPageObject\_getPresentationTitle(), ilPageObjectGUI\addMultiLangActionsAndInfo(), ilObjContentObject\cloneObject(), ilContainer\create(), ilObjContentObjectGUI\executeCommand(), ilObjMediaPoolGUI\executeCommand(), ilObjContentObjectGUI\export(), ilObjMediaPoolGUI\export(), ilObjContentObject\exportHTML(), ilObjContentObjectGUI\exportHTML(), ilContainerGUI\getContainerPageHTML(), ilLMPresentationGUI\getLMPresentationTitle(), ilObjContentObjectGUI\getMultiLangHeader(), ilObjContentObjectGUI\getPropertiesFormValues(), ilObjContentObject\getPublicExportFiles(), ilObjectDataSet\importRecord(), ilMediaPoolImportGUI\importTranslation(), ilLMImportGUI\importTranslation(), ilMediaPoolImportGUI\initTranslationImportForm(), ilLMImportGUI\initTranslationImportForm(), ilObjContentObject\MDUpdateListener(), ilContainer\read(), and ilObjContentObjectGUI\saveProperties().

69  {
70  if (!isset(self::$instances[$a_obj_id])) {
71  self::$instances[$a_obj_id] = new ilObjectTranslation($a_obj_id);
72  }
73 
74  return self::$instances[$a_obj_id];
75  }
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 133 of file class.ilObjectTranslation.php.

References $languages.

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

134  {
135  return $this->languages;
136  }
+ Here is the caller graph for this function:

◆ getMasterLanguage()

ilObjectTranslation::getMasterLanguage ( )

Get master language.

Returns
string master language

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

References $master_lang.

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

114  {
115  return $this->master_lang;
116  }
+ Here is the caller graph for this function:

◆ getObjId()

ilObjectTranslation::getObjId ( )

Get object id.

Returns
int object id

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

References $obj_id.

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

94  {
95  return $this->obj_id;
96  }
+ Here is the caller graph for this function:

◆ read()

ilObjectTranslation::read ( )

Read.

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

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

Referenced by __construct().

276  {
277  $set = $this->db->query(
278  "SELECT * FROM obj_content_master_lng " .
279  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
280  );
281  if ($rec = $this->db->fetchAssoc($set)) {
282  $this->setMasterLanguage($rec["master_lang"]);
283  $this->setContentActivated(true);
284  } else {
285  $this->setContentActivated(false);
286  }
287 
288  $this->setLanguages(array());
289  $set = $this->db->query(
290  "SELECT * FROM object_translation " .
291  " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
292  );
293  while ($rec = $this->db->fetchAssoc($set)) {
294  $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
295  }
296  }
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.
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 244 of file class.ilObjectTranslation.php.

References getMasterLanguage().

245  {
246  if ($a_lang != $this->getMasterLanguage()) {
247  unset($this->languages[$a_lang]);
248  }
249  }
getMasterLanguage()
Get master language.
+ Here is the call graph for this function:

◆ save()

ilObjectTranslation::save ( )

Save.

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

References $l, $t, getLanguages(), and getMasterLanguage().

328  {
329  $this->delete();
330 
331  if ($this->getMasterLanguage() != "") {
332  $this->db->manipulate("INSERT INTO obj_content_master_lng " .
333  "(obj_id, master_lang) VALUES (" .
334  $this->db->quote($this->getObjId(), "integer") . "," .
335  $this->db->quote($this->getMasterLanguage(), "text") .
336  ")");
337 
338  // ensure that an entry for the master language exists and is the default
339  if (!isset($this->languages[$this->getMasterLanguage()])) {
340  $this->languages[$this->getMasterLanguage()] = array("title" => "",
341  "description" => "", "lang_code" => $this->getMasterLanguage(), "lang_default" => 1);
342  }
343  foreach ($this->languages as $l => $trans) {
344  if ($l == $this->getMasterLanguage()) {
345  $this->languages[$l]["lang_default"] = 1;
346  } else {
347  $this->languages[$l]["lang_default"] = 0;
348  }
349  }
350  }
351 
352  foreach ($this->getLanguages() as $l => $trans) {
353  $this->db->manipulate($t = "INSERT INTO object_translation " .
354  "(obj_id, title, description, lang_code, lang_default) VALUES (" .
355  $this->db->quote($this->getObjId(), "integer") . "," .
356  $this->db->quote($trans["title"], "text") . "," .
357  $this->db->quote($trans["description"], "text") . "," .
358  $this->db->quote($l, "text") . "," .
359  $this->db->quote($trans["lang_default"], "integer") .
360  ")");
361  }
362  }
getMasterLanguage()
Get master language.
global $l
Definition: afr.php:30
+ 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 257 of file class.ilObjectTranslation.php.

Referenced by read().

258  {
259  $this->content_activated = $a_val;
260  }
+ Here is the caller graph for this function:

◆ setDefaultDescription()

ilObjectTranslation::setDefaultDescription (   $a_description)

Set default description.

Parameters
string$a_descriptiondescription

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

References $l.

215  {
216  foreach ($this->languages as $k => $l) {
217  if ($l["lang_default"]) {
218  $this->languages[$k]["description"] = $a_description;
219  }
220  }
221  }
global $l
Definition: afr.php:30

◆ setDefaultTitle()

ilObjectTranslation::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

References $l.

183  {
184  foreach ($this->languages as $k => $l) {
185  if ($l["lang_default"]) {
186  $this->languages[$k]["title"] = $a_title;
187  }
188  }
189  }
global $l
Definition: afr.php:30

◆ setLanguages()

ilObjectTranslation::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

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

Referenced by read().

124  {
125  $this->languages = $a_val;
126  }
+ Here is the caller graph for this function:

◆ setMasterLanguage()

ilObjectTranslation::setMasterLanguage (   $a_val)

Set master language.

Parameters
string$a_valmaster language

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

Referenced by read().

104  {
105  $this->master_lang = $a_val;
106  }
+ Here is the caller graph for this function:

◆ setObjId()

ilObjectTranslation::setObjId (   $a_val)

Set object id.

Parameters
int$a_valobject id

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

Referenced by __construct().

84  {
85  $this->obj_id = $a_val;
86  }
+ Here is the caller graph for this function:

Field Documentation

◆ $content_activated

ilObjectTranslation::$content_activated = false
protected

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

Referenced by getContentActivated().

◆ $db

ilObjectTranslation::$db
protected

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

◆ $instances

ilObjectTranslation::$instances = array()
staticprotected

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

◆ $languages

ilObjectTranslation::$languages = array()
protected

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

Referenced by getLanguages().

◆ $master_lang

ilObjectTranslation::$master_lang
protected

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

Referenced by getMasterLanguage().

◆ $obj_id

ilObjectTranslation::$obj_id
protected

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

Referenced by getObjId().


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