ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 function __construct($a_parent_type, $a_parent_id)
29 {
30 global $ilDB;
31
32 $this->db = $ilDB;
33
34 $this->setParentType($a_parent_type);
35 $this->setParentId($a_parent_id);
36
37 if ($this->getParentType() == "")
38 {
39 include_once("./Services/COPage/exceptions/class.ilCOPageException.php");
40 throw new ilCOPageException("ilPageMultiLang: No parent type passed.");
41 }
42
43 if ($this->getParentId() <= 0)
44 {
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 function setParentType($a_val)
58 {
59 $this->parent_type = $a_val;
60 }
61
67 function getParentType()
68 {
69 return $this->parent_type;
70 }
71
77 function setParentId($a_val)
78 {
79 $this->parent_id = $a_val;
80 }
81
87 function getParentId()
88 {
89 return $this->parent_id;
90 }
91
97 function setMasterLanguage($a_val)
98 {
99 $this->master_lang = $a_val;
100 }
101
108 {
109 return $this->master_lang;
110 }
111
117 function setLanguages(array $a_val)
118 {
119 $this->languages = $a_val;
120 }
121
127 function getLanguages()
128 {
129 return $this->languages;
130 }
131
137 function addLanguage($a_lang)
138 {
139 if ($a_lang != "" && !in_array($a_lang, $this->languages))
140 {
141 $this->languages[] = $a_lang;
142 }
143 }
144
145
151 protected function setActivated($a_val)
152 {
153 $this->activated = $a_val;
154 }
155
161 function getActivated()
162 {
163 return $this->activated;
164 }
165
169 function read()
170 {
171 $set = $this->db->query("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 {
177 $this->setMasterLanguage($rec["master_lang"]);
178 $this->setActivated(true);
179 }
180 else
181 {
182 $this->setActivated(false);
183 }
184
185 $this->setLanguages(array());
186 $set = $this->db->query("SELECT * FROM copg_multilang_lang ".
187 " WHERE parent_type = ".$this->db->quote($this->getParentType(), "text").
188 " AND parent_id = ".$this->db->quote($this->getParentId(), "integer")
189 );
190 while ($rec = $this->db->fetchAssoc($set))
191 {
192 $this->addLanguage($rec["lang"]);
193 }
194 }
195
199 function delete()
200 {
201 $this->db->manipulate("DELETE FROM copg_multilang ".
202 " WHERE parent_type = ".$this->db->quote($this->getParentType(), "text").
203 " AND parent_id = ".$this->db->quote($this->getParentId(), "integer")
204 );
205 $this->db->manipulate("DELETE FROM copg_multilang_lang ".
206 " WHERE parent_type = ".$this->db->quote($this->getParentType(), "text").
207 " AND parent_id = ".$this->db->quote($this->getParentId(), "integer")
208 );
209 }
210
214 function save()
215 {
216 $this->delete();
217
218 $this->db->manipulate("INSERT INTO copg_multilang ".
219 "(parent_type, parent_id, master_lang) VALUES (".
220 $this->db->quote($this->getParentType(), "text").",".
221 $this->db->quote($this->getParentId(), "integer").",".
222 $this->db->quote($this->getMasterLanguage(), "text").
223 ")");
224
225 foreach ($this->getLanguages() as $lang)
226 {
227 $this->db->manipulate("INSERT INTO copg_multilang_lang ".
228 "(parent_type, parent_id, lang) VALUES (".
229 $this->db->quote($this->getParentType(), "text").",".
230 $this->db->quote($this->getParentId(), "integer").",".
231 $this->db->quote($lang, "text").
232 ")");
233 }
234 }
235
243 function copy($a_target_parent_type, $a_target_parent_id)
244 {
245 if ($this->getActivated())
246 {
247 $target_ml = new ilPageMultiLang($a_target_parent_type, $a_target_parent_id);
248 $target_ml->setMasterLanguage($this->getMasterLanguage());
249 $target_ml->setLanguages($this->getLanguages());
250 $target_ml->save();
251 return $target_ml;
252 }
253
254 return null;
255 }
256
257
267 function getEffectiveLang($a_lang)
268 {
269 if ($this->getActivated() &&
270 in_array($a_lang, $this->getLanguages()) &&
271 ilPageObject::_exists($this->getParentType(), $this->getParentId(), $a_lang))
272 {
273 return $a_lang;
274 }
275 return "-";
276 }
277
278
279}
280
281?>
Base exception class for copage service.
Multi-language properties.
getLanguages()
Get languages.
setParentId($a_val)
Set parent id.
setActivated($a_val)
Set activated.
copy($a_target_parent_type, $a_target_parent_id)
Copy multilinguality settings.
setLanguages(array $a_val)
Set languages.
getParentType()
Get parent type.
getMasterLanguage()
Get master language.
addLanguage($a_lang)
Add language.
getParentId()
Get parent id.
setMasterLanguage($a_val)
Set master language.
__construct($a_parent_type, $a_parent_id)
Constructor.
setParentType($a_val)
Set parent type.
getActivated()
Get activated.
getEffectiveLang($a_lang)
Get effective language for given language.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
global $ilDB