ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
135 public function modifyPageContentPostXsl($a_output, $a_mode)
136 {
137 $a_output = self::insertTimings($a_output);
138 $a_output = $this->handleAccess($a_output, $a_mode);
139
140 return $a_output;
141 }
142
148 public function setActiveFrom($a_unix_ts)
149 {
150 if ($a_unix_ts > 0) {
151 $this->sec_node->set_attribute("ActiveFrom", $a_unix_ts);
152 } else {
153 if ($this->sec_node->has_attribute("ActiveFrom")) {
154 $this->sec_node->remove_attribute("ActiveFrom");
155 }
156 }
157 }
158
164 public function getActiveFrom()
165 {
166 if (is_object($this->sec_node)) {
167 return $this->sec_node->get_attribute("ActiveFrom");
168 }
169
170 return "";
171 }
172
178 public function setActiveTo($a_unix_ts)
179 {
180 if ($a_unix_ts > 0) {
181 $this->sec_node->set_attribute("ActiveTo", $a_unix_ts);
182 } else {
183 if ($this->sec_node->has_attribute("ActiveTo")) {
184 $this->sec_node->remove_attribute("ActiveTo");
185 }
186 }
187 }
188
194 public function getActiveTo()
195 {
196 if (is_object($this->sec_node)) {
197 return $this->sec_node->get_attribute("ActiveTo");
198 }
199
200 return "";
201 }
202
209 protected function setAttribute($a_attr, $a_val)
210 {
211 if (!empty($a_val)) {
212 $this->sec_node->set_attribute($a_attr, $a_val);
213 } else {
214 if ($this->sec_node->has_attribute($a_attr)) {
215 $this->sec_node->remove_attribute($a_attr);
216 }
217 }
218 }
219
226 public function getAttribute($a_attr)
227 {
228 if (is_object($this->sec_node)) {
229 return $this->sec_node->get_attribute($a_attr);
230 }
231 return "";
232 }
233
239 public function setPermission($a_val)
240 {
241 $this->setAttribute("Permission", $a_val);
242 }
243
249 public function getPermission()
250 {
251 return $this->getAttribute("Permission");
252 }
253
254
260 public function setPermissionRefId($a_ref_id)
261 {
262 $this->setAttribute("PermissionRefId", "il__ref_" . $a_ref_id);
263 }
264
270 public function getPermissionRefId()
271 {
272 $id = explode("_", $this->getAttribute("PermissionRefId"));
273 if (in_array($id[1], array("", 0, IL_INST_ID))) {
274 return $id[3];
275 }
276 return "";
277 }
278
282 public function setNoLink()
283 {
284 ilDOMUtil::deleteAllChildsByName($this->sec_node, array("IntLink", "ExtLink"));
285 }
286
291 public function setExtLink($a_href)
292 {
293 $this->setNoLink();
294 if (trim($a_href) != "") {
295 $attributes = array("Href" => trim($a_href));
297 $this->dom,
298 $this->sec_node,
299 "ExtLink",
300 array(""),
301 "",
303 );
304 }
305 }
306
310 public function setIntLink($a_type, $a_target, $a_target_frame)
311 {
312 $this->setNoLink();
313 $attributes = array("Type" => $a_type, "Target" => $a_target,
314 "TargetFrame" => $a_target_frame);
316 $this->dom,
317 $this->sec_node,
318 "IntLink",
319 array(""),
320 "",
322 );
323 }
324
331 public function getLink()
332 {
333 $childs = $this->sec_node->child_nodes();
334 foreach ($childs as $child) {
335 if ($child->node_name() == "ExtLink") {
336 return array("LinkType" => "ExtLink",
337 "Href" => $child->get_attribute("Href"));
338 }
339 if ($child->node_name() == "IntLink") {
340 return array("LinkType" => "IntLink",
341 "Target" => $child->get_attribute("Target"),
342 "Type" => $child->get_attribute("Type"),
343 "TargetFrame" => $child->get_attribute("TargetFrame"));
344 }
345 }
346 return array("LinkType" => "NoLink");
347 }
348
349
355 public function handleAccess($a_html, $a_mode)
356 {
357 $ilAccess = $this->access;
358
359 while (($start = strpos($a_html, "{{{{{Section;Access;")) > 0) {
360 $end = strpos($a_html, "}}}}}", $start);
361 $access_attr = explode(";", substr($a_html, $start, $end - $start));
362 $id = explode("_", $access_attr[3]);
363 $access = true;
364 if (in_array($id[1], array("", 0, IL_INST_ID)) && $id[3] > 0) {
365 $access = $ilAccess->checkAccess($access_attr[5], "", $id[3]);
366 }
367 if ($access) {
368 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + 5);
369 } else {
370 $end = strpos($a_html, "{{{{{Section;Access}}}}}", $start);
371 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + 24);
372 }
373 }
374
375 $a_html = str_replace("{{{{{Section;Access}}}}}", "", $a_html);
376
377 return $a_html;
378 }
379
385 public static function saveTimings($a_page)
386 {
387 global $DIC;
388
389 $ilDB = $DIC->database();
390
391 $ilDB->manipulate(
392 "DELETE FROM copg_section_timings WHERE " .
393 " page_id = " . $ilDB->quote($a_page->getId(), "integer") .
394 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
395 );
396
397 $xml = $a_page->getXMLFromDom();
398
399 $doc = domxml_open_mem($xml);
400
401 // media aliases
402 $xpc = xpath_new_context($doc);
403 $path = "//Section";
404 $res = xpath_eval($xpc, $path);
405 for ($i=0; $i < count($res->nodeset); $i++) {
406 $from = $res->nodeset[$i]->get_attribute("ActiveFrom");
407 if ($from != "") {
408 $ilDB->replace(
409 "copg_section_timings",
410 array(
411 "page_id" => array("integer", $a_page->getId()),
412 "parent_type" => array("text", $a_page->getParentType()),
413 "unix_ts" => array("integer", $from)
414 ),
415 array()
416 );
417 }
418 $to = $res->nodeset[$i]->get_attribute("ActiveTo");
419 if ($to != "") {
420 $ilDB->replace(
421 "copg_section_timings",
422 array(
423 "page_id" => array("integer", $a_page->getId()),
424 "parent_type" => array("text", $a_page->getParentType()),
425 "unix_ts" => array("integer", $to)
426 ),
427 array()
428 );
429 }
430 }
431 }
432
439 public static function getCacheTriggerString($a_page)
440 {
441 global $DIC;
442
443 $ilDB = $DIC->database();
444
445 $set = $ilDB->query(
446 "SELECT * FROM copg_section_timings " .
447 " WHERE page_id = " . $ilDB->quote($a_page->getId(), "integer") .
448 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
449 );
450 $str = "";
451 $current_ts = new ilDateTime(time(), IL_CAL_UNIX);
452 $current_ts = $current_ts->get(IL_CAL_UNIX);
453 while ($rec = $ilDB->fetchAssoc($set)) {
454 $unix_ts = $rec["unix_ts"];
455 if ($unix_ts < $current_ts) {
456 $unix_ts.= "a";
457 }
458 $str.= "-" . $unix_ts;
459 }
460
461 return $str;
462 }
463
470 public function insertTimings($a_html)
471 {
474
475 $c_pos = 0;
476 $start = strpos($a_html, "{{{{{Section;ActiveFrom");
477 if (is_int($start)) {
478 $end = strpos($a_html, "}}}}}", $start);
479 }
480 $i = 1;
481 while ($end > 0) {
482 $param = substr($a_html, $start + 13, $end - $start - 13);
483 $param = explode(";", $param);
484 $from = $param[1];
485 $to = $param[3];
486 $html = "";
487 if ($from != "") {
490 $html.= $lng->txt("cont_active_from") . ": " . ilDatePresentation::formatDate($from);
491 }
492 if ($to != "") {
493 $to = new ilDateTime($to, IL_CAL_UNIX);
494 $html.= " " . $lng->txt("cont_active_to") . ": " . ilDatePresentation::formatDate($to);
495 }
496
497 $h2 = substr($a_html, 0, $start) .
498 $html .
499 substr($a_html, $end + 5);
500 $a_html = $h2;
501 $i++;
502
503 $start = strpos($a_html, "{{{{{Section;ActiveFrom;", $start + 5);
504 $end = 0;
505 if (is_int($start)) {
506 $end = strpos($a_html, "}}}}}", $start);
507 }
508 }
509 return $a_html;
510 }
511}
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)
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)
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.
$i
Definition: disco.tpl.php:19
$html
Definition: example_001.php:87
if(!array_key_exists('StateId', $_REQUEST)) $id
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)
$xml
Definition: metadata.php:240
$end
Definition: saml1-acs.php:18
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$attributes
global $ilDB
$from
$a_type
Definition: workflow.php:92