ILIAS  Release_4_2_x_branch Revision 61807
 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  global $ilias, $ilDB;
223 
224  $r = $ilias->db->query("SELECT content FROM page_object WHERE parent_type='stys' AND page_id=".
225  $ilDB->quote($this->layout_id));
226  $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
227 
228  return $row['content'];
229  }
230 
231 
235  public function getPreview()
236  {
237  return $this->generatePreview();
238  }
239 
240 
241  private function getXSLPath() {
242  return "./Services/Style/xml/layout2html.xsl";
243  }
244 
245  private function generatePreview() {
246 
247  $xml = $this->getXMLContent();
248 
249  $dom = @domxml_open_mem($xml, DOMXML_LOAD_PARSING, $error);
250  $xpc = xpath_new_context($dom);
251  $path = "////PlaceHolder";
252  $res =& xpath_eval($xpc, $path);
253 
254  foreach ($res->nodeset as $item){
255  $height = $item->get_attribute("Height");
256 
257  $height = eregi_replace("px","",$height);
258  $height=$height/10;
259  $item->set_attribute("Height",$height."px");
260  }
261  $xsl = file_get_contents($this->getXSLPath());
262 
263  $xml = $dom->dump_mem(0, "UTF-8");
264 
265  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
266 
267  $xh = xslt_create();
268  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
269  xslt_error($xh);
270  xslt_free($xh);
271  return $output;
272  }
273 
279  public static function getLayoutsAsArray($a_active=0){
280 
281  global $ilDB;
282  $arr_layouts = array();
283  if ($active!=0) {
284  $add ="WHERE (active=1)";
285  }
286  $query = "SELECT * FROM page_layout $add ORDER BY title ";
287  $result = $ilDB->query($query);
288  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
289  {
290  array_push($arr_layouts,$row);
291  }
292  return $arr_layouts;
293 
294  }
295 
299  public static function getLayouts($a_active = false, $a_special_page = false, $a_module = null)
300  {
301  global $ilDB;
302  $arr_layouts = array();
303  $add = "WHERE special_page = ".$ilDB->quote($a_special_page, "integer");
304  if ($a_active)
305  {
306  $add.= " AND (active = 1)";
307  }
308  switch($a_module)
309  {
310  case self::MODULE_SCORM:
311  $add .= " AND mod_scorm = 1";
312  break;
313 
314  case self::MODULE_PORTFOLIO:
315  $add .= " AND mod_portfolio = 1";
316  break;
317  }
318  $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
319  $result = $ilDB->query($query);
320  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
321  {
322  array_push($arr_layouts,new ilPageLayout($row['layout_id']));
323  }
324 
325  return $arr_layouts;
326  }
327 
331  public static function activeLayouts($a_special_page = false, $a_module = null)
332  {
333  return self::getLayouts(true, $a_special_page, $a_module);
334  }
335 
344  static function import($a_filename, $a_filepath)
345  {
346  include_once("./Services/Export/classes/class.ilImport.php");
347  $imp = new ilImport();
348  $imp->importEntity($a_filepath, $a_filename,
349  "pgtp", "Services/COPage");
350  }
351 
352  static function getAvailableModules()
353  {
354  global $lng;
355 
356  return array(
357  self::MODULE_SCORM => $lng->txt("style_page_layout_module_scorm"),
358  self::MODULE_PORTFOLIO => $lng->txt("style_page_layout_module_portfolio")
359  );
360  }
361 }
362 
363 ?>