ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMultilingualism Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilMultilingualism:

Public Member Functions

 setObjId (int $a_val)
 
 getObjId ()
 
 setLanguages (array $a_val)
 
 getLanguages ()
 
 getType ()
 
 setType (string $type)
 
 getDefaultLanguage ()
 
 addLanguage (string $a_lang, string $a_title, string $a_description, bool $a_default, bool $a_force=false)
 Add language. More...
 
 getDefaultTitle ()
 Get default title. More...
 
 setDefaultTitle (string $a_title)
 Set title for default language. More...
 
 getDefaultDescription ()
 
 setDefaultDescription (string $a_description)
 Set default description. More...
 
 removeLanguage (string $a_lang)
 
 read ()
 
 delete ()
 
 save ()
 
 copy (int $a_obj_id)
 Copy multilinguality settings. More...
 
 toXml (ilXmlWriter $writer)
 Export to xml. More...
 
 fromXML (SimpleXMLElement $root)
 xml import More...
 

Static Public Member Functions

static getInstance (int $a_obj_id, string $a_type)
 

Protected Attributes

ilLanguage $lng
 
ilDBInterface $db
 
int $obj_id
 
array $languages = []
 
string $type = ""
 

Static Protected Attributes

static array $instances = []
 

Private Member Functions

 __construct (int $a_obj_id, string $a_type)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class handles translation mode for an object.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilMultilingualism::__construct ( int  $a_obj_id,
string  $a_type 
)
private
Exceptions
ilObjectException

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

41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $ilDB = $DIC->database();
46
47 $this->db = $ilDB;
48
49 $this->setObjId($a_obj_id);
50 $this->setType($a_type);
51
52 if ($this->getObjId() <= 0) {
53 throw new ilObjectException("Translation: No object ID passed.");
54 }
55
56 $this->read();
57 }
Base exception class for object service.
global $DIC
Definition: shib_login.php:26

References $DIC, $ilDB, getObjId(), ILIAS\Repository\lng(), read(), setObjId(), and setType().

+ Here is the call graph for this function:

Member Function Documentation

◆ addLanguage()

ilMultilingualism::addLanguage ( string  $a_lang,
string  $a_title,
string  $a_description,
bool  $a_default,
bool  $a_force = false 
)

Add language.

Parameters
string$a_langlanguage
string$a_titletitle
string$a_descriptiondescription
bool$a_defaultdefault language?
bool$a_forceoverwrite existing

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

137 : void {
138 if ($a_lang !== "" && (!isset($this->languages[$a_lang]) || $a_force)) {
139 if ($a_default) {
140 foreach ($this->languages as $k => $l) {
141 $this->languages[$k]["lang_default"] = false;
142 }
143 }
144 $this->languages[$a_lang] = [
145 "lang_code" => $a_lang,
146 "lang_default" => $a_default,
147 "title" => $a_title,
148 "description" => $a_description
149 ];
150 }
151 }

◆ copy()

ilMultilingualism::copy ( int  $a_obj_id)

Copy multilinguality settings.

Exceptions
ilObjectException

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

263 : self
264 {
265 $target_ml = new self($a_obj_id, $this->getType());
266 $target_ml->setLanguages($this->getLanguages());
267 $target_ml->save();
268 return $target_ml;
269 }

◆ delete()

ilMultilingualism::delete ( )

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

233 : void
234 {
235 $this->db->manipulate(
236 "DELETE FROM il_dt_translations " .
237 " WHERE id = " . $this->db->quote($this->getObjId(), "integer") .
238 " AND id_type = " . $this->db->quote($this->getType(), "text")
239 );
240 }

◆ fromXML()

ilMultilingualism::fromXML ( SimpleXMLElement  $root)

xml import

Parameters
SimpleXMLElement$root

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

296 : void
297 {
298 if ($root->translations) {
299 $root = $root->translations;
300 }
301
302 foreach ($root->translation as $trans) {
303 $this->addLanguage(
304 trim($trans["language"]),
305 trim($trans->title),
306 trim($trans->description),
307 (int) $trans["default"] !== 0
308 );
309 }
310 }
addLanguage(string $a_lang, string $a_title, string $a_description, bool $a_default, bool $a_force=false)
Add language.

◆ getDefaultDescription()

ilMultilingualism::getDefaultDescription ( )
Returns
string description of default language

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

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

◆ getDefaultLanguage()

ilMultilingualism::getDefaultLanguage ( )

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

108 : string
109 {
111
112 foreach ($this->languages as $k => $v) {
113 if ($v["lang_default"]) {
114 return $k;
115 }
116 }
117
118 return $lng->getDefaultLanguage();
119 }
getDefaultLanguage()
Return default language.

References $lng, and ilLanguage\getDefaultLanguage().

+ Here is the call graph for this function:

◆ getDefaultTitle()

ilMultilingualism::getDefaultTitle ( )

Get default title.

Returns
string title of default language

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

157 : string
158 {
159 foreach ($this->languages as $l) {
160 if ($l["lang_default"]) {
161 return $l["title"];
162 }
163 }
164 return "";
165 }

◆ getInstance()

static ilMultilingualism::getInstance ( int  $a_obj_id,
string  $a_type 
)
static
Parameters
int$a_obj_id(repository) object id

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

62 : self
63 {
64 if (!isset(self::$instances[$a_type][$a_obj_id])) {
65 self::$instances[$a_type][$a_obj_id] = new self($a_obj_id, $a_type);
66 }
67
68 return self::$instances[$a_type][$a_obj_id];
69 }

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

+ Here is the caller graph for this function:

◆ getLanguages()

ilMultilingualism::getLanguages ( )
Returns
array<string, array{lang_code: string, lang_default: bool, title: string, description: string}>

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

93 : array
94 {
95 return $this->languages;
96 }

References $languages.

◆ getObjId()

ilMultilingualism::getObjId ( )

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

76 : int
77 {
78 return $this->obj_id;
79 }

References $obj_id.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ getType()

ilMultilingualism::getType ( )

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

98 : string
99 {
100 return $this->type;
101 }

References $type.

◆ read()

ilMultilingualism::read ( )

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

215 : void
216 {
217 $this->setLanguages(array());
218 $set = $this->db->query(
219 "SELECT * FROM il_dt_translations " .
220 " WHERE id = " . $this->db->quote($this->getObjId(), "integer") .
221 " AND id_type = " . $this->db->quote($this->getType(), "text")
222 );
223 while ($rec = $this->db->fetchAssoc($set)) {
224 $this->addLanguage(
225 $rec["lang_code"],
226 (string) $rec["title"],
227 (string) $rec["description"],
228 (bool) $rec["lang_default"]
229 );
230 }
231 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ removeLanguage()

ilMultilingualism::removeLanguage ( string  $a_lang)
Parameters
string$a_langlanguage code

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

208 : void
209 {
210 if ($a_lang !== $this->getDefaultLanguage()) {
211 unset($this->languages[$a_lang]);
212 }
213 }

◆ save()

ilMultilingualism::save ( )

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

242 : void
243 {
244 $this->delete();
245
246 foreach ($this->getLanguages() as $l => $trans) {
247 $this->db->manipulate($t = "INSERT INTO il_dt_translations " .
248 "(id, id_type, title, description, lang_code, lang_default) VALUES (" .
249 $this->db->quote($this->getObjId(), "integer") . "," .
250 $this->db->quote($this->getType(), "text") . "," .
251 $this->db->quote($trans["title"], "text") . "," .
252 $this->db->quote($trans["description"], "text") . "," .
253 $this->db->quote($l, "text") . "," .
254 $this->db->quote($trans["lang_default"], "integer") .
255 ")");
256 }
257 }

◆ setDefaultDescription()

ilMultilingualism::setDefaultDescription ( string  $a_description)

Set default description.

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

195 : void
196 {
197 foreach ($this->languages as $k => $l) {
198 if ($l["lang_default"]) {
199 $this->languages[$k]["description"] = $a_description;
200 }
201 }
202 }

◆ setDefaultTitle()

ilMultilingualism::setDefaultTitle ( string  $a_title)

Set title for default language.

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

170 : void
171 {
172 foreach ($this->languages as $k => $l) {
173 if ($l["lang_default"]) {
174 $this->languages[$k]["title"] = $a_title;
175 }
176 }
177 }

◆ setLanguages()

ilMultilingualism::setLanguages ( array  $a_val)
Parameters
array<string,array{lang_codestring, lang_default: bool, title: string, description: string}> $a_val
Returns
void

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

85 : void
86 {
87 $this->languages = $a_val;
88 }

◆ setObjId()

ilMultilingualism::setObjId ( int  $a_val)

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

71 : void
72 {
73 $this->obj_id = $a_val;
74 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setType()

ilMultilingualism::setType ( string  $type)

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

103 : void
104 {
105 $this->type = $type;
106 }

References $type.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ toXml()

ilMultilingualism::toXml ( ilXmlWriter  $writer)

Export to xml.

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

278 : ilXmlWriter {
279 $writer->xmlStartTag('translations');
280
281 foreach ($this->getLanguages() as $k => $v) {
282 $writer->xmlStartTag('translation', array('language' => $k, 'default' => $v['lang_default'] ? 1 : 0));
283 $writer->xmlElement('title', array(), $v['title']);
284 $writer->xmlElement('description', array(), $v['description']);
285 $writer->xmlEndTag('translation');
286 }
287 $writer->xmlEndTag('translations');
288
289 return $writer;
290 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.

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

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilMultilingualism::$db
protected

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

◆ $instances

array ilMultilingualism::$instances = []
staticprotected

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

◆ $languages

array ilMultilingualism::$languages = []
protected

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

Referenced by getLanguages().

◆ $lng

ilLanguage ilMultilingualism::$lng
protected

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

Referenced by getDefaultLanguage().

◆ $obj_id

int ilMultilingualism::$obj_id
protected

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

Referenced by getObjId().

◆ $type

string ilMultilingualism::$type = ""
protected

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

Referenced by getType(), and setType().


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