ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_once("./Services/COPage/classes/class.ilPageContent.php");
6
18{
19 var $dom;
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
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 $a_output = $this->handleAccess($a_output, $a_mode);
125
126 return $a_output;
127 }
128
134 function setActiveFrom($a_unix_ts)
135 {
136 if ($a_unix_ts > 0)
137 {
138 $this->sec_node->set_attribute("ActiveFrom", $a_unix_ts);
139 }
140 else
141 {
142 if ($this->sec_node->has_attribute("ActiveFrom"))
143 {
144 $this->sec_node->remove_attribute("ActiveFrom");
145 }
146 }
147 }
148
154 function getActiveFrom()
155 {
156 if (is_object($this->sec_node))
157 {
158 return $this->sec_node->get_attribute("ActiveFrom");
159 }
160
161 return "";
162 }
163
169 function setActiveTo($a_unix_ts)
170 {
171 if ($a_unix_ts > 0)
172 {
173 $this->sec_node->set_attribute("ActiveTo", $a_unix_ts);
174 }
175 else
176 {
177 if ($this->sec_node->has_attribute("ActiveTo"))
178 {
179 $this->sec_node->remove_attribute("ActiveTo");
180 }
181 }
182 }
183
189 function getActiveTo()
190 {
191 if (is_object($this->sec_node))
192 {
193 return $this->sec_node->get_attribute("ActiveTo");
194 }
195
196 return "";
197 }
198
205 protected function setAttribute($a_attr, $a_val)
206 {
207 if (!empty($a_val))
208 {
209 $this->sec_node->set_attribute($a_attr, $a_val);
210 }
211 else
212 {
213 if ($this->sec_node->has_attribute($a_attr))
214 {
215 $this->sec_node->remove_attribute($a_attr);
216 }
217 }
218 }
219
226 function getAttribute($a_attr)
227 {
228 if (is_object($this->sec_node))
229 {
230 return $this->sec_node->get_attribute($a_attr);
231 }
232 return "";
233 }
234
240 function setPermission($a_val)
241 {
242 $this->setAttribute("Permission", $a_val);
243 }
244
250 function getPermission()
251 {
252 return $this->getAttribute("Permission");
253 }
254
255
261 function setPermissionRefId($a_ref_id)
262 {
263 $this->setAttribute("PermissionRefId", "il__ref_".$a_ref_id);
264 }
265
272 {
273 $id = explode("_", $this->getAttribute("PermissionRefId"));
274 if (in_array($id[1], array("", 0, IL_INST_ID)))
275 {
276 return $id[3];
277 }
278 return "";
279 }
280
284 function setNoLink()
285 {
286 ilDOMUtil::deleteAllChildsByName($this->sec_node, array("IntLink", "ExtLink"));
287 }
288
293 function setExtLink($a_href)
294 {
295 $this->setNoLink();
296 if (trim($a_href) != "")
297 {
298 $attributes = array("Href" => trim($a_href));
299 ilDOMUtil::setFirstOptionalElement($this->dom, $this->sec_node, "ExtLink",
300 array(""), "", $attributes);
301 }
302 }
303
307 function setIntLink($a_type, $a_target, $a_target_frame)
308 {
309 $this->setNoLink();
310 $attributes = array("Type" => $a_type, "Target" => $a_target,
311 "TargetFrame" => $a_target_frame);
312 ilDOMUtil::setFirstOptionalElement($this->dom, $this->sec_node, "IntLink",
313 array(""), "", $attributes);
314 }
315
322 function getLink()
323 {
324 $childs = $this->sec_node->child_nodes();
325 foreach($childs as $child)
326 {
327 if ($child->node_name() == "ExtLink")
328 {
329 return array("LinkType" => "ExtLink",
330 "Href" => $child->get_attribute("Href"));
331 }
332 if ($child->node_name() == "IntLink")
333 {
334 return array("LinkType" => "IntLink",
335 "Target" => $child->get_attribute("Target"),
336 "Type" => $child->get_attribute("Type"),
337 "TargetFrame" => $child->get_attribute("TargetFrame"));
338 }
339 }
340 return array("LinkType" => "NoLink");
341 }
342
343
349 function handleAccess($a_html, $a_mode)
350 {
351 global $ilAccess;
352
353 while (($start = strpos($a_html, "{{{{{Section;Access;")) > 0)
354 {
355 $end = strpos($a_html, "}}}}}", $start);
356 $access_attr = explode(";", substr($a_html, $start, $end - $start));
357 $id = explode("_", $access_attr[3]);
358 $access = true;
359 if (in_array($id[1], array("", 0, IL_INST_ID)) && $id[3] > 0)
360 {
361 $access = $ilAccess->checkAccess($access_attr[5], "", $id[3]);
362 }
363 if ($access)
364 {
365 $a_html = substr($a_html, 0, $start).substr($a_html, $end + 5);
366 }
367 else
368 {
369 $end = strpos($a_html, "{{{{{Section;Access}}}}}", $start);
370 $a_html = substr($a_html, 0, $start).substr($a_html, $end + 24);
371 }
372 }
373
374 $a_html = str_replace("{{{{{Section;Access}}}}}", "", $a_html);
375
376 return $a_html;
377 }
378
384 static function saveTimings($a_page)
385 {
386 global $ilDB;
387
388 $ilDB->manipulate("DELETE FROM copg_section_timings WHERE ".
389 " page_id = ".$ilDB->quote($a_page->getId(), "integer").
390 " AND parent_type = ".$ilDB->quote($a_page->getParentType(), "text")
391 );
392
393 $xml = $a_page->getXMLFromDom();
394
395 $doc = domxml_open_mem($xml);
396
397 // media aliases
398 $xpc = xpath_new_context($doc);
399 $path = "//Section";
400 $res = xpath_eval($xpc, $path);
401 for ($i=0; $i < count($res->nodeset); $i++)
402 {
403 $from = $res->nodeset[$i]->get_attribute("ActiveFrom");
404 if ($from != "")
405 {
406 $ilDB->replace("copg_section_timings",
407 array(
408 "page_id" => array("integer", $a_page->getId()),
409 "parent_type" => array("text", $a_page->getParentType()),
410 "unix_ts" => array("integer", $from)
411 ),
412 array()
413 );
414 }
415 $to = $res->nodeset[$i]->get_attribute("ActiveTo");
416 if ($to != "")
417 {
418 $ilDB->replace("copg_section_timings",
419 array(
420 "page_id" => array("integer", $a_page->getId()),
421 "parent_type" => array("text", $a_page->getParentType()),
422 "unix_ts" => array("integer", $to)
423 ),
424 array()
425 );
426 }
427 }
428 }
429
436 static function getCacheTriggerString($a_page)
437 {
438 global $ilDB;
439
440 $set = $ilDB->query("SELECT * FROM copg_section_timings ".
441 " WHERE page_id = ".$ilDB->quote($a_page->getId(), "integer").
442 " AND parent_type = ".$ilDB->quote($a_page->getParentType(), "text")
443 );
444 $str = "";
445 $current_ts = new ilDateTime(time(),IL_CAL_UNIX);
446 $current_ts = $current_ts->get(IL_CAL_UNIX);
447 while ($rec = $ilDB->fetchAssoc($set))
448 {
449 $unix_ts = $rec["unix_ts"];
450 if ($unix_ts < $current_ts)
451 {
452 $unix_ts.= "a";
453 }
454 $str.= "-".$unix_ts;
455 }
456
457 return $str;
458 }
459
466 function insertTimings($a_html)
467 {
468 global $ilCtrl, $lng;
469
470 $c_pos = 0;
471 $start = strpos($a_html, "{{{{{Section;ActiveFrom");
472 if (is_int($start))
473 {
474 $end = strpos($a_html, "}}}}}", $start);
475 }
476 $i = 1;
477 while ($end > 0)
478 {
479 $param = substr($a_html, $start + 13, $end - $start - 13);
480 $param = explode(";", $param);
481 $from = $param[1];
482 $to = $param[3];
483 $html = "";
484 if ($from != "")
485 {
487 $from = new ilDateTime($from, IL_CAL_UNIX);
488 $html.= $lng->txt("cont_active_from").": ".ilDatePresentation::formatDate($from);
489 }
490 if ($to != "")
491 {
492 $to = new ilDateTime($to, IL_CAL_UNIX);
493 $html.= " ".$lng->txt("cont_active_to").": ".ilDatePresentation::formatDate($to);
494 }
495
496 $h2 = substr($a_html, 0, $start).
497 $html.
498 substr($a_html, $end + 5);
499 $a_html = $h2;
500 $i++;
501
502 $start = strpos($a_html, "{{{{{Section;ActiveFrom;", $start + 5);
503 $end = 0;
504 if (is_int($start))
505 {
506 $end = strpos($a_html, "}}}}}", $start);
507 }
508 }
509 return $a_html;
510 }
511
512}
513
514?>
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_INSERT_AFTER
static setFirstOptionalElement($doc, $parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found,...
static deleteAllChildsByName($a_parent, $a_node_names)
delete all childs of a node by names in $a_node_names
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Class ilPCSection.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create section node in xml.
insertTimings($a_html)
Insert timings (in edit mode)
setCharacteristic($a_char)
Set Characteristic of section.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
setExtLink($a_href)
Set link of area to an external one.
setActiveTo($a_unix_ts)
Set activation to.
setPermission($a_val)
Set permission.
static saveTimings($a_page)
Save timings.
static getCacheTriggerString($a_page)
Get page cache update trigger string.
init()
Init page content component.
getPermission()
Get permission.
handleAccess($a_html, $a_mode)
modifyPageContentPostXsl($a_output, $a_mode)
Modify page content after xsl.
getAttribute($a_attr)
Get attribute.
getCharacteristic()
Get characteristic of section.
getActiveTo()
Get activation to.
setIntLink($a_type, $a_target, $a_target_frame)
Set link of area to an internal one.
setPermissionRefId($a_ref_id)
Set permission ref id.
setNoLink()
Set no link.
static getLangVars()
Get lang vars needed for editing.
setNode($a_node)
Set node.
setAttribute($a_attr, $a_val)
Set attribute.
setActiveFrom($a_unix_ts)
Set activation from.
getPermissionRefId()
Get permission ref id.
getLink()
Get link.
getActiveFrom()
Get activation from.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.
$html
Definition: example_001.php:87
global $ilCtrl
Definition: ilias.php:18
xpath_eval($xpath_context, $eval_str, $contextnode=null)
domxml_open_mem($str, $mode=0, &$error=NULL)
xpath_new_context($dom_document)
global $lng
Definition: privfeed.php:17
global $ilDB
$a_type
Definition: workflow.php:93