ILIAS  release_7 Revision v7.30-3-g800a261c036
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.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 12 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 32 of file class.ilMultilingualism.php.

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

33  {
34  global $DIC;
35 
36  $this->lng = $DIC->language();
37  $ilDB = $DIC->database();
38 
39  $this->db = $ilDB;
40 
41  $this->setObjId($a_obj_id);
42  $this->setType($a_type);
43 
44  if ($this->getObjId() <= 0) {
45  include_once("./Services/Object/exceptions/class.ilObjectException.php");
46  throw new ilObjectException("ilObjectTranslation: No object ID passed.");
47  }
48 
49  $this->read();
50  }
Base exception class for object service.
setObjId($a_val)
Set object id.
global $DIC
Definition: goto.php:24
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 146 of file class.ilMultilingualism.php.

Referenced by fromXML(), and read().

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  }
+ 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 285 of file class.ilMultilingualism.php.

References getLanguages(), and getType().

286  {
287  $target_ml = new self($a_obj_id, $this->getType());
288  $target_ml->setLanguages($this->getLanguages());
289  $target_ml->save();
290  return $target_ml;
291  }
getLanguages()
Get languages.
+ Here is the call graph for this function:

◆ delete()

ilMultilingualism::delete ( )

Delete.

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

250  {
251  $this->db->manipulate(
252  "DELETE FROM il_translations " .
253  " WHERE id = " . $this->db->quote($this->getObjId(), "integer") .
254  " AND id_type = " . $this->db->quote($this->getType(), "text")
255  );
256  }

◆ fromXML()

ilMultilingualism::fromXML ( SimpleXMLElement  $root)

xml import

Parameters
SimpleXMLElement$root
Returns
mixed

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

References addLanguage().

322  {
323  if ($root->translations) {
324  $root = $root->translations;
325  }
326 
327  foreach ($root->translation as $trans) {
328  $this->addLanguage(
329  (string) trim($trans["language"]),
330  (string) trim($trans->title),
331  (string) trim($trans->description),
332  (int) $trans["default"] != 0?true:false
333  );
334  }
335  }
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 193 of file class.ilMultilingualism.php.

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

◆ getDefaultLanguage()

ilMultilingualism::getDefaultLanguage ( )

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

References $lng.

Referenced by removeLanguage().

125  {
126  $lng = $this->lng;
127 
128  foreach ($this->languages as $k => $v) {
129  if ($v["lang_default"]) {
130  return $k;
131  }
132  }
133 
134  return $lng->getDefaultLanguage();
135  }
+ Here is the caller graph for this function:

◆ getDefaultTitle()

ilMultilingualism::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

165  {
166  foreach ($this->languages as $l) {
167  if ($l["lang_default"]) {
168  return $l["title"];
169  }
170  }
171  return "";
172  }

◆ 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 58 of file class.ilMultilingualism.php.

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

59  {
60  if (!isset(self::$instances[$a_type][$a_obj_id])) {
61  self::$instances[$a_type][$a_obj_id] = new self($a_obj_id, $a_type);
62  }
63 
64  return self::$instances[$a_type][$a_obj_id];
65  }
+ Here is the caller graph for this function:

◆ getLanguages()

ilMultilingualism::getLanguages ( )

Get languages.

Returns
array array of language codes

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

References $languages.

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

104  {
105  return $this->languages;
106  }
+ Here is the caller graph for this function:

◆ getObjId()

ilMultilingualism::getObjId ( )

Get object id.

Returns
int object id

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

References $obj_id.

Referenced by __construct().

84  {
85  return $this->obj_id;
86  }
+ Here is the caller graph for this function:

◆ getType()

ilMultilingualism::getType ( )
Returns
string

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

References $type.

Referenced by copy().

112  {
113  return $this->type;
114  }
+ Here is the caller graph for this function:

◆ read()

ilMultilingualism::read ( )

Read.

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

References addLanguage(), and setLanguages().

Referenced by __construct().

234  {
235  $this->setLanguages(array());
236  $set = $this->db->query(
237  "SELECT * FROM il_translations " .
238  " WHERE id = " . $this->db->quote($this->getObjId(), "integer") .
239  " AND id_type = " . $this->db->quote($this->getType(), "text")
240  );
241  while ($rec = $this->db->fetchAssoc($set)) {
242  $this->addLanguage($rec["lang_code"], $rec["title"], $rec["description"], $rec["lang_default"]);
243  }
244  }
setLanguages(array $a_val)
Set languages.
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 223 of file class.ilMultilingualism.php.

References getDefaultLanguage().

224  {
225  if ($a_lang != $this->getDefaultLanguage()) {
226  unset($this->languages[$a_lang]);
227  }
228  }
+ Here is the call graph for this function:

◆ save()

ilMultilingualism::save ( )

Save.

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

References getLanguages().

262  {
263  $this->delete();
264 
265  foreach ($this->getLanguages() as $l => $trans) {
266  $this->db->manipulate($t = "INSERT INTO il_translations " .
267  "(id, id_type, title, description, lang_code, lang_default) VALUES (" .
268  $this->db->quote($this->getObjId(), "integer") . "," .
269  $this->db->quote($this->getType(), "text") . "," .
270  $this->db->quote($trans["title"], "text") . "," .
271  $this->db->quote($trans["description"], "text") . "," .
272  $this->db->quote($l, "text") . "," .
273  $this->db->quote($trans["lang_default"], "integer") .
274  ")");
275  }
276  }
getLanguages()
Get languages.
+ Here is the call graph for this function:

◆ setDefaultDescription()

ilMultilingualism::setDefaultDescription (   $a_description)

Set default description.

Parameters
string$a_descriptiondescription

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

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

◆ setDefaultTitle()

ilMultilingualism::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

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

◆ setLanguages()

ilMultilingualism::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

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

Referenced by read().

94  {
95  $this->languages = $a_val;
96  }
+ Here is the caller graph for this function:

◆ setObjId()

ilMultilingualism::setObjId (   $a_val)

Set object id.

Parameters
int$a_valobject id

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

Referenced by __construct().

74  {
75  $this->obj_id = $a_val;
76  }
+ Here is the caller graph for this function:

◆ setType()

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

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

References $type.

Referenced by __construct().

120  {
121  $this->type = $type;
122  }
+ Here is the caller graph for this function:

◆ toXml()

ilMultilingualism::toXml ( ilXmlWriter  $writer)

Export.

Parameters
ilXmlWriter$writer
Returns
ilXmlWriter

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

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

301  {
302  $writer->xmlStartTag('translations');
303 
304  foreach ($this->getLanguages() as $k => $v) {
305  $writer->xmlStartTag('translation', array('language' => $k, 'default' => $v['lang_default'] ? 1 : 0));
306  $writer->xmlElement('title', array(), $v['title']);
307  $writer->xmlElement('description', array(), $v['description']);
308  $writer->xmlEndTag('translation');
309  }
310  $writer->xmlEndTag('translations');
311 
312  return $writer;
313  }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlEndTag($tag)
Writes an endtag.
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 19 of file class.ilMultilingualism.php.

◆ $instances

ilMultilingualism::$instances = array()
staticprotected

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

◆ $languages

ilMultilingualism::$languages = array()
protected

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

Referenced by getLanguages().

◆ $lng

ilMultilingualism::$lng
protected

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

Referenced by getDefaultLanguage().

◆ $obj_id

ilMultilingualism::$obj_id
protected

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

Referenced by getObjId().

◆ $type

ilMultilingualism::$type = ""
protected

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

Referenced by getType(), and setType().


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