ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilXHTMLPage.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
17 {
21  protected $db;
22 
23  public $id = 0;
24  public $content = "";
25 
31  public function __construct($a_id = 0)
32  {
33  global $DIC;
34 
35  $this->db = $DIC->database();
36  if ($a_id > 0) {
37  $this->setId($a_id);
38  $this->read();
39  }
40  }
41 
47  public function getId()
48  {
49  return $this->id;
50  }
51 
57  public function setId($a_id)
58  {
59  $this->id = $a_id;
60  }
61 
67  public function getContent()
68  {
69  return $this->content;
70  }
71 
77  public function setContent($a_content)
78  {
79  $this->content = $a_content;
80  }
81 
85  public function read()
86  {
87  $ilDB = $this->db;
88 
89  $set = $ilDB->query("SELECT * FROM xhtml_page WHERE id = " .
90  $ilDB->quote($this->getId(), "integer"));
91  if ($rec = $ilDB->fetchAssoc($set)) {
92  $this->setContent($rec["content"]);
93  }
94  }
95 
99  public static function _lookupContent($a_id)
100  {
101  global $DIC;
102 
103  $ilDB = $DIC->database();
104 
105  $set = $ilDB->query("SELECT content FROM xhtml_page WHERE id = " .
106  $ilDB->quote($a_id, "integer"));
107  if ($rec = $ilDB->fetchAssoc($set)) {
108  return $rec["content"];
109  }
110  }
111 
115  public static function _lookupSavedContent($a_id)
116  {
117  global $DIC;
118 
119  $ilDB = $DIC->database();
120 
121  $set = $ilDB->query("SELECT save_content FROM xhtml_page WHERE id = " .
122  $ilDB->quote($a_id, "integer"));
123  if ($rec = $ilDB->fetchAssoc($set)) {
124  return $rec["save_content"];
125  }
126  }
127 
131  public function save()
132  {
133  $ilDB = $this->db;
134 
135  if ($this->getId() > 0) {
136  $old_content = ilXHTMLPage::_lookupContent($this->getId());
137  $ilDB->update("xhtml_page", array(
138  "content" => array("clob", $this->getContent()),
139  "save_content" => array("clob", $old_content)
140  ), array(
141  "id" => array("integer", $this->getId())
142  ));
143  } else {
144  $this->setId($ilDB->nextId("xhtml_page"));
145  $ilDB->insert("xhtml_page", array(
146  "id" => array("integer", $this->getId()),
147  "content" => array("clob", $this->getContent())
148  ));
149  }
150  }
151 
155  public function undo()
156  {
157  $ilDB = $this->db;
158 
159  if ($this->getId() > 0) {
161  $save_content = ilXHTMLPage::_lookupSavedContent($this->getId());
162  $ilDB->update("xhtml_page", array(
163  "content" => array("clob", $save_content),
164  "save_content" => array("clob", $content)
165  ), array(
166  "id" => array("integer", $this->getId())
167  ));
168  }
169  }
170 
174  public function clear()
175  {
176  $ilDB = $this->db;
177 
178  if ($this->getId() > 0) {
179  $this->setContent("");
180  $this->save();
181  }
182  }
183 }
getId()
Get page ID.
global $DIC
Definition: saml.php:7
static _lookupContent($a_id)
Lookup Content.
read()
Read page data from database.
getContent()
Get content of page.
save()
Save the page.
__construct($a_id=0)
Constructor.
$a_content
Definition: workflow.php:93
Create styles array
The data for the language used.
XHTML Page class.
undo()
Undo last change.
global $ilDB
setContent($a_content)
Set content of page.
setId($a_id)
Set page ID.
static _lookupSavedContent($a_id)
Lookup Saved Content.
clear()
Clear page.