ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPageLayout.php
Go to the documentation of this file.
1<?php
2
25{
26 public const SEQ_TEMPLATE_DIR = './components/ILIAS/Scorm2004/templates/editor/page_layouts_temp/thumbnails';
27 public const MODULE_SCORM = 1;
28 public const MODULE_PORTFOLIO = 2;
29 public const MODULE_LM = 3;
30 protected ?string $xml_content = null;
31 protected \ILIAS\COPage\Dom\DomUtil $dom_util;
32 protected int $special_page;
33 protected int $style_id;
34
35 protected ilDBInterface $db;
36 public int $layout_id = 0;
37 public string $title = "";
38 public string $description = "";
39 public bool $active = false;
40 public array $modules = array();
41
42 public function __construct(
43 int $a_id = 0
44 ) {
45 global $DIC;
46
47 $this->db = $DIC->database();
48 $ilDB = $DIC->database();
49
50 //create new instance
51 if ($a_id == 0) {
52 $this->layout_id = $ilDB->nextId("page_layout");
53 $ilDB->insert("page_layout", array(
54 "layout_id" => array("integer", $this->layout_id),
55 "active" => array("integer", 0),
56 "title" => array("text", ""),
57 "content" => array("clob", ""),
58 "description" => array("text", "")
59 ));
60 //$query = "INSERT INTO page_layout(active) values (0);";
61 //$result = $ilDB->query($query);
62 //$query = "SELECT LAST_INSERT_ID() as id";
63 //$res = $ilDB->query($query);
64 //$row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
65 //$this->layout_id = $row->id;
66 $this->active = false;
67 } else {
68 $this->layout_id = $a_id;
69 }
70 $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
71 }
72
73 public function getActive(): bool
74 {
75 return $this->active;
76 }
77
78 public function getDescription(): string
79 {
80 return $this->description;
81 }
82
83 public function setDescription(string $a_description): void
84 {
85 $this->description = $a_description;
86 }
87
88 public function getTitle(): string
89 {
90 return $this->title;
91 }
92
93 public function setTitle(string $a_title): void
94 {
95 $this->title = $a_title;
96 }
97
98 public function getId(): int
99 {
100 return $this->layout_id;
101 }
102
103
104 /*
105 public function setStyleId(int $a_val) : void
106 {
107 $this->style_id = $a_val;
108 }
109
110 public function getStyleId() : int
111 {
112 return $this->style_id;
113 }*/
114
115
116 public function setModules(array $a_values = []): void
117 {
118 if ($a_values) {
119 $valid = array_keys($this->getAvailableModules());
120 $this->modules = array_intersect($a_values, $valid);
121 } else {
122 $this->modules = array();
123 }
124 }
125
126 public function getModules(): array
127 {
128 return $this->modules;
129 }
130
134 public function activate(
135 bool $a_setting = true
136 ): void {
137 $ilDB = $this->db;
138
139 $query = "UPDATE page_layout SET active=" . $ilDB->quote($a_setting, "integer") .
140 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
141 $result = $ilDB->manipulate($query);
142 }
143
147 public function delete(): void
148 {
149 $ilDB = $this->db;
150
151 $query = "DELETE FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
152 $result = $ilDB->manipulate($query);
153 }
154
158 public function update(): void
159 {
160 $ilDB = $this->db;
161
162 $mod_scorm = $mod_portfolio = $mod_lm = 0;
163 if (in_array(self::MODULE_SCORM, $this->modules)) {
164 $mod_scorm = 1;
165 }
166 if (in_array(self::MODULE_PORTFOLIO, $this->modules)) {
167 $mod_portfolio = 1;
168 }
169 if (in_array(self::MODULE_LM, $this->modules)) {
170 $mod_lm = 1;
171 }
172
173 $query = "UPDATE page_layout SET title=" . $ilDB->quote($this->title, "text") .
174 ",description =" . $ilDB->quote($this->description, "text") .
175 ",active =" . $ilDB->quote($this->active, "integer") .
176 ",mod_scorm =" . $ilDB->quote($mod_scorm, "integer") .
177 ",mod_portfolio =" . $ilDB->quote($mod_portfolio, "integer") .
178 ",mod_lm =" . $ilDB->quote($mod_lm, "integer") .
179 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
180
181 $result = $ilDB->manipulate($query);
182 }
183
184 public function readObject(): void
185 {
186 $ilDB = $this->db;
187 $query = "SELECT * FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
188 $result = $ilDB->query($query);
189 $row = $ilDB->fetchAssoc($result);
190 $this->title = (string) $row['title'];
191 $this->description = (string) $row['description'];
192 $this->active = (bool) $row['active'];
193
194 $mods = array();
195 if ($row["mod_scorm"]) {
196 $mods[] = self::MODULE_SCORM;
197 }
198 if ($row["mod_portfolio"]) {
199 $mods[] = self::MODULE_PORTFOLIO;
200 }
201 if ($row["mod_lm"]) {
202 $mods[] = self::MODULE_LM;
203 }
204 $this->setModules($mods);
205 }
206
207 public function setXMLContent(string $content): void
208 {
209 $this->xml_content = $content;
210 }
211
212 public function getXMLContent(): string
213 {
214 if (!is_null($this->xml_content)) {
215 return $this->xml_content;
216 }
217 $layout_page = new ilPageLayoutPage($this->layout_id);
218 return $layout_page->getXMLContent();
219 }
220
221 public function copyXmlContent(bool $self_ass = true): string
222 {
223 $layout_page = new ilPageLayoutPage($this->layout_id);
224 return $layout_page->copyXmlContent(true, 0, 0, $self_ass);
225 }
226
227 public function getPreview(): string
228 {
229 return $this->generatePreview();
230 }
231
232 private function getXSLPath(): string
233 {
234 if (is_file("./components/ILIAS/COPage/Layout/xml/layout2html.xsl")) {
235 return "./components/ILIAS/COPage/Layout/xml/layout2html.xsl";
236 }
237 return "../components/ILIAS/COPage/Layout/xml/layout2html.xsl";
238 }
239
240 private function generatePreview(): string
241 {
242 $error = null;
243 $dom = $this->dom_util->docFromString($this->getXMLContent(), $error);
244 $path = "////PlaceHolder";
245 $nodes = $this->dom_util->path($dom, $path);
246 foreach ($nodes as $node) {
247 $height = $node->getAttribute("Height");
248
249 $height = str_ireplace("px", "", $height);
250 $height = $height / 10;
251 $node->setAttribute("Height", $height . "px");
252 }
253
254 $xml = $this->dom_util->dump($dom->documentElement);
255 $output = $this->xslt($xml, []);
256 return $output;
257 }
258
259 protected function xslt(
260 string $xml,
261 array $params
262 ): string {
263 $xslt = new \XSLTProcessor();
264 $xsl = file_get_contents($this->getXSLPath());
265 $xslt_domdoc = new \DomDocument();
266 $xslt_domdoc->loadXML($xsl);
267 $xslt->importStylesheet($xslt_domdoc);
268 foreach ($params as $key => $value) {
269 $xslt->setParameter("", $key, (string) $value);
270 }
271 $xml_domdoc = new \DomDocument();
272 $xml_domdoc->loadXML($xml);
273 // show warnings again due to discussion in #12866
274 $result = $xslt->transformToXml($xml_domdoc);
275 unset($xslt);
276 return $result;
277 }
278
279
280 public static function getLayoutsAsArray(
281 int $a_active = 0
282 ): array {
283 global $DIC;
284
285 $ilDB = $DIC->database();
286 $arr_layouts = array();
287 $add = "";
288 if ($a_active != 0) {
289 $add = "WHERE (active=1)";
290 }
291 $query = "SELECT * FROM page_layout $add ORDER BY title ";
292 $result = $ilDB->query($query);
293 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
294 if (ilPageObject::_exists("stys", $row["layout_id"])) {
295 $arr_layouts[] = $row;
296 }
297 }
298 return $arr_layouts;
299 }
300
301 public static function getLayouts(
302 bool $a_active = false,
303 int $a_module = 0
304 ): array {
305 global $DIC;
306
307 $ilDB = $DIC->database();
308 $arr_layouts = array();
309 $add = "";
310 $conc = " WHERE ";
311 if ($a_active) {
312 $add .= $conc . " (active = 1)";
313 $conc = " AND ";
314 }
315 switch ($a_module) {
316 case self::MODULE_SCORM:
317 $add .= $conc . " mod_scorm = 1";
318 break;
319
320 case self::MODULE_PORTFOLIO:
321 $add .= $conc . " mod_portfolio = 1";
322 break;
323
324 case self::MODULE_LM:
325 $add .= $conc . " mod_lm = 1";
326 break;
327 }
328 $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
329 $result = $ilDB->query($query);
330 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
331 $arr_layouts[] = new ilPageLayout($row['layout_id']);
332 }
333
334 return $arr_layouts;
335 }
336
340 public static function activeLayouts(
341 int $a_module = 0
342 ): array {
343 return self::getLayouts(true, $a_module);
344 }
345
349 public static function import(
350 string $a_filename,
351 string $a_filepath
352 ): void {
353 $imp = new ilImport();
354 $imp->importEntity(
355 $a_filepath,
356 $a_filename,
357 "pgtp",
358 "components/ILIAS/COPage"
359 );
360 }
361
362 public static function getAvailableModules(): array
363 {
364 global $DIC;
365
366 $lng = $DIC->language();
367
368 return array(
369 self::MODULE_PORTFOLIO => $lng->txt("style_page_layout_module_portfolio"),
370 self::MODULE_LM => $lng->txt("style_page_layout_module_learning_module")
371 );
372 }
373}
return true
Import class.
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...
copyXmlContent(bool $self_ass=true)
static getLayouts(bool $a_active=false, int $a_module=0)
ILIAS COPage Dom DomUtil $dom_util
setDescription(string $a_description)
static activeLayouts(int $a_module=0)
Get active layouts.
update()
Update page layout.
ilDBInterface $db
static getAvailableModules()
xslt(string $xml, array $params)
activate(bool $a_setting=true)
(De-)Activate layout
setTitle(string $a_title)
__construct(int $a_id=0)
setModules(array $a_values=[])
static getLayoutsAsArray(int $a_active=0)
setXMLContent(string $content)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$valid
Interface ilDBInterface.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$path
Definition: ltiservices.php:30
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26