ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 $title = ilStr::substr($this->getTitle(), 0, 200);
119 if (!self::exists($this->getId(), $this->getLang())) {
120 $ilDB->manipulate("INSERT INTO lm_data_transl " .
121 "(id, lang, title, short_title, create_date, last_update) VALUES (" .
122 $ilDB->quote($this->getId(), "integer") . "," .
123 $ilDB->quote($this->getLang(), "text") . "," .
124 $ilDB->quote($title, "text") . "," .
125 $ilDB->quote($this->getShortTitle(), "text") . "," .
126 $ilDB->now() . "," .
127 $ilDB->now() .
128 ")");
129 } else {
130 $ilDB->manipulate(
131 "UPDATE lm_data_transl SET " .
132 " title = " . $ilDB->quote($title, "text") . "," .
133 " short_title = " . $ilDB->quote($this->getShortTitle(), "text") . "," .
134 " last_update = " . $ilDB->now() .
135 " WHERE id = " . $ilDB->quote($this->getId(), "integer") .
136 " AND lang = " . $ilDB->quote($this->getLang(), "text")
137 );
138 }
139 }
140
144 public static function exists(
145 int $a_id,
146 string $a_lang
147 ): bool {
148 global $DIC;
149
150 $ilDB = $DIC->database();
151
152 $set = $ilDB->query(
153 "SELECT * FROM lm_data_transl " .
154 " WHERE id = " . $ilDB->quote($a_id, "integer") .
155 " AND lang = " . $ilDB->quote($a_lang, "text")
156 );
157 if ($rec = $ilDB->fetchAssoc($set)) {
158 return true;
159 }
160 return false;
161 }
162
166 public static function copy(
167 string $a_source_id,
168 string $a_target_id
169 ): void {
170 global $DIC;
171
172 $ilDB = $DIC->database();
173
174 $set = $ilDB->query(
175 "SELECT * FROM lm_data_transl " .
176 " WHERE id = " . $ilDB->quote($a_source_id, "integer")
177 );
178 while ($rec = $ilDB->fetchAssoc($set)) {
179 $lmobjtrans = new ilLMObjTranslation($a_target_id, $rec["lang"]);
180 $lmobjtrans->setTitle((string) $rec["title"]);
181 $lmobjtrans->setShortTitle((string) $rec["short_title"]);
182 $lmobjtrans->save();
183 }
184 }
185}
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