ILIAS  Release_4_0_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-2009 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  var $layout_id = null;
20  var $title = null;
21  var $description = null;
22  var $active = null;
23 
24  function ilPageLayout($a_id=null) {
25  global $ilias, $ilDB;
26  //create new instance
27  if ($a_id == null) {
28  $this->layout_id = $ilDB->nextId("page_layout");
29  $ilDB->insert("page_layout", array(
30  "layout_id" => array("integer", $this->layout_id),
31  "active" => array("integer", 0),
32  "title" => array("text", ""),
33  "content" => array("clob", ""),
34  "description" => array("text", "")
35  ));
36  //$query = "INSERT INTO page_layout(active) values (0);";
37  //$result = $ilDB->query($query);
38  //$query = "SELECT LAST_INSERT_ID() as id";
39  //$res = $ilDB->query($query);
40  //$row = $res->fetchRow(DB_FETCHMODE_OBJECT);
41  //$this->layout_id = $row->id;
42  $this->active = false;
43  }
44  else {
45  $this->layout_id = $a_id;
46  }
47  }
48 
49  public function getActive() {
50  return $this->active;
51  }
52 
53  public function getDescription() {
54  return $this->description;
55  }
56 
57  public function setDescription($a_description) {
58  $this->description = $a_description;
59  }
60 
61  public function getTitle() {
62  return $this->title;
63  }
64 
65  public function setTitle($a_title) {
66  $this->title = $a_title;
67  }
68 
69  public function getId() {
70  return $this->layout_id;
71  }
72 
73 
74  public function activate($a_setting=true) {
75  global $ilias, $ilDB;
76  $query = "UPDATE page_layout SET active=".$ilDB->quote($a_setting, "integer").
77  " WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
78  $result = $ilDB->manipulate($query);
79  }
80 
81  public function delete($a_setting=true) {
82  global $ilias, $ilDB;
83  $query = "DELETE FROM page_layout WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
84  $result = $ilDB->manipulate($query);
85  }
86 
87  public function update() {
88  global $ilias, $ilDB;
89  $query = "UPDATE page_layout SET title=".$ilDB->quote($this->title, "text").
90  ",description =".$ilDB->quote($this->description, "text").
91  ",active =".$ilDB->quote($this->active, "integer").
92  " WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
93  $result = $ilDB->manipulate($query);
94  }
95 
96  public function readObject() {
97  global $ilias, $ilDB;
98  $query = "SELECT * FROM page_layout WHERE layout_id =".$ilDB->quote($this->layout_id, "integer");
99  $result = $ilDB->query($query);
100  $row = $ilDB->fetchAssoc($result);
101  $this->title=$row['title'];
102  $this->description=$row['description'];
103  $this->active=$row['active'];
104  }
105 
106  public function getXMLContent() {
107  global $ilias, $ilDB;
108  $r = $ilias->db->query("SELECT content FROM page_object WHERE parent_type='stys' AND page_id=".
109  $ilDB->quote($this->layout_id));
110  $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
111  return $row['content'];
112  }
113 
114 
115  public function getPreview() {
116  return $this->generatePreview();
117  }
118 
119 
120  private function getXSLPath() {
121  return "./Services/Style/xml/layout2html.xsl";
122  }
123 
124  private function generatePreview() {
125 
126  $xml = $this->getXMLContent();
127 
128  $dom = @domxml_open_mem($xml, DOMXML_LOAD_PARSING, $error);
129  $xpc = xpath_new_context($dom);
130  $path = "////PlaceHolder";
131  $res =& xpath_eval($xpc, $path);
132 
133  foreach ($res->nodeset as $item){
134  $height = $item->get_attribute("Height");
135 
136  $height = eregi_replace("px","",$height);
137  $height=$height/10;
138  $item->set_attribute("Height",$height."px");
139  }
140  $xsl = file_get_contents($this->getXSLPath());
141 
142  $xml = $dom->dump_mem(0, "UTF-8");
143 
144  $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
145 
146  $xh = xslt_create();
147  $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL);
148  xslt_error($xh);
149  xslt_free($xh);
150  return $output;
151  }
152 
158  public static function getLayoutsAsArray($a_active=0){
159 
160  global $ilDB;
161  $arr_layouts = array();
162  if ($active!=0) {
163  $add ="WHERE (active=1)";
164  }
165  $query = "SELECT * FROM page_layout $add ORDER BY title ";
166  $result = $ilDB->query($query);
167  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
168  {
169  array_push($arr_layouts,$row);
170  }
171  return $arr_layouts;
172 
173  }
174 
175  public static function getLayouts($a_active=false){
176  global $ilDB;
177  $arr_layouts = array();
178  $add="";
179  if ($a_active) {
180  $add ="WHERE (active=1)";
181  }
182  $query = "SELECT layout_id FROM page_layout $add ORDER BY title ";
183  $result = $ilDB->query($query);
184  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
185  {
186  array_push($arr_layouts,new ilPageLayout($row['layout_id']));
187  }
188  return $arr_layouts;
189  }
190 
191  public static function activeLayouts()
192  {
193  return self::getLayouts(true);
194  }
195 
196 }