ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
16 
17  const SEQ_TEMPLATE_DIR = './Modules/Scorm2004/templates/editor/page_layouts_temp/thumbnails';
18 
19  const MODULE_SCORM = 1;
20  const MODULE_PORTFOLIO = 2;
21 
22  var $layout_id = null;
23  var $title = null;
24  var $description = null;
25  var $active = null;
26  var $modules = array();
27 
28  function ilPageLayout($a_id=null)
29  {
30  global $ilias, $ilDB;
31  //create new instance
32  if ($a_id == null) {
33  $this->layout_id = $ilDB->nextId("page_layout");
34  $ilDB->insert("page_layout", array(
35  "layout_id" => array("integer", $this->layout_id),
36  "active" => array("integer", 0),
37  "title" => array("text", ""),
38  "content" => array("clob", ""),
39  "description" => array("text", "")
40  ));
41  //$query = "INSERT INTO page_layout(active) values (0);";
42  //$result = $ilDB->query($query);
43  //$query = "SELECT LAST_INSERT_ID() as id";
44  //$res = $ilDB->query($query);
45  //$row = $res->fetchRow(DB_FETCHMODE_OBJECT);
46  //$this->layout_id = $row->id;
47  $this->active = false;
48  }
49  else {
50  $this->layout_id = $a_id;
51  }
52  }
53 
54  public function getActive() {
55  return $this->active;
56  }
57 
58  public function getDescription() {
59  return $this->description;
60  }
61 
62  public function setDescription($a_description) {
63  $this->description = $a_description;
64  }
65 
66  public function getTitle() {
67  return $this->title;
68  }
69 
70  public function setTitle($a_title) {
71  $this->title = $a_title;
72  }
73 
74  public function getId() {
75  return $this->layout_id;
76  }
77 
81  public function setStyleId($a_val)
82  {
83  $this->style_id = $a_val;
84  }
85 
89  public function getStyleId()
90  {
91  return $this->style_id;
92  }
93 
97  public function setSpecialPage($a_val)
98  {
99  $this->special_page = $a_val;
100  }
101 
105  public function getSpecialPage()
106  {
107  return $this->special_page;
108  }
109 
113  public function setModules(array $a_values = null)
114  {
115  if($a_values)
116  {
117  $valid = array_keys($this->getAvailableModules());
118  $this->modules = array_intersect($a_values, $valid);
119  }
120  else
121  {
122  $this->modules = array();
123  }
124  }
125 
129  public function getModules()
130  {
131  return $this->modules;
132  }
133 
139  public function activate($a_setting=true)
140  {
141  global $ilias, $ilDB;
142 
143  $query = "UPDATE page_layout SET active=".$ilDB->quote($a_setting, "integer").
144  " WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
145  $result = $ilDB->manipulate($query);
146  }
147 
151  public function delete()
152  {
153  global $ilias, $ilDB;
154 
155  $query = "DELETE FROM page_layout WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
156  $result = $ilDB->manipulate($query);
157  }
158 
162  public function update()
163  {
164  global $ilias, $ilDB;
165 
166  $mod_scorm = $mod_portfolio = 0;
167  if(in_array(self::MODULE_SCORM, $this->modules))
168  {
169  $mod_scorm = 1;
170  }
171  if(in_array(self::MODULE_PORTFOLIO, $this->modules))
172  {
173  $mod_portfolio = 1;
174  }
175 
176  $query = "UPDATE page_layout SET title=".$ilDB->quote($this->title, "text").
177  ",description =".$ilDB->quote($this->description, "text").
178  ",active =".$ilDB->quote($this->active, "integer").
179  ",style_id =".$ilDB->quote($this->getStyleId(), "integer").
180  ",special_page =".$ilDB->quote((int) $this->getSpecialPage(), "integer").
181  ",mod_scorm =".$ilDB->quote($mod_scorm, "integer").
182  ",mod_portfolio =".$ilDB->quote($mod_portfolio, "integer").
183  " WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
184 
185  $result = $ilDB->manipulate($query);
186  }
187 
191  public function readObject()
192  {
193  global $ilias, $ilDB;
194  $query = "SELECT * FROM page_layout WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
195  $result = $ilDB->query($query);
196  $row = $ilDB->fetchAssoc($result);
197  $this->title = $row['title'];
198  $this->setStyleId($row['style_id']);
199  $this->setSpecialPage($row['special_page']);
200  $this->description=$row['description'];
201  $this->active=$row['active'];
202 
203  $mods = array();
204  if($row["mod_scorm"])
205  {
206  $mods[] = self::MODULE_SCORM;
207  }
208  if($row["mod_portfolio"])
209  {
210  $mods[] = self::MODULE_PORTFOLIO;
211  }
212  $this->setModules($mods);
213  }
214 
220  public function getXMLContent()
221  {
222  include_once "Services/Style/classes/class.ilPageLayoutPage.php";
223  $layout_page = new ilPageLayoutPage($this->layout_id);
224  return $layout_page->getXMLContent();
225  }
226 
227 
231  public function getPreview()
232  {
233  return $this->generatePreview();
234  }
235 
236 
237  private function getXSLPath() {
238  return "./Services/Style/xml/layout2html.xsl";
239  }
240 
241  private function generatePreview() {
242 
243  $xml = $this->getXMLContent();
244 
245  $dom = @domxml_open_mem($xml, DOMXML_LOAD_PARSING, $error);
246  $xpc = xpath_new_context($dom);
247  $path = "////PlaceHolder";
248  $res =& xpath_eval($xpc, $path);
249 
250  foreach ($res->nodeset as $item){
251  $height = $item->get_attribute("Height");
252 
253  $height = eregi_replace("px","",$height);
254  $height=$height/10;
255  $item->set_attribute("Height",$height."px");
256  }
257  $xsl = file_get_contents($this->getXSLPath());
258 
259  $xml = $dom->dump_mem(0, "UTF-8");
260 
261  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
262 
263  $xh = xslt_create();
264  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
265  xslt_error($xh);
266  xslt_free($xh);
267  return $output;
268  }
269 
275  public static function getLayoutsAsArray($a_active=0){
276 
277  global $ilDB;
278  $arr_layouts = array();
279  if ($active!=0) {
280  $add ="WHERE (active=1)";
281  }
282  $query = "SELECT * FROM page_layout $add ORDER BY title ";
283  $result = $ilDB->query($query);
284  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
285  {
286  array_push($arr_layouts,$row);
287  }
288  return $arr_layouts;
289 
290  }
291 
295  public static function getLayouts($a_active = false, $a_special_page = false, $a_module = null)
296  {
297  global $ilDB;
298  $arr_layouts = array();
299  $add = "WHERE special_page = ".$ilDB->quote($a_special_page, "integer");
300  if ($a_active)
301  {
302  $add.= " AND (active = 1)";
303  }
304  switch($a_module)
305  {
306  case self::MODULE_SCORM:
307  $add .= " AND mod_scorm = 1";
308  break;
309 
310  case self::MODULE_PORTFOLIO:
311  $add .= " AND mod_portfolio = 1";
312  break;
313  }
314  $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
315  $result = $ilDB->query($query);
316  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
317  {
318  array_push($arr_layouts,new ilPageLayout($row['layout_id']));
319  }
320 
321  return $arr_layouts;
322  }
323 
327  public static function activeLayouts($a_special_page = false, $a_module = null)
328  {
329  return self::getLayouts(true, $a_special_page, $a_module);
330  }
331 
340  static function import($a_filename, $a_filepath)
341  {
342  include_once("./Services/Export/classes/class.ilImport.php");
343  $imp = new ilImport();
344  $imp->importEntity($a_filepath, $a_filename,
345  "pgtp", "Services/COPage");
346  }
347 
348  static function getAvailableModules()
349  {
350  global $lng;
351 
352  return array(
353  self::MODULE_SCORM => $lng->txt("style_page_layout_module_scorm"),
354  self::MODULE_PORTFOLIO => $lng->txt("style_page_layout_module_portfolio")
355  );
356  }
357 }
358 
359 ?>