ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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

 $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 44 of file class.ilMultilingualism.php.

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

45  {
46  global $ilDB;
47 
48  $this->db = $ilDB;
49 
50  $this->setObjId($a_obj_id);
51  $this->setType($a_type);
52 
53  if ($this->getObjId() <= 0)
54  {
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.
$a_type
Definition: workflow.php:93
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 159 of file class.ilMultilingualism.php.

References $l, and array.

Referenced by fromXML(), and read().

160  {
161  if ($a_lang != "" && (!isset($this->languages[$a_lang]) || $a_force))
162  {
163  if ($a_default)
164  {
165  foreach ($this->languages as $k => $l)
166  {
167  $this->languages[$k]["lang_default"] = false;
168  }
169  }
170  $this->languages[$a_lang] = array("lang_code" => $a_lang, "lang_default" => $a_default,
171  "title" => $a_title, "description" => $a_description);
172  }
173  }
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 310 of file class.ilMultilingualism.php.

References getLanguages(), and getType().

311  {
312  $target_ml = new self($a_obj_id, $this->getType());
313  $target_ml->setLanguages($this->getLanguages());
314  $target_ml->save();
315  return $target_ml;
316  }
getLanguages()
Get languages.
+ Here is the call graph for this function:

◆ delete()

ilMultilingualism::delete ( )

Delete.

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

275  {
276  $this->db->manipulate("DELETE FROM il_translations ".
277  " WHERE id = ".$this->db->quote($this->getObjId(), "integer").
278  " AND id_type = " . $this->db->quote($this->getType(), "text")
279  );
280  }

◆ fromXML()

ilMultilingualism::fromXML ( SimpleXMLElement  $root)

xml import

Parameters
SimpleXMLElement$root
Returns
mixed

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

References addLanguage().

348  {
349  if($root->translations)
350  {
351  $root = $root->translations;
352  }
353 
354  foreach($root->translation as $trans)
355  {
356  $this->addLanguage(
357  (string)trim($trans["language"]),
358  (string)trim($trans->title),
359  (string)trim($trans->description),
360  (int)$trans["default"] != 0?true:false
361  );
362  }
363  }
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 213 of file class.ilMultilingualism.php.

References $l.

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

◆ getDefaultLanguage()

ilMultilingualism::getDefaultLanguage ( )

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

References $lng.

Referenced by removeLanguage().

136  {
137  global $lng;
138 
139  foreach($this->languages as $k => $v)
140  {
141  if($v["lang_default"])
142  {
143  return $k;
144  }
145  }
146 
147  return $lng->getDefaultLanguage();
148  }
global $lng
Definition: privfeed.php:17
+ Here is the caller graph for this function:

◆ getDefaultTitle()

ilMultilingualism::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

References $l.

181  {
182  foreach ($this->languages as $l)
183  {
184  if ($l["lang_default"])
185  {
186  return $l["title"];
187  }
188  }
189  return "";
190  }
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 68 of file class.ilMultilingualism.php.

References $a_type.

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

69  {
70  if (!isset(self::$instances[$a_type][$a_obj_id]))
71  {
72  self::$instances[$a_type][$a_obj_id] = new self($a_obj_id, $a_type);
73  }
74 
75  return self::$instances[$a_type][$a_obj_id];
76  }
$a_type
Definition: workflow.php:93
+ Here is the caller graph for this function:

◆ getLanguages()

ilMultilingualism::getLanguages ( )

Get languages.

Returns
array array of language codes

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

References $languages.

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

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

◆ getObjId()

ilMultilingualism::getObjId ( )

Get object id.

Returns
int object id

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

References $obj_id.

Referenced by __construct().

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

◆ getType()

ilMultilingualism::getType ( )
Returns
string

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

References $type.

Referenced by copy().

123  {
124  return $this->type;
125  }
+ Here is the caller graph for this function:

◆ read()

ilMultilingualism::read ( )

Read.

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

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

Referenced by __construct().

259  {
260  $this->setLanguages(array());
261  $set = $this->db->query("SELECT * FROM il_translations ".
262  " WHERE id = ".$this->db->quote($this->getObjId(), "integer") .
263  " AND id_type = " . $this->db->quote($this->getType(), "text")
264  );
265  while ($rec = $this->db->fetchAssoc($set))
266  {
267  $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
268  }
269  }
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 247 of file class.ilMultilingualism.php.

References getDefaultLanguage().

248  {
249  if($a_lang != $this->getDefaultLanguage())
250  {
251  unset($this->languages[$a_lang]);
252  }
253  }
+ Here is the call graph for this function:

◆ save()

ilMultilingualism::save ( )

Save.

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

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

286  {
287  $this->delete();
288 
289  foreach ($this->getLanguages() as $l => $trans)
290  {
291  $this->db->manipulate($t = "INSERT INTO il_translations ".
292  "(id, id_type, title, description, lang_code, lang_default) VALUES (".
293  $this->db->quote($this->getObjId(), "integer").",".
294  $this->db->quote($this->getType(), "text").",".
295  $this->db->quote($trans["title"], "text").",".
296  $this->db->quote($trans["description"], "text").",".
297  $this->db->quote($l, "text").",".
298  $this->db->quote($trans["lang_default"], "integer").
299  ")");
300  }
301  }
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 230 of file class.ilMultilingualism.php.

References $l.

231  {
232  foreach ($this->languages as $k => $l)
233  {
234  if ($l["lang_default"])
235  {
236  $this->languages[$k]["description"] = $a_description;
237  }
238  }
239  }
global $l
Definition: afr.php:30

◆ setDefaultTitle()

ilMultilingualism::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

References $l.

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

◆ setLanguages()

ilMultilingualism::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

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

Referenced by read().

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

◆ setObjId()

ilMultilingualism::setObjId (   $a_val)

Set object id.

Parameters
int$a_valobject id

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

Referenced by __construct().

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

◆ setType()

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

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

References $type.

Referenced by __construct().

131  {
132  $this->type = $type;
133  }
+ Here is the caller graph for this function:

◆ toXml()

ilMultilingualism::toXml ( ilXmlWriter  $writer)

Export.

Parameters
ilXmlWriter$writer
Returns
ilXmlWriter

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

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

326  {
327  $writer->xmlStartTag('translations');
328 
329  foreach ($this->getLanguages() as $k => $v)
330  {
331  $writer->xmlStartTag('translation',array('language' => $k, 'default' => $v['lang_default'] ? 1 : 0));
332  $writer->xmlElement('title',array(),$v['title']);
333  $writer->xmlElement('description', array(), $v['description']);
334  $writer->xmlEndTag('translation');
335  }
336  $writer->xmlEndTag('translations');
337 
338  return $writer;
339  }
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
xmlEndTag($tag)
Writes an endtag.
Create styles array
The data for the language used.
getLanguages()
Get languages.
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilMultilingualism::$db
protected

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

◆ $instances

ilMultilingualism::$instances = array()
staticprotected

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

◆ $languages

ilMultilingualism::$languages = array()
protected

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

Referenced by getLanguages().

◆ $obj_id

ilMultilingualism::$obj_id
protected

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

Referenced by getObjId().

◆ $type

ilMultilingualism::$type = ""
protected

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

Referenced by getType(), and setType().


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