ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLMObjTranslation.php
Go to the documentation of this file.
1<?php
2
25{
26 protected int $id = 0;
27 protected ilDBInterface $db;
28 protected string $lang = "";
29 protected string $title = "";
30 protected string $short_title = "";
31 protected string $create_date = "";
32 protected string $last_update = "";
33
34 public function __construct(
35 int $a_id = 0,
36 string $a_lang = ""
37 ) {
38 global $DIC;
39
40 $this->db = $DIC->database();
41 if ($a_id > 0 && $a_lang != "") {
42 $this->setId($a_id);
43 $this->setLang($a_lang);
44 $this->read();
45 }
46 }
47
48 public function setId(int $a_val): void
49 {
50 $this->id = $a_val;
51 }
52
53 public function getId(): int
54 {
55 return $this->id;
56 }
57
58 public function setLang(string $a_val): void
59 {
60 $this->lang = $a_val;
61 }
62
63 public function getLang(): string
64 {
65 return $this->lang;
66 }
67
68 public function setTitle(string $a_val): void
69 {
70 $this->title = $a_val;
71 }
72
73 public function getTitle(): string
74 {
75 return $this->title;
76 }
77
78 public function setShortTitle(string $a_val): void
79 {
80 $this->short_title = $a_val;
81 }
82
83 public function getShortTitle(): string
84 {
85 return $this->short_title;
86 }
87
88 public function getCreateDate(): string
89 {
90 return $this->create_date;
91 }
92
93 public function getLastUpdate(): string
94 {
95 return $this->last_update;
96 }
97
98 public function read(): void
99 {
101
102 $set = $ilDB->query(
103 "SELECT * FROM lm_data_transl " .
104 " WHERE id = " . $ilDB->quote($this->getId(), "integer") .
105 " AND lang = " . $ilDB->quote($this->getLang(), "text")
106 );
107 $rec = $ilDB->fetchAssoc($set);
108 $this->setTitle($rec["title"] ?? "");
109 $this->setShortTitle($rec["short_title"] ?? "");
110 $this->create_date = ($rec["create_date"] ?? 0);
111 $this->last_update = ($rec["last_update"] ?? 0);
112 }
113
114 public function save(): void
115 {
117
118 if (!self::exists($this->getId(), $this->getLang())) {
119 $ilDB->manipulate("INSERT INTO lm_data_transl " .
120 "(id, lang, title, short_title, create_date, last_update) VALUES (" .
121 $ilDB->quote($this->getId(), "integer") . "," .
122 $ilDB->quote($this->getLang(), "text") . "," .
123 $ilDB->quote($this->getTitle(), "text") . "," .
124 $ilDB->quote($this->getShortTitle(), "text") . "," .
125 $ilDB->now() . "," .
126 $ilDB->now() .
127 ")");
128 } else {
129 $ilDB->manipulate(
130 "UPDATE lm_data_transl SET " .
131 " title = " . $ilDB->quote($this->getTitle(), "text") . "," .
132 " short_title = " . $ilDB->quote($this->getShortTitle(), "text") . "," .
133 " last_update = " . $ilDB->now() .
134 " WHERE id = " . $ilDB->quote($this->getId(), "integer") .
135 " AND lang = " . $ilDB->quote($this->getLang(), "text")
136 );
137 }
138 }
139
143 public static function exists(
144 int $a_id,
145 string $a_lang
146 ): bool {
147 global $DIC;
148
149 $ilDB = $DIC->database();
150
151 $set = $ilDB->query(
152 "SELECT * FROM lm_data_transl " .
153 " WHERE id = " . $ilDB->quote($a_id, "integer") .
154 " AND lang = " . $ilDB->quote($a_lang, "text")
155 );
156 if ($rec = $ilDB->fetchAssoc($set)) {
157 return true;
158 }
159 return false;
160 }
161
165 public static function copy(
166 string $a_source_id,
167 string $a_target_id
168 ): void {
169 global $DIC;
170
171 $ilDB = $DIC->database();
172
173 $set = $ilDB->query(
174 "SELECT * FROM lm_data_transl " .
175 " WHERE id = " . $ilDB->quote($a_source_id, "integer")
176 );
177 while ($rec = $ilDB->fetchAssoc($set)) {
178 $lmobjtrans = new ilLMObjTranslation($a_target_id, $rec["lang"]);
179 $lmobjtrans->setTitle((string) $rec["title"]);
180 $lmobjtrans->setShortTitle((string) $rec["short_title"]);
181 $lmobjtrans->save();
182 }
183 }
184}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_id=0, string $a_lang="")
static copy(string $a_source_id, string $a_target_id)
Copy all translations of an object.
static exists(int $a_id, string $a_lang)
Check for existence.
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26