ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilPCSection.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Services/COPage/classes/class.ilPageContent.php");
6 
18 {
19  var $dom;
20  var $sec_node;
21 
25  function init()
26  {
27  $this->setType("sec");
28  }
29 
33  function setNode(&$a_node)
34  {
35  parent::setNode($a_node); // this is the PageContent node
36  $this->sec_node =& $a_node->first_child(); // this is the Section node
37  }
38 
45  function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
46  {
47  $this->node = $this->createPageContentNode();
48  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
49  $this->sec_node =& $this->dom->create_element("Section");
50  $this->sec_node =& $this->node->append_child($this->sec_node);
51  $this->sec_node->set_attribute("Characteristic", "Block");
52  }
53 
59  function setCharacteristic($a_char)
60  {
61  if (!empty($a_char))
62  {
63  $this->sec_node->set_attribute("Characteristic", $a_char);
64  }
65  else
66  {
67  if ($this->sec_node->has_attribute("Characteristic"))
68  {
69  $this->sec_node->remove_attribute("Characteristic");
70  }
71  }
72  }
73 
79  function getCharacteristic()
80  {
81  if (is_object($this->sec_node))
82  {
83  $char = $this->sec_node->get_attribute("Characteristic");
84  if (substr($char, 0, 4) == "ilc_")
85  {
86  $char = substr($char, 4);
87  }
88  return $char;
89  }
90  }
91 
96  static function getLangVars()
97  {
98  return array("ed_insert_section");
99  }
100 
109  static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
110  {
111  include_once("./Services/COPage/classes/class.ilPCSection.php");
112  self::saveTimings($a_page);
113  }
114 
121  function modifyPageContentPostXsl($a_output, $a_mode)
122  {
123  $a_output = self::insertTimings($a_output);
124 
125  return $a_output;
126  }
127 
133  function setActiveFrom($a_unix_ts)
134  {
135  if ($a_unix_ts > 0)
136  {
137  $this->sec_node->set_attribute("ActiveFrom", $a_unix_ts);
138  }
139  else
140  {
141  if ($this->sec_node->has_attribute("ActiveFrom"))
142  {
143  $this->sec_node->remove_attribute("ActiveFrom");
144  }
145  }
146  }
147 
153  function getActiveFrom()
154  {
155  if (is_object($this->sec_node))
156  {
157  return $this->sec_node->get_attribute("ActiveFrom");
158  }
159 
160  return "";
161  }
162 
168  function setActiveTo($a_unix_ts)
169  {
170  if ($a_unix_ts > 0)
171  {
172  $this->sec_node->set_attribute("ActiveTo", $a_unix_ts);
173  }
174  else
175  {
176  if ($this->sec_node->has_attribute("ActiveTo"))
177  {
178  $this->sec_node->remove_attribute("ActiveTo");
179  }
180  }
181  }
182 
188  function getActiveTo()
189  {
190  if (is_object($this->sec_node))
191  {
192  return $this->sec_node->get_attribute("ActiveTo");
193  }
194 
195  return "";
196  }
197 
203  static function saveTimings($a_page)
204  {
205  global $ilDB;
206 
207  $ilDB->manipulate("DELETE FROM copg_section_timings WHERE ".
208  " page_id = ".$ilDB->quote($a_page->getId(), "integer").
209  " AND parent_type = ".$ilDB->quote($a_page->getParentType(), "text")
210  );
211 
212  $xml = $a_page->getXMLFromDom();
213 
214  $doc = domxml_open_mem($xml);
215 
216  // media aliases
217  $xpc = xpath_new_context($doc);
218  $path = "//Section";
219  $res = xpath_eval($xpc, $path);
220  for ($i=0; $i < count($res->nodeset); $i++)
221  {
222  $from = $res->nodeset[$i]->get_attribute("ActiveFrom");
223  if ($from != "")
224  {
225  $ilDB->manipulate("INSERT INTO copg_section_timings ".
226  "(page_id, parent_type, unix_ts) VALUES (".
227  $ilDB->quote($a_page->getId(), "integer").",".
228  $ilDB->quote($a_page->getParentType(), "text").",".
229  $ilDB->quote($from, "text").
230  ")");
231  }
232  $to = $res->nodeset[$i]->get_attribute("ActiveTo");
233  if ($to != "")
234  {
235  $ilDB->manipulate("INSERT INTO copg_section_timings ".
236  "(page_id, parent_type, unix_ts) VALUES (".
237  $ilDB->quote($a_page->getId(), "integer").",".
238  $ilDB->quote($a_page->getParentType(), "text").",".
239  $ilDB->quote($to, "text").
240  ")");
241  }
242  }
243  }
244 
251  static function getCacheTriggerString($a_page)
252  {
253  global $ilDB;
254 
255  $set = $ilDB->query("SELECT * FROM copg_section_timings ".
256  " WHERE page_id = ".$ilDB->quote($a_page->getId(), "integer").
257  " AND parent_type = ".$ilDB->quote($a_page->getParentType(), "text")
258  );
259  $str = "";
260  $current_ts = new ilDateTime(time(),IL_CAL_UNIX);
261  $current_ts = $current_ts->get(IL_CAL_UNIX);
262  while ($rec = $ilDB->fetchAssoc($set))
263  {
264  $unix_ts = $rec["unix_ts"];
265  if ($unix_ts < $current_ts)
266  {
267  $unix_ts.= "a";
268  }
269  $str.= "-".$unix_ts;
270  }
271 
272  return $str;
273  }
274 
281  function insertTimings($a_html)
282  {
283  global $ilCtrl, $lng;
284 
285  $c_pos = 0;
286  $start = strpos($a_html, "{{{{{Section;ActiveFrom");
287  if (is_int($start))
288  {
289  $end = strpos($a_html, "}}}}}", $start);
290  }
291  $i = 1;
292  while ($end > 0)
293  {
294  $param = substr($a_html, $start + 13, $end - $start - 13);
295  $param = explode(";", $param);
296  $from = $param[1];
297  $to = $param[3];
298  $html = "";
299  if ($from != "")
300  {
302  $from = new ilDateTime($from, IL_CAL_UNIX);
303  $html.= $lng->txt("cont_active_from").": ".ilDatePresentation::formatDate($from);
304  }
305  if ($to != "")
306  {
307  $to = new ilDateTime($to, IL_CAL_UNIX);
308  $html.= " ".$lng->txt("cont_active_to").": ".ilDatePresentation::formatDate($to);
309  }
310 
311  $h2 = substr($a_html, 0, $start).
312  $html.
313  substr($a_html, $end + 5);
314  $a_html = $h2;
315  $i++;
316 
317  $start = strpos($a_html, "{{{{{Section;ActiveFrom;", $start + 5);
318  $end = 0;
319  if (is_int($start))
320  {
321  $end = strpos($a_html, "}}}}}", $start);
322  }
323  }
324  return $a_html;
325  }
326 
327 }
328 
329 ?>
modifyPageContentPostXsl($a_output, $a_mode)
Modify page content after xsl.
domxml_open_mem($str, $mode=DOMXML_LOAD_PARSING, &$error=NULL)
getActiveFrom()
Get activation from.
xpath_new_context($dom_document)
getActiveTo()
Get activation to.
getCharacteristic()
Get characteristic of section.
insertTimings($a_html)
Insert timings (in edit mode)
xpath_eval($xpath_context, $eval_str, $contextnode=null)
static setUseRelativeDates($a_status)
set use relative dates
setType($a_type)
Set Type.
init()
Init page content component.
setActiveTo($a_unix_ts)
Set activation to.
const IL_CAL_UNIX
Class ilPageContent.
Class ilPCSection.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
global $ilCtrl
Definition: ilias.php:18
static saveTimings($a_page)
Save timings.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
const IL_INSERT_AFTER
static getCacheTriggerString($a_page)
Get page cache update trigger string.
setActiveFrom($a_unix_ts)
Set activation from.
static getLangVars()
Get lang vars needed for editing.
setCharacteristic($a_char)
Set Characteristic of section.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
global $lng
Definition: privfeed.php:40
$path
Definition: index.php:22
global $ilDB
setNode(&$a_node)
Set node.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create section node in xml.
$html
Definition: example_001.php:87