ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
27 public $layout_id = null;
28 public $title = null;
29 public $description = null;
30 public $active = null;
31 public $modules = array();
32
33 public function __construct($a_id = null)
34 {
35 global $DIC;
36
37 $this->db = $DIC->database();
38 $ilDB = $DIC->database();
39 //create new instance
40 if ($a_id == null) {
41 $this->layout_id = $ilDB->nextId("page_layout");
42 $ilDB->insert("page_layout", array(
43 "layout_id" => array("integer", $this->layout_id),
44 "active" => array("integer", 0),
45 "title" => array("text", ""),
46 "content" => array("clob", ""),
47 "description" => array("text", "")
48 ));
49 //$query = "INSERT INTO page_layout(active) values (0);";
50 //$result = $ilDB->query($query);
51 //$query = "SELECT LAST_INSERT_ID() as id";
52 //$res = $ilDB->query($query);
53 //$row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
54 //$this->layout_id = $row->id;
55 $this->active = false;
56 } else {
57 $this->layout_id = $a_id;
58 }
59 }
60
61 public function getActive()
62 {
63 return $this->active;
64 }
65
66 public function getDescription()
67 {
68 return $this->description;
69 }
70
71 public function setDescription($a_description)
72 {
73 $this->description = $a_description;
74 }
75
76 public function getTitle()
77 {
78 return $this->title;
79 }
80
81 public function setTitle($a_title)
82 {
83 $this->title = $a_title;
84 }
85
86 public function getId()
87 {
88 return $this->layout_id;
89 }
90
94 public function setStyleId($a_val)
95 {
96 $this->style_id = $a_val;
97 }
98
102 public function getStyleId()
103 {
104 return $this->style_id;
105 }
106
110 public function setSpecialPage($a_val)
111 {
112 $this->special_page = $a_val;
113 }
114
118 public function getSpecialPage()
119 {
120 return $this->special_page;
121 }
122
126 public function setModules(array $a_values = null)
127 {
128 if ($a_values) {
129 $valid = array_keys($this->getAvailableModules());
130 $this->modules = array_intersect($a_values, $valid);
131 } else {
132 $this->modules = array();
133 }
134 }
135
139 public function getModules()
140 {
141 return $this->modules;
142 }
143
149 public function activate($a_setting = true)
150 {
152
153 $query = "UPDATE page_layout SET active=" . $ilDB->quote($a_setting, "integer") .
154 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
155 $result = $ilDB->manipulate($query);
156 }
157
161 public function delete()
162 {
164
165 $query = "DELETE FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
166 $result = $ilDB->manipulate($query);
167 }
168
172 public function update()
173 {
175
176 $mod_scorm = $mod_portfolio = 0;
177 if (in_array(self::MODULE_SCORM, $this->modules)) {
178 $mod_scorm = 1;
179 }
180 if (in_array(self::MODULE_PORTFOLIO, $this->modules)) {
181 $mod_portfolio = 1;
182 }
183
184 $query = "UPDATE page_layout SET title=" . $ilDB->quote($this->title, "text") .
185 ",description =" . $ilDB->quote($this->description, "text") .
186 ",active =" . $ilDB->quote($this->active, "integer") .
187 ",style_id =" . $ilDB->quote($this->getStyleId(), "integer") .
188 ",special_page =" . $ilDB->quote((int) $this->getSpecialPage(), "integer") .
189 ",mod_scorm =" . $ilDB->quote($mod_scorm, "integer") .
190 ",mod_portfolio =" . $ilDB->quote($mod_portfolio, "integer") .
191 " WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
192
193 $result = $ilDB->manipulate($query);
194 }
195
199 public function readObject()
200 {
202 $query = "SELECT * FROM page_layout WHERE layout_id =" . $ilDB->quote($this->layout_id, "integer");
203 $result = $ilDB->query($query);
204 $row = $ilDB->fetchAssoc($result);
205 $this->title = $row['title'];
206 $this->setStyleId($row['style_id']);
207 $this->setSpecialPage($row['special_page']);
208 $this->description = $row['description'];
209 $this->active = $row['active'];
210
211 $mods = array();
212 if ($row["mod_scorm"]) {
213 $mods[] = self::MODULE_SCORM;
214 }
215 if ($row["mod_portfolio"]) {
216 $mods[] = self::MODULE_PORTFOLIO;
217 }
218 $this->setModules($mods);
219 }
220
226 public function getXMLContent()
227 {
228 include_once "Services/COPage/Layout/classes/class.ilPageLayoutPage.php";
229 $layout_page = new ilPageLayoutPage($this->layout_id);
230 return $layout_page->getXMLContent();
231 }
232
233
237 public function getPreview()
238 {
239 return $this->generatePreview();
240 }
241
242
243 private function getXSLPath()
244 {
245 return "./Services/COPage/Layout/xml/layout2html.xsl";
246 }
247
248 private function generatePreview()
249 {
250 $xml = $this->getXMLContent();
251
252 $dom = @domxml_open_mem($xml, DOMXML_LOAD_PARSING, $error);
253 $xpc = xpath_new_context($dom);
254 $path = "////PlaceHolder";
255 $res = xpath_eval($xpc, $path);
256
257 foreach ($res->nodeset as $item) {
258 $height = $item->get_attribute("Height");
259
260 $height = str_ireplace("px", "", $height);
261 $height = $height / 10;
262 $item->set_attribute("Height", $height . "px");
263 }
264 $xsl = file_get_contents($this->getXSLPath());
265
266 $xml = $dom->dump_mem(0, "UTF-8");
267
268 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
269
270 $xh = xslt_create();
271 $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", null, $args, null);
272 xslt_error($xh);
273 xslt_free($xh);
274 return $output;
275 }
276
282 public static function getLayoutsAsArray($a_active = 0)
283 {
284 global $DIC;
285
286 $ilDB = $DIC->database();
287 $arr_layouts = array();
288 if ($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 array_push($arr_layouts, $row);
295 }
296 return $arr_layouts;
297 }
298
302 public static function getLayouts($a_active = false, $a_special_page = false, $a_module = null)
303 {
304 global $DIC;
305
306 $ilDB = $DIC->database();
307 $arr_layouts = array();
308 $add = "WHERE special_page = " . $ilDB->quote($a_special_page, "integer");
309 if ($a_active) {
310 $add .= " AND (active = 1)";
311 }
312 switch ($a_module) {
314 $add .= " AND mod_scorm = 1";
315 break;
316
318 $add .= " AND mod_portfolio = 1";
319 break;
320 }
321 $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
322 $result = $ilDB->query($query);
323 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
324 array_push($arr_layouts, new ilPageLayout($row['layout_id']));
325 }
326
327 return $arr_layouts;
328 }
329
333 public static function activeLayouts($a_special_page = false, $a_module = null)
334 {
335 return self::getLayouts(true, $a_special_page, $a_module);
336 }
337
346 public static function import($a_filename, $a_filepath)
347 {
348 include_once("./Services/Export/classes/class.ilImport.php");
349 $imp = new ilImport();
350 $imp->importEntity(
351 $a_filepath,
352 $a_filename,
353 "pgtp",
354 "Services/COPage"
355 );
356 }
357
358 public static function getAvailableModules()
359 {
360 global $DIC;
361
362 $lng = $DIC->language();
363
364 return array(
365 self::MODULE_SCORM => $lng->txt("style_page_layout_module_scorm"),
366 self::MODULE_PORTFOLIO => $lng->txt("style_page_layout_module_portfolio")
367 );
368 }
369}
$result
$path
Definition: aliased.php:25
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
$row
$query
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB