ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPageMultiLang.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilDBInterface $db;
27 protected string $parent_type;
28 protected int $parent_id;
29 protected string $master_lang;
30 protected array $languages = array();
31 protected bool $activated = false;
32
40 public function __construct(
41 string $a_parent_type,
42 int $a_parent_id
43 ) {
44 global $DIC;
45
46 $ilDB = $DIC->database();
47
48 $this->db = $ilDB;
49
50 $this->setParentType($a_parent_type);
51 $this->setParentId($a_parent_id);
52
53 if ($this->getParentType() == "") {
54 throw new ilCOPageException("ilPageMultiLang: No parent type passed.");
55 }
56
57 if ($this->getParentId() <= 0) {
58 throw new ilCOPageException("ilPageMultiLang: No parent ID passed.");
59 }
60
61 $this->read();
62 }
63
64 public function setParentType(string $a_val): void
65 {
66 $this->parent_type = $a_val;
67 }
68
69 public function getParentType(): string
70 {
71 return $this->parent_type;
72 }
73
74 public function setParentId(int $a_val): void
75 {
76 $this->parent_id = $a_val;
77 }
78
79 public function getParentId(): int
80 {
81 return $this->parent_id;
82 }
83
84 public function setMasterLanguage(string $a_val): void
85 {
86 $this->master_lang = $a_val;
87 }
88
89 public function getMasterLanguage(): string
90 {
91 return $this->master_lang;
92 }
93
94 public function setLanguages(array $a_val): void
95 {
96 $this->languages = $a_val;
97 }
98
99 public function getLanguages(): array
100 {
101 return $this->languages;
102 }
103
104 public function addLanguage(string $a_lang): void
105 {
106 if ($a_lang != "" && !in_array($a_lang, $this->languages)) {
107 $this->languages[] = $a_lang;
108 }
109 }
110
111 protected function setActivated(bool $a_val): void
112 {
113 $this->activated = $a_val;
114 }
115
116 public function getActivated(): bool
117 {
118 return $this->activated;
119 }
120
121 public function read(): void
122 {
123 $set = $this->db->query(
124 "SELECT * FROM copg_multilang " .
125 " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
126 " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
127 );
128 if ($rec = $this->db->fetchAssoc($set)) {
129 $this->setMasterLanguage($rec["master_lang"]);
130 $this->setActivated(true);
131 } else {
132 $this->setActivated(false);
133 }
134
135 $this->setLanguages(array());
136 $set = $this->db->query(
137 "SELECT * FROM copg_multilang_lang " .
138 " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
139 " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
140 );
141 while ($rec = $this->db->fetchAssoc($set)) {
142 $this->addLanguage($rec["lang"]);
143 }
144 }
145
146 public function delete(): void
147 {
148 $this->db->manipulate(
149 "DELETE FROM copg_multilang " .
150 " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
151 " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
152 );
153 $this->db->manipulate(
154 "DELETE FROM copg_multilang_lang " .
155 " WHERE parent_type = " . $this->db->quote($this->getParentType(), "text") .
156 " AND parent_id = " . $this->db->quote($this->getParentId(), "integer")
157 );
158 }
159
160 public function save(): void
161 {
162 $this->delete();
163
164 $this->db->manipulate("INSERT INTO copg_multilang " .
165 "(parent_type, parent_id, master_lang) VALUES (" .
166 $this->db->quote($this->getParentType(), "text") . "," .
167 $this->db->quote($this->getParentId(), "integer") . "," .
168 $this->db->quote($this->getMasterLanguage(), "text") .
169 ")");
170
171 foreach ($this->getLanguages() as $lang) {
172 $this->db->manipulate("INSERT INTO copg_multilang_lang " .
173 "(parent_type, parent_id, lang) VALUES (" .
174 $this->db->quote($this->getParentType(), "text") . "," .
175 $this->db->quote($this->getParentId(), "integer") . "," .
176 $this->db->quote($lang, "text") .
177 ")");
178 }
179 }
180
189 public function copy(
190 string $a_target_parent_type,
191 int $a_target_parent_id
192 ): ?ilPageMultiLang {
193 if ($this->getActivated()) {
194 $target_ml = new ilPageMultiLang($a_target_parent_type, $a_target_parent_id);
195 $target_ml->setMasterLanguage($this->getMasterLanguage());
196 $target_ml->setLanguages($this->getLanguages());
197 $target_ml->save();
198 return $target_ml;
199 }
200
201 return null;
202 }
203
204
214 public function getEffectiveLang(string $a_lang): string
215 {
216 if ($this->getActivated() &&
217 in_array($a_lang, $this->getLanguages()) &&
218 ilPageObject::_exists($this->getParentType(), $this->getParentId(), $a_lang)) {
219 return $a_lang;
220 }
221 return "-";
222 }
223}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLanguages(array $a_val)
setMasterLanguage(string $a_val)
getEffectiveLang(string $a_lang)
Get effective language for given language.
__construct(string $a_parent_type, int $a_parent_id)
Constructor.
addLanguage(string $a_lang)
copy(string $a_target_parent_type, int $a_target_parent_id)
Copy multilinguality settings.
setParentType(string $a_val)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
Interface ilDBInterface.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25