ILIAS  release_7 Revision v7.30-3-g800a261c036
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{
22 protected $access;
23
27 protected $ctrl;
28
32 protected $lng;
33
34 public $dom;
35 public $sec_node;
36
40 public function init()
41 {
42 global $DIC;
43
44 $this->access = $DIC->access();
45 $this->ctrl = $DIC->ctrl();
46 $this->lng = $DIC->language();
47 $this->setType("sec");
48 }
49
53 public function setNode($a_node)
54 {
55 parent::setNode($a_node); // this is the PageContent node
56 $this->sec_node = $a_node->first_child(); // this is the Section node
57 }
58
65 public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
66 {
67 $this->node = $this->createPageContentNode();
68 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
69 $this->sec_node = $this->dom->create_element("Section");
70 $this->sec_node = $this->node->append_child($this->sec_node);
71 $this->sec_node->set_attribute("Characteristic", "Block");
72 }
73
79 public function setCharacteristic($a_char)
80 {
81 if (!empty($a_char)) {
82 $this->sec_node->set_attribute("Characteristic", $a_char);
83 } else {
84 if ($this->sec_node->has_attribute("Characteristic")) {
85 $this->sec_node->remove_attribute("Characteristic");
86 }
87 }
88 }
89
95 public function getCharacteristic()
96 {
97 if (is_object($this->sec_node)) {
98 $char = $this->sec_node->get_attribute("Characteristic");
99 if (substr($char, 0, 4) == "ilc_") {
100 $char = substr($char, 4);
101 }
102 return $char;
103 }
104 }
105
110 public static function getLangVars()
111 {
112 return array("ed_insert_section");
113 }
114
123 public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
124 {
125 include_once("./Services/COPage/classes/class.ilPCSection.php");
126 self::saveTimings($a_page);
127 }
128
132 public function modifyPageContentPostXsl($a_output, $a_mode, $a_abstract_only = false)
133 {
134 $a_output = self::insertTimings($a_output);
135 $a_output = $this->handleAccess($a_output, $a_mode);
136
137 return $a_output;
138 }
139
145 public function setActiveFrom($a_unix_ts)
146 {
147 if ($a_unix_ts > 0) {
148 $this->sec_node->set_attribute("ActiveFrom", $a_unix_ts);
149 } else {
150 if ($this->sec_node->has_attribute("ActiveFrom")) {
151 $this->sec_node->remove_attribute("ActiveFrom");
152 }
153 }
154 }
155
161 public function getActiveFrom()
162 {
163 if (is_object($this->sec_node)) {
164 return $this->sec_node->get_attribute("ActiveFrom");
165 }
166
167 return "";
168 }
169
175 public function setActiveTo($a_unix_ts)
176 {
177 if ($a_unix_ts > 0) {
178 $this->sec_node->set_attribute("ActiveTo", $a_unix_ts);
179 } else {
180 if ($this->sec_node->has_attribute("ActiveTo")) {
181 $this->sec_node->remove_attribute("ActiveTo");
182 }
183 }
184 }
185
191 public function getActiveTo()
192 {
193 if (is_object($this->sec_node)) {
194 return $this->sec_node->get_attribute("ActiveTo");
195 }
196
197 return "";
198 }
199
206 protected function setAttribute($a_attr, $a_val)
207 {
208 if (!empty($a_val)) {
209 $this->sec_node->set_attribute($a_attr, $a_val);
210 } else {
211 if ($this->sec_node->has_attribute($a_attr)) {
212 $this->sec_node->remove_attribute($a_attr);
213 }
214 }
215 }
216
223 public function getAttribute($a_attr)
224 {
225 if (is_object($this->sec_node)) {
226 return $this->sec_node->get_attribute($a_attr);
227 }
228 return "";
229 }
230
236 public function setPermission($a_val)
237 {
238 $this->setAttribute("Permission", $a_val);
239 }
240
246 public function getPermission()
247 {
248 return $this->getAttribute("Permission");
249 }
250
251
257 public function setPermissionRefId($a_ref_id)
258 {
259 $this->setAttribute("PermissionRefId", "il__ref_" . $a_ref_id);
260 }
261
267 public function getPermissionRefId()
268 {
269 $id = explode("_", $this->getAttribute("PermissionRefId"));
270 if (in_array($id[1], array("", 0, IL_INST_ID))) {
271 return $id[3];
272 }
273 return "";
274 }
275
279 public function setNoLink()
280 {
281 ilDOMUtil::deleteAllChildsByName($this->sec_node, array("IntLink", "ExtLink"));
282 }
283
288 public function setExtLink($a_href)
289 {
290 $this->setNoLink();
291 if (trim($a_href) != "") {
292 $attributes = array("Href" => trim($a_href));
294 $this->dom,
295 $this->sec_node,
296 "ExtLink",
297 array(""),
298 "",
300 );
301 }
302 }
303
307 public 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);
313 $this->dom,
314 $this->sec_node,
315 "IntLink",
316 array(""),
317 "",
319 );
320 }
321
328 public function getLink()
329 {
330 $childs = $this->sec_node->child_nodes();
331 foreach ($childs as $child) {
332 if ($child->node_name() == "ExtLink") {
333 return array("LinkType" => "ExtLink",
334 "Href" => $child->get_attribute("Href"));
335 }
336 if ($child->node_name() == "IntLink") {
337 return array("LinkType" => "IntLink",
338 "Target" => $child->get_attribute("Target"),
339 "Type" => $child->get_attribute("Type"),
340 "TargetFrame" => $child->get_attribute("TargetFrame"));
341 }
342 }
343 return array("LinkType" => "NoLink");
344 }
345
346
352 public function handleAccess($a_html, $a_mode)
353 {
354 $ilAccess = $this->access;
355
356 while (($start = strpos($a_html, "{{{{{Section;Access;")) > 0) {
357 $end = strpos($a_html, "}}}}}", $start);
358 $access_attr = explode(";", substr($a_html, $start, $end - $start));
359 $id = explode("_", $access_attr[3]);
360 $section_nr = $access_attr[6];
361 $access = true;
362 if (in_array($id[1], array("", 0, IL_INST_ID)) && $id[3] > 0) {
363 if ($access_attr[5] == "no_read") {
364 $access = !$ilAccess->checkAccess("read", "", $id[3]);
365 } else {
366 $access = $ilAccess->checkAccess($access_attr[5], "", $id[3]);
367 }
368 }
369 if ($a_mode == ilPageObjectGUI::EDIT) {
370 $access = true;
371 }
372 $end_limiter = "{{{{{Section;AccessEnd;".$section_nr."}}}}}";
373 if ($access) {
374 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + 5);
375 $a_html = str_replace($end_limiter, "", $a_html);
376 } else {
377 $end = strpos($a_html, $end_limiter, $start);
378 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + strlen($end_limiter));
379 }
380 }
381
382 $a_html = str_replace("{{{{{Section;Access}}}}}", "", $a_html);
383 return $a_html;
384 }
385
391 public static function saveTimings($a_page)
392 {
393 global $DIC;
394
395 $ilDB = $DIC->database();
396
397 $ilDB->manipulate(
398 "DELETE FROM copg_section_timings WHERE " .
399 " page_id = " . $ilDB->quote($a_page->getId(), "integer") .
400 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
401 );
402
403 $xml = $a_page->getXMLFromDom();
404
405 $doc = domxml_open_mem($xml);
406
407 // media aliases
408 $xpc = xpath_new_context($doc);
409 $path = "//Section";
410 $res = xpath_eval($xpc, $path);
411 for ($i = 0; $i < count($res->nodeset); $i++) {
412 $from = $res->nodeset[$i]->get_attribute("ActiveFrom");
413 if ($from != "") {
414 $ilDB->replace(
415 "copg_section_timings",
416 array(
417 "page_id" => array("integer", $a_page->getId()),
418 "parent_type" => array("text", $a_page->getParentType()),
419 "unix_ts" => array("integer", $from)
420 ),
421 array()
422 );
423 }
424 $to = $res->nodeset[$i]->get_attribute("ActiveTo");
425 if ($to != "") {
426 $ilDB->replace(
427 "copg_section_timings",
428 array(
429 "page_id" => array("integer", $a_page->getId()),
430 "parent_type" => array("text", $a_page->getParentType()),
431 "unix_ts" => array("integer", $to)
432 ),
433 array()
434 );
435 }
436 }
437 }
438
445 public static function getCacheTriggerString($a_page)
446 {
447 global $DIC;
448
449 $ilDB = $DIC->database();
450
451 $set = $ilDB->query(
452 "SELECT * FROM copg_section_timings " .
453 " WHERE page_id = " . $ilDB->quote($a_page->getId(), "integer") .
454 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
455 );
456 $str = "1"; // changed to 1 to force cache miss for #24277
457 $current_ts = new ilDateTime(time(), IL_CAL_UNIX);
458 $current_ts = $current_ts->get(IL_CAL_UNIX);
459 while ($rec = $ilDB->fetchAssoc($set)) {
460 $unix_ts = $rec["unix_ts"];
461 if ($unix_ts < $current_ts) {
462 $unix_ts .= "a";
463 }
464 $str .= "-" . $unix_ts;
465 }
466
467 return $str;
468 }
469
476 public function insertTimings($a_html)
477 {
478 $ilCtrl = $this->ctrl;
480
481 $c_pos = 0;
482 $start = strpos($a_html, "{{{{{Section;ActiveFrom");
483 if (is_int($start)) {
484 $end = strpos($a_html, "}}}}}", $start);
485 }
486 $i = 1;
487 while ($end > 0) {
488 $param = substr($a_html, $start + 13, $end - $start - 13);
489 $param = explode(";", $param);
490 $from = $param[1];
491 $to = $param[3];
492 $html = "";
493 if ($from != "") {
495 $from = new ilDateTime($from, IL_CAL_UNIX);
496 $html .= $lng->txt("cont_active_from") . ": " . ilDatePresentation::formatDate($from);
497 }
498 if ($to != "") {
499 $to = new ilDateTime($to, IL_CAL_UNIX);
500 $html .= " " . $lng->txt("cont_active_to") . ": " . ilDatePresentation::formatDate($to);
501 }
502
503 $h2 = substr($a_html, 0, $start) .
504 $html .
505 substr($a_html, $end + 5);
506 $a_html = $h2;
507 $i++;
508
509 $start = strpos($a_html, "{{{{{Section;ActiveFrom;", $start + 5);
510 $end = 0;
511 if (is_int($start)) {
512 $end = strpos($a_html, "}}}}}", $start);
513 }
514 }
515 return $a_html;
516 }
517}
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
@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)
getAttribute($a_attr)
Get attribute.
modifyPageContentPostXsl($a_output, $a_mode, $a_abstract_only=false)
@inheritDoc
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.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
xpath_eval($xpath_context, $eval_str, $contextnode=null)
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
$i
Definition: metadata.php:24
$attributes
Definition: metadata.php:231
$xml
Definition: metadata.php:332
foreach($_POST as $key=> $value) $res
global $ilDB
$param
Definition: xapitoken.php:29