ILIAS  release_8 Revision v8.24
class.ilPageLayout.php
Go to the documentation of this file.
1<?php
2
25{
26 public const SEQ_TEMPLATE_DIR = './Modules/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 int $special_page;
31 protected int $style_id;
32
33 protected ilDBInterface $db;
34 public int $layout_id = 0;
35 public string $title = "";
36 public string $description = "";
37 public bool $active = false;
38 public array $modules = array();
39
40 public function __construct(
41 int $a_id = 0
42 ) {
43 global $DIC;
44
45 $this->db = $DIC->database();
46 $ilDB = $DIC->database();
47
48 //create new instance
49 if ($a_id == 0) {
50 $this->layout_id = $ilDB->nextId("page_layout");
51 $ilDB->insert("page_layout", array(
52 "layout_id" => array("integer", $this->layout_id),
53 "active" => array("integer", 0),
54 "title" => array("text", ""),
55 "content" => array("clob", ""),
56 "description" => array("text", "")
57 ));
58 //$query = "INSERT INTO page_layout(active) values (0);";
59 //$result = $ilDB->query($query);
60 //$query = "SELECT LAST_INSERT_ID() as id";
61 //$res = $ilDB->query($query);
62 //$row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
63 //$this->layout_id = $row->id;
64 $this->active = false;
65 } else {
66 $this->layout_id = $a_id;
67 }
68 }
69
70 public function getActive(): bool
71 {
72 return $this->active;
73 }
74
75 public function getDescription(): string
76 {
77 return $this->description;
78 }
79
80 public function setDescription(string $a_description): void
81 {
82 $this->description = $a_description;
83 }
84
85 public function getTitle(): string
86 {
87 return $this->title;
88 }
89
90 public function setTitle(string $a_title): void
91 {
92 $this->title = $a_title;
93 }
94
95 public function getId(): int
96 {
97 return $this->layout_id;
98 }
99
100
101 /*
102 public function setStyleId(int $a_val) : void
103 {
104 $this->style_id = $a_val;
105 }
106
107 public function getStyleId() : int
108 {
109 return $this->style_id;
110 }*/
111
112
113 public function setModules(array $a_values = []): void
114 {
115 if ($a_values) {
116 $valid = array_keys($this->getAvailableModules());
117 $this->modules = array_intersect($a_values, $valid);
118 } else {
119 $this->modules = array();
120 }
121 }
122
123 public function getModules(): array
124 {
125 return $this->modules;
126 }
127
131 public function activate(
132 bool $a_setting = true
133 ): void {
134 $ilDB = $this->db;
135
136 $query = "UPDATE page_layout SET active=" . $ilDB->quote($a_setting, "integer") .
137 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
138 $result = $ilDB->manipulate($query);
139 }
140
144 public function delete(): void
145 {
146 $ilDB = $this->db;
147
148 $query = "DELETE FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
149 $result = $ilDB->manipulate($query);
150 }
151
155 public function update(): void
156 {
157 $ilDB = $this->db;
158
159 $mod_scorm = $mod_portfolio = $mod_lm = 0;
160 if (in_array(self::MODULE_SCORM, $this->modules)) {
161 $mod_scorm = 1;
162 }
163 if (in_array(self::MODULE_PORTFOLIO, $this->modules)) {
164 $mod_portfolio = 1;
165 }
166 if (in_array(self::MODULE_LM, $this->modules)) {
167 $mod_lm = 1;
168 }
169
170 $query = "UPDATE page_layout SET title=" . $ilDB->quote($this->title, "text") .
171 ",description =" . $ilDB->quote($this->description, "text") .
172 ",active =" . $ilDB->quote($this->active, "integer") .
173 ",mod_scorm =" . $ilDB->quote($mod_scorm, "integer") .
174 ",mod_portfolio =" . $ilDB->quote($mod_portfolio, "integer") .
175 ",mod_lm =" . $ilDB->quote($mod_lm, "integer") .
176 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
177
178 $result = $ilDB->manipulate($query);
179 }
180
181 public function readObject(): void
182 {
183 $ilDB = $this->db;
184 $query = "SELECT * FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
185 $result = $ilDB->query($query);
186 $row = $ilDB->fetchAssoc($result);
187 $this->title = (string) $row['title'];
188 $this->description = (string) $row['description'];
189 $this->active = (bool) $row['active'];
190
191 $mods = array();
192 if ($row["mod_scorm"]) {
193 $mods[] = self::MODULE_SCORM;
194 }
195 if ($row["mod_portfolio"]) {
196 $mods[] = self::MODULE_PORTFOLIO;
197 }
198 if ($row["mod_lm"]) {
199 $mods[] = self::MODULE_LM;
200 }
201 $this->setModules($mods);
202 }
203
204 public function getXMLContent(): string
205 {
206 $layout_page = new ilPageLayoutPage($this->layout_id);
207 return $layout_page->getXMLContent();
208 }
209
210 public function copyXmlContent(bool $self_ass = true): string
211 {
212 $layout_page = new ilPageLayoutPage($this->layout_id);
213 return $layout_page->copyXmlContent(true, 0, 0, $self_ass);
214 }
215
216 public function getPreview(): string
217 {
218 return $this->generatePreview();
219 }
220
221 private function getXSLPath(): string
222 {
223 return "./Services/COPage/Layout/xml/layout2html.xsl";
224 }
225
226 private function generatePreview(): string
227 {
228 $xml = $this->getXMLContent();
229
231 $xpc = xpath_new_context($dom);
232 $path = "////PlaceHolder";
233 $res = xpath_eval($xpc, $path);
234
235 foreach ($res->nodeset as $item) {
236 $height = $item->get_attribute("Height");
237
238 $height = str_ireplace("px", "", $height);
239 $height = $height / 10;
240 $item->set_attribute("Height", $height . "px");
241 }
242 $xsl = file_get_contents($this->getXSLPath());
243
244 $xml = $dom->dump_mem(0, "UTF-8");
245
246 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
247
248 $xh = xslt_create();
249 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, null);
250 xslt_error($xh);
251 xslt_free($xh);
252 return $output;
253 }
254
255 public static function getLayoutsAsArray(
256 int $a_active = 0
257 ): array {
258 global $DIC;
259
260 $ilDB = $DIC->database();
261 $arr_layouts = array();
262 $add = "";
263 if ($a_active != 0) {
264 $add = "WHERE (active=1)";
265 }
266 $query = "SELECT * FROM page_layout $add ORDER BY title ";
267 $result = $ilDB->query($query);
268 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
269 if (ilPageObject::_exists("stys", $row["layout_id"])) {
270 $arr_layouts[] = $row;
271 }
272 }
273 return $arr_layouts;
274 }
275
276 public static function getLayouts(
277 bool $a_active = false,
278 int $a_module = 0
279 ): array {
280 global $DIC;
281
282 $ilDB = $DIC->database();
283 $arr_layouts = array();
284 $add = "";
285 $conc = " WHERE ";
286 if ($a_active) {
287 $add .= $conc . " (active = 1)";
288 $conc = " AND ";
289 }
290 switch ($a_module) {
291 case self::MODULE_SCORM:
292 $add .= $conc . " mod_scorm = 1";
293 break;
294
295 case self::MODULE_PORTFOLIO:
296 $add .= $conc . " mod_portfolio = 1";
297 break;
298
299 case self::MODULE_LM:
300 $add .= $conc . " mod_lm = 1";
301 break;
302 }
303 $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
304 $result = $ilDB->query($query);
305 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
306 $arr_layouts[] = new ilPageLayout($row['layout_id']);
307 }
308
309 return $arr_layouts;
310 }
311
315 public static function activeLayouts(
316 int $a_module = 0
317 ): array {
318 return self::getLayouts(true, $a_module);
319 }
320
324 public static function import(
325 string $a_filename,
326 string $a_filepath
327 ): void {
328 $imp = new ilImport();
329 $imp->importEntity(
330 $a_filepath,
331 $a_filename,
332 "pgtp",
333 "Services/COPage"
334 );
335 }
336
337 public static function getAvailableModules(): array
338 {
339 global $DIC;
340
341 $lng = $DIC->language();
342
343 return array(
344 self::MODULE_PORTFOLIO => $lng->txt("style_page_layout_module_portfolio"),
345 self::MODULE_LM => $lng->txt("style_page_layout_module_learning_module")
346 );
347 }
348}
return true
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...
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)
setDescription(string $a_description)
static activeLayouts(int $a_module=0)
Get active layouts.
update()
Update page layout.
ilDBInterface $db
static getAvailableModules()
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)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
$valid
global $DIC
Definition: feed.php:28
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
const DOMXML_LOAD_PARSING
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
xslt_error(&$proc)
xslt_free(&$proc)
xslt_create()
Interface ilDBInterface.
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$xml
Definition: metadata.php:351
$query
$lng