ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMultilingualism Class Reference

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

+ Collaboration diagram for ilMultilingualism:

Public Member Functions

 setObjId ($a_val)
 Set object id. More...
 
 getObjId ()
 Get object id. More...
 
 setLanguages (array $a_val)
 Set languages. More...
 
 getLanguages ()
 Get languages. More...
 
 getType ()
 
 setType ($type)
 
 getDefaultLanguage ()
 
 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...
 
 read ()
 Read. More...
 
 delete ()
 Delete. More...
 
 save ()
 Save. More...
 
 copy ($a_obj_id)
 Copy multilinguality settings. More...
 
 toXml (ilXmlWriter $writer)
 Export. More...
 
 fromXML (SimpleXMLElement $root)
 xml import More...
 

Static Public Member Functions

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

Protected Attributes

 $lng
 
 $db
 
 $obj_id
 
 $languages = array()
 
 $type = ""
 

Static Protected Attributes

static $instances = array()
 

Private Member Functions

 __construct ($a_obj_id, $a_type)
 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.ilMultilingualism.php.

Constructor & Destructor Documentation

◆ __construct()

ilMultilingualism::__construct (   $a_obj_id,
  $a_type 
)
private

Constructor.

Parameters
int$a_obj_idobject id
string$a_typeid type
Exceptions
ilObjectException

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

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

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

Member Function Documentation

◆ addLanguage()

ilMultilingualism::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 163 of file class.ilMultilingualism.php.

References $l, and array.

Referenced by fromXML(), and read().

164  {
165  if ($a_lang != "" && (!isset($this->languages[$a_lang]) || $a_force)) {
166  if ($a_default) {
167  foreach ($this->languages as $k => $l) {
168  $this->languages[$k]["lang_default"] = false;
169  }
170  }
171  $this->languages[$a_lang] = array("lang_code" => $a_lang, "lang_default" => $a_default,
172  "title" => $a_title, "description" => $a_description);
173  }
174  }
Create styles array
The data for the language used.
global $l
Definition: afr.php:30
+ Here is the caller graph for this function:

◆ copy()

ilMultilingualism::copy (   $a_obj_id)

Copy multilinguality settings.

Parameters
string$a_typeparent object type
int$a_obj_idparent object id
Returns
ilObjectTranslation target multilang object

Definition at line 302 of file class.ilMultilingualism.php.

References getLanguages(), and getType().

303  {
304  $target_ml = new self($a_obj_id, $this->getType());
305  $target_ml->setLanguages($this->getLanguages());
306  $target_ml->save();
307  return $target_ml;
308  }
getLanguages()
Get languages.
+ Here is the call graph for this function:

◆ delete()

ilMultilingualism::delete ( )

Delete.

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

267  {
268  $this->db->manipulate(
269  "DELETE FROM il_translations " .
270  " WHERE id = " . $this->db->quote($this->getObjId(), "integer") .
271  " AND id_type = " . $this->db->quote($this->getType(), "text")
272  );
273  }

◆ fromXML()

ilMultilingualism::fromXML ( SimpleXMLElement  $root)

xml import

Parameters
SimpleXMLElement$root
Returns
mixed

Definition at line 338 of file class.ilMultilingualism.php.

References addLanguage().

339  {
340  if ($root->translations) {
341  $root = $root->translations;
342  }
343 
344  foreach ($root->translation as $trans) {
345  $this->addLanguage(
346  (string) trim($trans["language"]),
347  (string) trim($trans->title),
348  (string) trim($trans->description),
349  (int) $trans["default"] != 0?true:false
350  );
351  }
352  }
addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force=false)
Add language.
+ Here is the call graph for this function:

◆ getDefaultDescription()

ilMultilingualism::getDefaultDescription ( )

Get default description.

Returns
string description of default language

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

References $l.

211  {
212  foreach ($this->languages as $l) {
213  if ($l["lang_default"]) {
214  return $l["description"];
215  }
216  }
217  return "";
218  }
global $l
Definition: afr.php:30

◆ getDefaultLanguage()

ilMultilingualism::getDefaultLanguage ( )

Definition at line 141 of file class.ilMultilingualism.php.

References $lng.

Referenced by removeLanguage().

142  {
143  $lng = $this->lng;
144 
145  foreach ($this->languages as $k => $v) {
146  if ($v["lang_default"]) {
147  return $k;
148  }
149  }
150 
151  return $lng->getDefaultLanguage();
152  }
+ Here is the caller graph for this function:

◆ getDefaultTitle()

ilMultilingualism::getDefaultTitle ( )

Get default title.

Returns
string title of default language

Definition at line 181 of file class.ilMultilingualism.php.

References $l.

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

◆ getInstance()

static ilMultilingualism::getInstance (   $a_obj_id,
  $a_type 
)
static

Get instance.

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

Definition at line 75 of file class.ilMultilingualism.php.

References $a_type.

Referenced by ilMultilingualismGUI\__construct(), ilDidacticTemplateSetting\getTranslationObject(), and ilDidacticTemplateImport\parseSettings().

76  {
77  if (!isset(self::$instances[$a_type][$a_obj_id])) {
78  self::$instances[$a_type][$a_obj_id] = new self($a_obj_id, $a_type);
79  }
80 
81  return self::$instances[$a_type][$a_obj_id];
82  }
$a_type
Definition: workflow.php:92
+ Here is the caller graph for this function:

◆ getLanguages()

ilMultilingualism::getLanguages ( )

Get languages.

Returns
array array of language codes

Definition at line 120 of file class.ilMultilingualism.php.

References $languages.

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

121  {
122  return $this->languages;
123  }
+ Here is the caller graph for this function:

◆ getObjId()

ilMultilingualism::getObjId ( )

Get object id.

Returns
int object id

Definition at line 100 of file class.ilMultilingualism.php.

References $obj_id.

Referenced by __construct().

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

◆ getType()

ilMultilingualism::getType ( )
Returns
string

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

References $type.

Referenced by copy().

129  {
130  return $this->type;
131  }
+ Here is the caller graph for this function:

◆ read()

ilMultilingualism::read ( )

Read.

Definition at line 250 of file class.ilMultilingualism.php.

References addLanguage(), array, and setLanguages().

Referenced by __construct().

251  {
252  $this->setLanguages(array());
253  $set = $this->db->query(
254  "SELECT * FROM il_translations " .
255  " WHERE id = " . $this->db->quote($this->getObjId(), "integer") .
256  " AND id_type = " . $this->db->quote($this->getType(), "text")
257  );
258  while ($rec = $this->db->fetchAssoc($set)) {
259  $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
260  }
261  }
setLanguages(array $a_val)
Set languages.
Create styles array
The data for the language used.
addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force=false)
Add language.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeLanguage()

ilMultilingualism::removeLanguage (   $a_lang)

Remove language.

Parameters
string$a_langlanguage code

Definition at line 240 of file class.ilMultilingualism.php.

References getDefaultLanguage().

241  {
242  if ($a_lang != $this->getDefaultLanguage()) {
243  unset($this->languages[$a_lang]);
244  }
245  }
+ Here is the call graph for this function:

◆ save()

ilMultilingualism::save ( )

Save.

Definition at line 278 of file class.ilMultilingualism.php.

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

279  {
280  $this->delete();
281 
282  foreach ($this->getLanguages() as $l => $trans) {
283  $this->db->manipulate($t = "INSERT INTO il_translations " .
284  "(id, id_type, title, description, lang_code, lang_default) VALUES (" .
285  $this->db->quote($this->getObjId(), "integer") . "," .
286  $this->db->quote($this->getType(), "text") . "," .
287  $this->db->quote($trans["title"], "text") . "," .
288  $this->db->quote($trans["description"], "text") . "," .
289  $this->db->quote($l, "text") . "," .
290  $this->db->quote($trans["lang_default"], "integer") .
291  ")");
292  }
293  }
getLanguages()
Get languages.
global $l
Definition: afr.php:30
+ Here is the call graph for this function:

◆ setDefaultDescription()

ilMultilingualism::setDefaultDescription (   $a_description)

Set default description.

Parameters
string$a_descriptiondescription

Definition at line 225 of file class.ilMultilingualism.php.

References $l.

226  {
227  foreach ($this->languages as $k => $l) {
228  if ($l["lang_default"]) {
229  $this->languages[$k]["description"] = $a_description;
230  }
231  }
232  }
global $l
Definition: afr.php:30

◆ setDefaultTitle()

ilMultilingualism::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

Definition at line 196 of file class.ilMultilingualism.php.

References $l.

197  {
198  foreach ($this->languages as $k => $l) {
199  if ($l["lang_default"]) {
200  $this->languages[$k]["title"] = $a_title;
201  }
202  }
203  }
global $l
Definition: afr.php:30

◆ setLanguages()

ilMultilingualism::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

Definition at line 110 of file class.ilMultilingualism.php.

Referenced by read().

111  {
112  $this->languages = $a_val;
113  }
+ Here is the caller graph for this function:

◆ setObjId()

ilMultilingualism::setObjId (   $a_val)

Set object id.

Parameters
int$a_valobject id

Definition at line 90 of file class.ilMultilingualism.php.

Referenced by __construct().

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

◆ setType()

ilMultilingualism::setType (   $type)
Parameters
string$type

Definition at line 136 of file class.ilMultilingualism.php.

References $type.

Referenced by __construct().

137  {
138  $this->type = $type;
139  }
+ Here is the caller graph for this function:

◆ toXml()

ilMultilingualism::toXml ( ilXmlWriter  $writer)

Export.

Parameters
ilXmlWriter$writer
Returns
ilXmlWriter

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

References array, getLanguages(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

318  {
319  $writer->xmlStartTag('translations');
320 
321  foreach ($this->getLanguages() as $k => $v) {
322  $writer->xmlStartTag('translation', array('language' => $k, 'default' => $v['lang_default'] ? 1 : 0));
323  $writer->xmlElement('title', array(), $v['title']);
324  $writer->xmlElement('description', array(), $v['description']);
325  $writer->xmlEndTag('translation');
326  }
327  $writer->xmlEndTag('translations');
328 
329  return $writer;
330  }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlEndTag($tag)
Writes an endtag.
Create styles array
The data for the language used.
getLanguages()
Get languages.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilMultilingualism::$db
protected

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

◆ $instances

ilMultilingualism::$instances = array()
staticprotected

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

◆ $languages

ilMultilingualism::$languages = array()
protected

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

Referenced by getLanguages().

◆ $lng

ilMultilingualism::$lng
protected

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

Referenced by getDefaultLanguage().

◆ $obj_id

ilMultilingualism::$obj_id
protected

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

Referenced by getObjId().

◆ $type

ilMultilingualism::$type = ""
protected

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

Referenced by getType(), and setType().


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