ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilLMObjTranslation.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
17  protected $db;
18 
19  protected $lang;
20  protected $title;
21  protected $short_title;
22  protected $create_date;
23  protected $last_update;
24 
31  public function __construct($a_id = 0, $a_lang = "")
32  {
33  global $DIC;
34 
35  $this->db = $DIC->database();
36  if ($a_id > 0 && $a_lang != "") {
37  $this->setId($a_id);
38  $this->setLang($a_lang);
39  $this->read();
40  }
41  }
42 
48  public function setId($a_val)
49  {
50  $this->id = $a_val;
51  }
52 
58  public function getId()
59  {
60  return $this->id;
61  }
62 
68  public function setLang($a_val)
69  {
70  $this->lang = $a_val;
71  }
72 
78  public function getLang()
79  {
80  return $this->lang;
81  }
82 
88  public function setTitle($a_val)
89  {
90  $this->title = $a_val;
91  }
92 
98  public function getTitle()
99  {
100  return $this->title;
101  }
102 
108  public function setShortTitle($a_val)
109  {
110  $this->short_title = $a_val;
111  }
112 
118  public function getShortTitle()
119  {
120  return $this->short_title;
121  }
122 
128  public function getCreateDate()
129  {
130  return $this->create_date;
131  }
132 
138  public function getLastUpdate()
139  {
140  return $this->last_update;
141  }
142 
146  public function read()
147  {
148  $ilDB = $this->db;
149 
150  $set = $ilDB->query(
151  "SELECT * FROM lm_data_transl " .
152  " WHERE id = " . $ilDB->quote($this->getId(), "integer") .
153  " AND lang = " . $ilDB->quote($this->getLang(), "text")
154  );
155  $rec = $ilDB->fetchAssoc($set);
156  $this->setTitle($rec["title"]);
157  $this->setShortTitle($rec["short_title"]);
158  $this->create_date = $rec["create_date"];
159  $this->last_update = $rec["last_update"];
160  }
161 
165  public function save()
166  {
167  $ilDB = $this->db;
168 
169  if (!self::exists($this->getId(), $this->getLang())) {
170  $ilDB->manipulate("INSERT INTO lm_data_transl " .
171  "(id, lang, title, short_title, create_date, last_update) VALUES (" .
172  $ilDB->quote($this->getId(), "integer") . "," .
173  $ilDB->quote($this->getLang(), "text") . "," .
174  $ilDB->quote($this->getTitle(), "text") . "," .
175  $ilDB->quote($this->getShortTitle(), "text") . "," .
176  $ilDB->now() . "," .
177  $ilDB->now() .
178  ")");
179  } else {
180  $ilDB->manipulate(
181  "UPDATE lm_data_transl SET " .
182  " title = " . $ilDB->quote($this->getTitle(), "text") . "," .
183  " short_title = " . $ilDB->quote($this->getShortTitle(), "text") . "," .
184  " last_update = " . $ilDB->now() .
185  " WHERE id = " . $ilDB->quote($this->getId(), "integer") .
186  " AND lang = " . $ilDB->quote($this->getLang(), "text")
187  );
188  }
189  }
190 
198  public static function exists($a_id, $a_lang)
199  {
200  global $DIC;
201 
202  $ilDB = $DIC->database();
203 
204  $set = $ilDB->query(
205  "SELECT * FROM lm_data_transl " .
206  " WHERE id = " . $ilDB->quote($a_id, "integer") .
207  " AND lang = " . $ilDB->quote($a_lang, "text")
208  );
209  if ($rec = $ilDB->fetchAssoc($set)) {
210  return true;
211  }
212  return false;
213  }
214 
221  public static function copy($a_source_id, $a_target_id)
222  {
223  global $DIC;
224 
225  $ilDB = $DIC->database();
226 
227  $set = $ilDB->query(
228  "SELECT * FROM lm_data_transl " .
229  " WHERE id = " . $ilDB->quote($a_source_id, "integer")
230  );
231  while ($rec = $ilDB->fetchAssoc($set)) {
232  $lmobjtrans = new ilLMObjTranslation($a_target_id, $rec["lang"]);
233  $lmobjtrans->setTitle($rec["title"]);
234  $lmobjtrans->setShortTitle($rec["short_title"]);
235  $lmobjtrans->save();
236  }
237  }
238 }
getShortTitle()
Get short title.
setShortTitle($a_val)
Set short title.
global $DIC
Definition: saml.php:7
getCreateDate()
Get create date.
if(!array_key_exists('StateId', $_REQUEST)) $id
static exists($a_id, $a_lang)
Check for existence.
setTitle($a_val)
Set title.
global $ilDB
Translation information on lm object.
__construct($a_id=0, $a_lang="")
Constructor.
static copy($a_source_id, $a_target_id)
Copy all translations of an object.
save()
Save (inserts if not existing, otherwise updates)
getLastUpdate()
Get update date.