ILIAS  release_4-4 Revision
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)
 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...
 
 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 getObjId(), read(), and setObjId().

45  {
46  global $ilDB;
47 
48  $this->db = $ilDB;
49 
50  $this->setObjId($a_obj_id);
51 
52  if ($this->getObjId() <= 0)
53  {
54  include_once("./Services/Object/exceptions/class.ilObjectException.php");
55  throw new ilObjectException("ilObjectTranslation: No object ID passed.");
56  }
57 
58  $this->read();
59  }
Base exception class for object service.
setObjId($a_val)
Set object id.
+ Here is the call graph for this function:

Member Function Documentation

◆ addLanguage()

ilObjectTranslation::addLanguage (   $a_lang,
  $a_title,
  $a_description,
  $a_default 
)

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.

Referenced by read().

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

References getLanguages(), and getMasterLanguage().

369  {
370  $target_ml = new ilObjectTranslation($a_obj_id);
371  $target_ml->setMasterLanguage($this->getMasterLanguage());
372  $target_ml->setLanguages($this->getLanguages());
373  $target_ml->save();
374  return $target_ml;
375  }
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 307 of file class.ilObjectTranslation.php.

308  {
309  $this->db->manipulate("DELETE FROM obj_content_master_lng ".
310  " WHERE obj_id = ".$this->db->quote($this->getObjId(), "integer")
311  );
312  }

◆ delete()

ilObjectTranslation::delete ( )

Delete.

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

295  {
296  $this->db->manipulate("DELETE FROM obj_content_master_lng ".
297  " WHERE obj_id = ".$this->db->quote($this->getObjId(), "integer")
298  );
299  $this->db->manipulate("DELETE FROM object_translation ".
300  " WHERE obj_id = ".$this->db->quote($this->getObjId(), "integer")
301  );
302  }

◆ getContentActivated()

ilObjectTranslation::getContentActivated ( )

Get activated for content.

Returns
bool activated for content?

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

201  {
202  foreach ($this->languages as $l)
203  {
204  if ($l["lang_default"])
205  {
206  return $l["description"];
207  }
208  }
209  return "";
210  }

◆ getDefaultTitle()

ilObjectTranslation::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

168  {
169  foreach ($this->languages as $l)
170  {
171  if ($l["lang_default"])
172  {
173  return $l["title"];
174  }
175  }
176  return "";
177  }

◆ 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 388 of file class.ilObjectTranslation.php.

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

389  {
390  $langs = $this->getLanguages();
391  if ($this->getContentActivated() &&
392  isset($langs[$a_lang]) &&
393  ilPageObject::_exists($a_parent_type, $this->getObjId(), $a_lang))
394  {
395  return $a_lang;
396  }
397  return "-";
398  }
static _exists($a_parent_type, $a_id, $a_lang="")
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

◆ 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(), and getEffectiveContentLang().

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

◆ read()

ilObjectTranslation::read ( )

Read.

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

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

Referenced by __construct().

267  {
268  $set = $this->db->query("SELECT * FROM obj_content_master_lng ".
269  " WHERE obj_id = ".$this->db->quote($this->getObjId(), "integer")
270  );
271  if ($rec = $this->db->fetchAssoc($set))
272  {
273  $this->setMasterLanguage($rec["master_lang"]);
274  $this->setContentActivated(true);
275  }
276  else
277  {
278  $this->setContentActivated(false);
279  }
280 
281  $this->setLanguages(array());
282  $set = $this->db->query("SELECT * FROM object_translation ".
283  " WHERE obj_id = ".$this->db->quote($this->getObjId(), "integer")
284  );
285  while ($rec = $this->db->fetchAssoc($set))
286  {
287  $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
288  }
289  }
addLanguage($a_lang, $a_title, $a_description, $a_default)
Add language.
setLanguages(array $a_val)
Set languages.
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 234 of file class.ilObjectTranslation.php.

References getMasterLanguage().

235  {
236  if ($a_lang != $this->getMasterLanguage())
237  {
238  unset($this->languages[$a_lang]);
239  }
240  }
getMasterLanguage()
Get master language.
+ Here is the call graph for this function:

◆ save()

ilObjectTranslation::save ( )

Save.

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

References getLanguages(), and getMasterLanguage().

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

Referenced by read().

249  {
250  $this->content_activated = $a_val;
251  }
+ Here is the caller graph for this function:

◆ setDefaultDescription()

ilObjectTranslation::setDefaultDescription (   $a_description)

Set default description.

Parameters
string$a_descriptiondescription

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

218  {
219  foreach ($this->languages as $k => $l)
220  {
221  if ($l["lang_default"])
222  {
223  $this->languages[$k]["description"] = $a_description;
224  }
225  }
226  }

◆ setDefaultTitle()

ilObjectTranslation::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

185  {
186  foreach ($this->languages as $k => $l)
187  {
188  if ($l["lang_default"])
189  {
190  $this->languages[$k]["title"] = $a_title;
191  }
192  }
193  }

◆ 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: