36 $this->lng = $DIC->language();
37 $ilDB = $DIC->database();
45 include_once(
"./Services/Object/exceptions/class.ilObjectException.php");
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);
64 return self::$instances[$a_type][$a_obj_id];
75 $this->obj_id = $a_val;
95 $this->languages = $a_val;
128 foreach ($this->languages as $k => $v) {
129 if ($v[
"lang_default"]) {
134 return $lng->getDefaultLanguage();
146 public function addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force =
false)
148 if ($a_lang !=
"" && (!isset($this->languages[$a_lang]) || $a_force)) {
150 foreach ($this->languages as $k => $l) {
151 $this->languages[$k][
"lang_default"] =
false;
154 $this->languages[$a_lang] = array(
"lang_code" => $a_lang,
"lang_default" => $a_default,
155 "title" => $a_title,
"description" => $a_description);
166 foreach ($this->languages as $l) {
167 if ($l[
"lang_default"]) {
181 foreach ($this->languages as $k => $l) {
182 if ($l[
"lang_default"]) {
183 $this->languages[$k][
"title"] = $a_title;
195 foreach ($this->languages as $l) {
196 if ($l[
"lang_default"]) {
197 return $l[
"description"];
210 foreach ($this->languages as $k => $l) {
211 if ($l[
"lang_default"]) {
212 $this->languages[$k][
"description"] = $a_description;
226 unset($this->languages[$a_lang]);
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")
241 while ($rec = $this->db->fetchAssoc($set)) {
242 $this->
addLanguage($rec[
"lang_code"], $rec[
"title"], $rec[
"description"], $rec[
"lang_default"]);
249 public function delete()
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")
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") .
285 public function copy($a_obj_id)
287 $target_ml =
new self($a_obj_id, $this->
getType());
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']);
321 public function fromXML(SimpleXMLElement $root)
323 if ($root->translations) {
324 $root = $root->translations;
327 foreach ($root->translation as $trans) {
329 (
string) trim($trans[
"language"]),
330 (
string) trim($trans->title),
331 (
string) trim($trans->description),
332 (
int) $trans[
"default"] != 0?
true:
false static getInstance($a_obj_id, $a_type)
Get instance.
toXml(ilXmlWriter $writer)
Export.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
setLanguages(array $a_val)
Set languages.
fromXML(SimpleXMLElement $root)
xml import
Base exception class for object service.
setDefaultDescription($a_description)
Set default description.
getDefaultTitle()
Get default title.
xmlEndTag($tag)
Writes an endtag.
setObjId($a_val)
Set object id.
getDefaultDescription()
Get default description.
getLanguages()
Get languages.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
removeLanguage($a_lang)
Remove language.
setDefaultTitle($a_title)
Set default title.
__construct($a_obj_id, $a_type)
Constructor.
copy($a_obj_id)
Copy multilinguality settings.
Class handles translation mode for an object.
addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force=false)
Add language.