ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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.

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

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

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

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 }

Referenced by fromXML(), and read().

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

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 }

References getLanguages(), and getType().

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

References getType().

+ Here is the call graph for this function:

◆ fromXML()

ilMultilingualism::fromXML ( SimpleXMLElement  $root)

xml import

Parameters
SimpleXMLElement$root
Returns
mixed

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

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.

References addLanguage().

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

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

◆ getDefaultLanguage()

ilMultilingualism::getDefaultLanguage ( )

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

142 {
144
145 foreach ($this->languages as $k => $v) {
146 if ($v["lang_default"]) {
147 return $k;
148 }
149 }
150
151 return $lng->getDefaultLanguage();
152 }

References $lng.

Referenced by removeLanguage().

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

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

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

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 }

References $a_type.

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

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

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

101 {
102 return $this->obj_id;
103 }

References $obj_id.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getType()

ilMultilingualism::getType ( )
Returns
string

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

129 {
130 return $this->type;
131 }

References $type.

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

+ Here is the caller graph for this function:

◆ read()

ilMultilingualism::read ( )

Read.

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

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.

References addLanguage(), and setLanguages().

Referenced by __construct().

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

241 {
242 if ($a_lang != $this->getDefaultLanguage()) {
243 unset($this->languages[$a_lang]);
244 }
245 }

References getDefaultLanguage().

+ Here is the call graph for this function:

◆ save()

ilMultilingualism::save ( )

Save.

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

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 }

References getLanguages(), and getType().

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

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

◆ setDefaultTitle()

ilMultilingualism::setDefaultTitle (   $a_title)

Set default title.

Parameters
string$a_titletitle

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

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

◆ setLanguages()

ilMultilingualism::setLanguages ( array  $a_val)

Set languages.

Parameters
array$a_valarray of language codes

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

111 {
112 $this->languages = $a_val;
113 }

Referenced by read().

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

91 {
92 $this->obj_id = $a_val;
93 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setType()

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

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

137 {
138 $this->type = $type;
139 }

References $type.

Referenced by __construct().

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

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 }
xmlEndTag($tag)
Writes an endtag.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.

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

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