ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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...
 
 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 350 of file class.ilObjectTranslation.php.

351 {
352 $target_ml = new ilObjectTranslation($a_obj_id);
353 $target_ml->setMasterLanguage($this->getMasterLanguage());
354 $target_ml->setLanguages($this->getLanguages());
355 $target_ml->save();
356 return $target_ml;
357 }
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 295 of file class.ilObjectTranslation.php.

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

◆ delete()

ilObjectTranslation::delete ( )

Delete.

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

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

Get activated for content.

Returns
bool activated for content?

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

194 {
195 foreach ($this->languages as $l) {
196 if ($l["lang_default"]) {
197 return $l["description"];
198 }
199 }
200 return "";
201 }

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 return "";
172 }

References $l.

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

371 {
372 $langs = $this->getLanguages();
373 if ($this->getContentActivated() &&
374 isset($langs[$a_lang]) &&
375 ilPageObject::_exists($a_parent_type, $this->getObjId(), $a_lang)) {
376 return $a_lang;
377 }
378 return "-";
379 }
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()

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

+ Here is the caller graph for this function:

◆ read()

ilObjectTranslation::read ( )

Read.

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

255 {
256 $set = $this->db->query(
257 "SELECT * FROM obj_content_master_lng " .
258 " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
259 );
260 if ($rec = $this->db->fetchAssoc($set)) {
261 $this->setMasterLanguage($rec["master_lang"]);
262 $this->setContentActivated(true);
263 } else {
264 $this->setContentActivated(false);
265 }
266
267 $this->setLanguages(array());
268 $set = $this->db->query(
269 "SELECT * FROM object_translation " .
270 " WHERE obj_id = " . $this->db->quote($this->getObjId(), "integer")
271 );
272 while ($rec = $this->db->fetchAssoc($set)) {
273 $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
274 }
275 }
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 223 of file class.ilObjectTranslation.php.

224 {
225 if ($a_lang != $this->getMasterLanguage()) {
226 unset($this->languages[$a_lang]);
227 }
228 }

References getMasterLanguage().

+ Here is the call graph for this function:

◆ save()

ilObjectTranslation::save ( )

Save.

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

307 {
308 $this->delete();
309
310 if ($this->getMasterLanguage() != "") {
311 $this->db->manipulate("INSERT INTO obj_content_master_lng " .
312 "(obj_id, master_lang) VALUES (" .
313 $this->db->quote($this->getObjId(), "integer") . "," .
314 $this->db->quote($this->getMasterLanguage(), "text") .
315 ")");
316
317 // ensure that an entry for the master language exists and is the default
318 if (!isset($this->languages[$this->getMasterLanguage()])) {
319 $this->languages[$this->getMasterLanguage()] = array("title" => "",
320 "description" => "", "lang_code" => $this->getMasterLanguage(), "lang_default" => 1);
321 }
322 foreach ($this->languages as $l => $trans) {
323 if ($l == $this->getMasterLanguage()) {
324 $this->languages[$l]["lang_default"] = 1;
325 } else {
326 $this->languages[$l]["lang_default"] = 0;
327 }
328 }
329 }
330
331 foreach ($this->getLanguages() as $l => $trans) {
332 $this->db->manipulate($t = "INSERT INTO object_translation " .
333 "(obj_id, title, description, lang_code, lang_default) VALUES (" .
334 $this->db->quote($this->getObjId(), "integer") . "," .
335 $this->db->quote($trans["title"], "text") . "," .
336 $this->db->quote($trans["description"], "text") . "," .
337 $this->db->quote($l, "text") . "," .
338 $this->db->quote($trans["lang_default"], "integer") .
339 ")");
340 }
341 }

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

237 {
238 $this->content_activated = $a_val;
239 }

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

209 {
210 foreach ($this->languages as $k => $l) {
211 if ($l["lang_default"]) {
212 $this->languages[$k]["description"] = $a_description;
213 }
214 }
215 }

References $l.

◆ setDefaultTitle()

ilObjectTranslation::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

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

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: