53 $this->lng = $DIC->language();
54 $ilDB = $DIC->database();
62 include_once(
"./Services/Object/exceptions/class.ilObjectException.php");
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);
81 return self::$instances[
$a_type][$a_obj_id];
92 $this->obj_id = $a_val;
112 $this->languages = $a_val;
145 foreach ($this->languages as $k => $v) {
146 if ($v[
"lang_default"]) {
151 return $lng->getDefaultLanguage();
163 public function addLanguage($a_lang, $a_title, $a_description, $a_default, $a_force =
false)
165 if ($a_lang !=
"" && (!isset($this->languages[$a_lang]) || $a_force)) {
167 foreach ($this->languages as $k =>
$l) {
168 $this->languages[$k][
"lang_default"] =
false;
171 $this->languages[$a_lang] = array(
"lang_code" => $a_lang,
"lang_default" => $a_default,
172 "title" => $a_title,
"description" => $a_description);
183 foreach ($this->languages as
$l) {
184 if ($l[
"lang_default"]) {
198 foreach ($this->languages as $k =>
$l) {
199 if (
$l[
"lang_default"]) {
200 $this->languages[$k][
"title"] = $a_title;
212 foreach ($this->languages as
$l) {
213 if ($l[
"lang_default"]) {
214 return $l[
"description"];
227 foreach ($this->languages as $k =>
$l) {
228 if (
$l[
"lang_default"]) {
229 $this->languages[$k][
"description"] = $a_description;
243 unset($this->languages[$a_lang]);
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")
258 while ($rec = $this->db->fetchAssoc($set)) {
259 $this->
addLanguage($rec[
"lang_code"], $rec[
"title"], $rec[
"description"], $rec[
"lang_default"]);
266 public function delete()
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")
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") .
302 public function copy($a_obj_id)
304 $target_ml =
new self($a_obj_id, $this->
getType());
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']);
340 if ($root->translations) {
341 $root = $root->translations;
344 foreach ($root->translation as $trans) {
346 (
string) trim($trans[
"language"]),
347 (
string) trim($trans->title),
348 (
string) trim($trans->description),
349 (
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.