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.

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 }
Base exception class for object service.
setObjId($a_val)
Set object id.
global $DIC
Definition: saml.php:7
global $ilDB

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

+ 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.

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

References $l.

Referenced by read().

+ 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.

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 }
Class handles translation mode for an object.
getMasterLanguage()
Get master language.

References getLanguages(), and getMasterLanguage().

+ 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.

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

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

+ 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.

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

References $l.

◆ getDefaultTitle()

ilObjectTranslation::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

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

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

+ 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.

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 }
getContentActivated()
Get activated for content.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.

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

+ 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().

+ 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().

+ 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().

+ Here is the caller graph for this function:

◆ read()

ilObjectTranslation::read ( )

Read.

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

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 }
addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force=false)
Add language.
setLanguages(array $a_val)
Set languages.
setMasterLanguage($a_val)
Set master language.
setContentActivated($a_val)
Set activated for content.

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

Referenced by __construct().

+ 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.

245 {
246 if ($a_lang != $this->getMasterLanguage()) {
247 unset($this->languages[$a_lang]);
248 }
249 }

References getMasterLanguage().

+ Here is the call graph for this function:

◆ save()

ilObjectTranslation::save ( )

Save.

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

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 }

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

+ 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.

258 {
259 $this->content_activated = $a_val;
260 }

Referenced by read().

+ 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.

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

References $l.

◆ setDefaultTitle()

ilObjectTranslation::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

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

References $l.

◆ setLanguages()

ilObjectTranslation::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

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

124 {
125 $this->languages = $a_val;
126 }

Referenced by read().

+ 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.

104 {
105 $this->master_lang = $a_val;
106 }

Referenced by read().

+ 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.

84 {
85 $this->obj_id = $a_val;
86 }

Referenced by __construct().

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