ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPageLayout.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3
15{
19 protected $db;
20
21
22 const SEQ_TEMPLATE_DIR = './Modules/Scorm2004/templates/editor/page_layouts_temp/thumbnails';
23
24 const MODULE_SCORM = 1;
26 const MODULE_LM = 3;
27
28 public $layout_id = null;
29 public $title = null;
30 public $description = null;
31 public $active = null;
32 public $modules = array();
33
34 public function __construct($a_id = null)
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
39 $ilDB = $DIC->database();
40 //create new instance
41 if ($a_id == null) {
42 $this->layout_id = $ilDB->nextId("page_layout");
43 $ilDB->insert("page_layout", array(
44 "layout_id" => array("integer", $this->layout_id),
45 "active" => array("integer", 0),
46 "title" => array("text", ""),
47 "content" => array("clob", ""),
48 "description" => array("text", "")
49 ));
50 //$query = "INSERT INTO page_layout(active) values (0);";
51 //$result = $ilDB->query($query);
52 //$query = "SELECT LAST_INSERT_ID() as id";
53 //$res = $ilDB->query($query);
54 //$row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
55 //$this->layout_id = $row->id;
56 $this->active = false;
57 } else {
58 $this->layout_id = $a_id;
59 }
60 }
61
62 public function getActive()
63 {
64 return $this->active;
65 }
66
67 public function getDescription()
68 {
69 return $this->description;
70 }
71
72 public function setDescription($a_description)
73 {
74 $this->description = $a_description;
75 }
76
77 public function getTitle()
78 {
79 return $this->title;
80 }
81
82 public function setTitle($a_title)
83 {
84 $this->title = $a_title;
85 }
86
87 public function getId()
88 {
89 return $this->layout_id;
90 }
91
95 public function setStyleId($a_val)
96 {
97 $this->style_id = $a_val;
98 }
99
103 public function getStyleId()
104 {
105 return $this->style_id;
106 }
107
111 public function setSpecialPage($a_val)
112 {
113 $this->special_page = $a_val;
114 }
115
119 public function getSpecialPage()
120 {
121 return $this->special_page;
122 }
123
127 public function setModules(array $a_values = null)
128 {
129 if ($a_values) {
130 $valid = array_keys($this->getAvailableModules());
131 $this->modules = array_intersect($a_values, $valid);
132 } else {
133 $this->modules = array();
134 }
135 }
136
140 public function getModules()
141 {
142 return $this->modules;
143 }
144
150 public function activate($a_setting = true)
151 {
153
154 $query = "UPDATE page_layout SET active=" . $ilDB->quote($a_setting, "integer") .
155 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
156 $result = $ilDB->manipulate($query);
157 }
158
162 public function delete()
163 {
165
166 $query = "DELETE FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
167 $result = $ilDB->manipulate($query);
168 }
169
173 public function update()
174 {
176
177 $mod_scorm = $mod_portfolio = $mod_lm = 0;
178 if (in_array(self::MODULE_SCORM, $this->modules)) {
179 $mod_scorm = 1;
180 }
181 if (in_array(self::MODULE_PORTFOLIO, $this->modules)) {
182 $mod_portfolio = 1;
183 }
184 if (in_array(self::MODULE_LM, $this->modules)) {
185 $mod_lm = 1;
186 }
187
188 $query = "UPDATE page_layout SET title=" . $ilDB->quote($this->title, "text") .
189 ",description =" . $ilDB->quote($this->description, "text") .
190 ",active =" . $ilDB->quote($this->active, "integer") .
191 ",style_id =" . $ilDB->quote($this->getStyleId(), "integer") .
192 ",special_page =" . $ilDB->quote((int) $this->getSpecialPage(), "integer") .
193 ",mod_scorm =" . $ilDB->quote($mod_scorm, "integer") .
194 ",mod_portfolio =" . $ilDB->quote($mod_portfolio, "integer") .
195 ",mod_lm =" . $ilDB->quote($mod_lm, "integer") .
196 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
197
198 $result = $ilDB->manipulate($query);
199 }
200
204 public function readObject()
205 {
207 $query = "SELECT * FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
208 $result = $ilDB->query($query);
209 $row = $ilDB->fetchAssoc($result);
210 $this->title = $row['title'];
211 $this->setStyleId($row['style_id']);
212 $this->setSpecialPage($row['special_page']);
213 $this->description = $row['description'];
214 $this->active = $row['active'];
215
216 $mods = array();
217 if ($row["mod_scorm"]) {
218 $mods[] = self::MODULE_SCORM;
219 }
220 if ($row["mod_portfolio"]) {
221 $mods[] = self::MODULE_PORTFOLIO;
222 }
223 if ($row["mod_lm"]) {
224 $mods[] = self::MODULE_LM;
225 }
226 $this->setModules($mods);
227 }
228
234 public function getXMLContent()
235 {
236 include_once "Services/COPage/Layout/classes/class.ilPageLayoutPage.php";
237 $layout_page = new ilPageLayoutPage($this->layout_id);
238 return $layout_page->getXMLContent();
239 }
240
241
245 public function getPreview()
246 {
247 return $this->generatePreview();
248 }
249
250
251 private function getXSLPath()
252 {
253 return "./Services/COPage/Layout/xml/layout2html.xsl";
254 }
255
256 private function generatePreview()
257 {
258 $xml = $this->getXMLContent();
259
260 $dom = @domxml_open_mem($xml, DOMXML_LOAD_PARSING, $error);
261 $xpc = xpath_new_context($dom);
262 $path = "////PlaceHolder";
263 $res = xpath_eval($xpc, $path);
264
265 foreach ($res->nodeset as $item) {
266 $height = $item->get_attribute("Height");
267
268 $height = str_ireplace("px", "", $height);
269 $height = $height / 10;
270 $item->set_attribute("Height", $height . "px");
271 }
272 $xsl = file_get_contents($this->getXSLPath());
273
274 $xml = $dom->dump_mem(0, "UTF-8");
275
276 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
277
278 $xh = xslt_create();
279 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, null);
280 xslt_error($xh);
281 xslt_free($xh);
282 return $output;
283 }
284
290 public static function getLayoutsAsArray($a_active = 0)
291 {
292 global $DIC;
293
294 $ilDB = $DIC->database();
295 $arr_layouts = array();
296 if ($active != 0) {
297 $add = "WHERE (active=1)";
298 }
299 $query = "SELECT * FROM page_layout $add ORDER BY title ";
300 $result = $ilDB->query($query);
301 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
302 array_push($arr_layouts, $row);
303 }
304 return $arr_layouts;
305 }
306
310 public static function getLayouts($a_active = false, $a_special_page = false, $a_module = null)
311 {
312 global $DIC;
313
314 $ilDB = $DIC->database();
315 $arr_layouts = array();
316 $add = "WHERE special_page = " . $ilDB->quote($a_special_page, "integer");
317 if ($a_active) {
318 $add .= " AND (active = 1)";
319 }
320 switch ($a_module) {
322 $add .= " AND mod_scorm = 1";
323 break;
324
326 $add .= " AND mod_portfolio = 1";
327 break;
328
329 case self::MODULE_LM:
330 $add .= " AND mod_lm = 1";
331 break;
332 }
333 $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
334 $result = $ilDB->query($query);
335 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
336 array_push($arr_layouts, new ilPageLayout($row['layout_id']));
337 }
338
339 return $arr_layouts;
340 }
341
345 public static function activeLayouts($a_special_page = false, $a_module = null)
346 {
347 return self::getLayouts(true, $a_special_page, $a_module);
348 }
349
358 public static function import($a_filename, $a_filepath)
359 {
360 include_once("./Services/Export/classes/class.ilImport.php");
361 $imp = new ilImport();
362 $imp->importEntity(
363 $a_filepath,
364 $a_filename,
365 "pgtp",
366 "Services/COPage"
367 );
368 }
369
370 public static function getAvailableModules()
371 {
372 global $DIC;
373
374 $lng = $DIC->language();
375
376 return array(
377 self::MODULE_SCORM => $lng->txt("style_page_layout_module_scorm"),
378 self::MODULE_PORTFOLIO => $lng->txt("style_page_layout_module_portfolio"),
379 self::MODULE_LM => $lng->txt("style_page_layout_module_learning_module")
380 );
381 }
382}
$result
An exception for terminatinating execution or to throw for unit testing.
Import class.
Page layout page object.
Class ilPageLayout.
readObject()
Read page layout.
setSpecialPage($a_val)
Set special page.
__construct($a_id=null)
setModules(array $a_values=null)
Set modules.
getStyleId()
Get style id.
setDescription($a_description)
getPreview()
Get preview.
getSpecialPage()
Get special page.
static activeLayouts($a_special_page=false, $a_module=null)
Get active layouts.
setStyleId($a_val)
Set style id.
update()
Update page layout.
static getAvailableModules()
activate($a_setting=true)
(De-)Activate layout
getModules()
Get modules.
getXMLContent()
Get xml content.
static getLayouts($a_active=false, $a_special_page=false, $a_module=null)
Get layouts.
static getLayoutsAsArray($a_active=0)
Static access functions.
$valid
xslt_error(&$proc)
xslt_free(&$proc)
xslt_create()
xpath_eval($xpath_context, $eval_str, $contextnode=null)
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
const DOMXML_LOAD_PARSING
$xml
Definition: metadata.php:332
$query
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46