ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPageMultiLang.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
14  protected $db;
15  protected $parent_type;
16  protected $parent_id;
17  protected $master_lang;
18  protected $languages = array();
19  protected $activated = false;
20 
28  public function __construct($a_parent_type, $a_parent_id)
29  {
30  global $DIC;
31 
32  $ilDB = $DIC->database();
33 
34  $this->db = $ilDB;
35 
36  $this->setParentType($a_parent_type);
37  $this->setParentId($a_parent_id);
38 
39  if ($this->getParentType() == "") {
40  include_once("./Services/COPage/exceptions/class.ilCOPageException.php");
41  throw new ilCOPageException("ilPageMultiLang: No parent type passed.");
42  }
43 
44  if ($this->getParentId() <= 0) {
45  include_once("./Services/COPage/exceptions/class.ilCOPageException.php");
46  throw new ilCOPageException("ilPageMultiLang: No parent ID passed.");
47  }
48 
49  $this->read();
50  }
51 
57  public function setParentType($a_val)
58  {
59  $this->parent_type = $a_val;
60  }
61 
67  public function getParentType()
68  {
69  return $this->parent_type;
70  }
71 
77  public function setParentId($a_val)
78  {
79  $this->parent_id = $a_val;
80  }
81 
87  public function getParentId()
88  {
89  return $this->parent_id;
90  }
91 
97  public function setMasterLanguage($a_val)
98  {
99  $this->master_lang = $a_val;
100  }
101 
107  public function getMasterLanguage()
108  {
109  return $this->master_lang;
110  }
111 
117  public function setLanguages(array $a_val)
118  {
119  $this->languages = $a_val;
120  }
121 
127  public function getLanguages()
128  {
129  return $this->languages;
130  }
131 
137  public function addLanguage($a_lang)
138  {
139  if ($a_lang != "" && !in_array($a_lang, $this->languages)) {
140  $this->languages[] = $a_lang;
141  }
142  }
143 
144 
150  protected function setActivated($a_val)
151  {
152  $this->activated = $a_val;
153  }
154 
160  public function getActivated()
161  {
162  return $this->activated;
163  }
164 
168  public function read()
169  {
170  $set = $this->db->query(
171  "SELECT * FROM copg_multilang " .
172  " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
173  " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
174  );
175  if ($rec = $this->db->fetchAssoc($set)) {
176  $this->setMasterLanguage($rec["master_lang"]);
177  $this->setActivated(true);
178  } else {
179  $this->setActivated(false);
180  }
181 
182  $this->setLanguages(array());
183  $set = $this->db->query(
184  "SELECT * FROM copg_multilang_lang " .
185  " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
186  " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
187  );
188  while ($rec = $this->db->fetchAssoc($set)) {
189  $this->addLanguage($rec["lang"]);
190  }
191  }
192 
196  public function delete()
197  {
198  $this->db->manipulate(
199  "DELETE FROM copg_multilang " .
200  " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
201  " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
202  );
203  $this->db->manipulate(
204  "DELETE FROM copg_multilang_lang " .
205  " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
206  " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
207  );
208  }
209 
213  public function save()
214  {
215  $this->delete();
216 
217  $this->db->manipulate("INSERT INTO copg_multilang " .
218  "(parent_type, parent_id, master_lang) VALUES (" .
219  $this->db->quote($this->getParentType(), "text") . "," .
220  $this->db->quote($this->getParentId(), "integer") . "," .
221  $this->db->quote($this->getMasterLanguage(), "text") .
222  ")");
223 
224  foreach ($this->getLanguages() as $lang) {
225  $this->db->manipulate("INSERT INTO copg_multilang_lang " .
226  "(parent_type, parent_id, lang) VALUES (" .
227  $this->db->quote($this->getParentType(), "text") . "," .
228  $this->db->quote($this->getParentId(), "integer") . "," .
229  $this->db->quote($lang, "text") .
230  ")");
231  }
232  }
233 
241  public function copy($a_target_parent_type, $a_target_parent_id)
242  {
243  if ($this->getActivated()) {
244  $target_ml = new ilPageMultiLang($a_target_parent_type, $a_target_parent_id);
245  $target_ml->setMasterLanguage($this->getMasterLanguage());
246  $target_ml->setLanguages($this->getLanguages());
247  $target_ml->save();
248  return $target_ml;
249  }
250 
251  return null;
252  }
253 
254 
264  public function getEffectiveLang($a_lang)
265  {
266  if ($this->getActivated() &&
267  in_array($a_lang, $this->getLanguages()) &&
268  ilPageObject::_exists($this->getParentType(), $this->getParentId(), $a_lang)) {
269  return $a_lang;
270  }
271  return "-";
272  }
273 }
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Multi-language properties.
global $DIC
Definition: saml.php:7
setParentType($a_val)
Set parent type.
addLanguage($a_lang)
Add language.
getMasterLanguage()
Get master language.
setMasterLanguage($a_val)
Set master language.
getParentId()
Get parent id.
setParentId($a_val)
Set parent id.
setActivated($a_val)
Set activated.
Create styles array
The data for the language used.
__construct($a_parent_type, $a_parent_id)
Constructor.
getActivated()
Get activated.
global $ilDB
getParentType()
Get parent type.
setLanguages(array $a_val)
Set languages.
getEffectiveLang($a_lang)
Get effective language for given language.
getLanguages()
Get languages.
copy($a_target_parent_type, $a_target_parent_id)
Copy multilinguality settings.
Base exception class for copage service.