ILIAS  release_8 Revision v8.24
class.ilPCSection.php
Go to the documentation of this file.
1<?php
2
25{
27 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
30
31 public function init(): void
32 {
33 global $DIC;
34
35 $this->access = $DIC->access();
36 $this->ctrl = $DIC->ctrl();
37 $this->lng = $DIC->language();
38 $this->setType("sec");
39 }
40
41 public function setNode(php4DOMElement $a_node): void
42 {
43 parent::setNode($a_node); // this is the PageContent node
44 $this->sec_node = $a_node->first_child(); // this is the Section node
45 }
46
47 public function create(
48 ilPageObject $a_pg_obj,
49 string $a_hier_id,
50 string $a_pc_id = ""
51 ): void {
52 $this->node = $this->createPageContentNode();
53 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
54 $this->sec_node = $this->dom->create_element("Section");
55 $this->sec_node = $this->node->append_child($this->sec_node);
56 $this->sec_node->set_attribute("Characteristic", "Block");
57 }
58
59 public function setCharacteristic(string $a_char): void
60 {
61 if (!empty($a_char)) {
62 $this->sec_node->set_attribute("Characteristic", $a_char);
63 } else {
64 if ($this->sec_node->has_attribute("Characteristic")) {
65 $this->sec_node->remove_attribute("Characteristic");
66 }
67 }
68 }
69
70 public function getCharacteristic(): string
71 {
72 if (is_object($this->sec_node)) {
73 $char = $this->sec_node->get_attribute("Characteristic");
74 if (substr($char, 0, 4) == "ilc_") {
75 $char = substr($char, 4);
76 }
77 return $char;
78 }
79 return "";
80 }
81
82 public static function getLangVars(): array
83 {
84 return array("ed_insert_section");
85 }
86
90 public static function afterPageUpdate(
91 ilPageObject $a_page,
92 DOMDocument $a_domdoc,
93 string $a_xml,
94 bool $a_creation
95 ): void {
96 self::saveTimings($a_page);
97 }
98
103 string $a_output,
104 string $a_mode,
105 bool $a_abstract_only = false
106 ): string {
107 $a_output = self::insertTimings($a_output);
108 $a_output = $this->handleAccess($a_output, $a_mode);
109
110 return $a_output;
111 }
112
113 public function setActiveFrom(int $a_unix_ts): void
114 {
115 if ($a_unix_ts > 0) {
116 $this->sec_node->set_attribute("ActiveFrom", $a_unix_ts);
117 } else {
118 if ($this->sec_node->has_attribute("ActiveFrom")) {
119 $this->sec_node->remove_attribute("ActiveFrom");
120 }
121 }
122 }
123
127 public function getActiveFrom(): int
128 {
129 if (is_object($this->sec_node)) {
130 return (int) $this->sec_node->get_attribute("ActiveFrom");
131 }
132 return 0;
133 }
134
138 public function setActiveTo(int $a_unix_ts): void
139 {
140 if ($a_unix_ts > 0) {
141 $this->sec_node->set_attribute("ActiveTo", $a_unix_ts);
142 } else {
143 if ($this->sec_node->has_attribute("ActiveTo")) {
144 $this->sec_node->remove_attribute("ActiveTo");
145 }
146 }
147 }
148
149 public function getActiveTo(): int
150 {
151 if (is_object($this->sec_node)) {
152 return (int) $this->sec_node->get_attribute("ActiveTo");
153 }
154 return 0;
155 }
156
157 protected function setAttribute(
158 string $a_attr,
159 string $a_val
160 ): void {
161 if (!empty($a_val)) {
162 $this->sec_node->set_attribute($a_attr, $a_val);
163 } else {
164 if ($this->sec_node->has_attribute($a_attr)) {
165 $this->sec_node->remove_attribute($a_attr);
166 }
167 }
168 }
169
170 public function getAttribute(string $a_attr): string
171 {
172 if (is_object($this->sec_node)) {
173 return $this->sec_node->get_attribute($a_attr);
174 }
175 return "";
176 }
177
182 public function setPermission(string $a_val): void
183 {
184 $this->setAttribute("Permission", $a_val);
185 }
186
187 public function getPermission(): string
188 {
189 return $this->getAttribute("Permission");
190 }
191
192 public function setPermissionRefId(int $a_ref_id): void
193 {
194 $this->setAttribute("PermissionRefId", "il__ref_" . $a_ref_id);
195 }
196
197 public function getPermissionRefId(): int
198 {
199 $id = explode("_", $this->getAttribute("PermissionRefId"));
200 if (isset($id[3]) && in_array($id[1], array("", 0, IL_INST_ID))) {
201 return (int) $id[3];
202 }
203 return 0;
204 }
205
209 public function setNoLink(): void
210 {
211 ilDOMUtil::deleteAllChildsByName($this->sec_node, array("IntLink", "ExtLink"));
212 }
213
217 public function setExtLink(string $a_href): void
218 {
219 $this->setNoLink();
220 if (trim($a_href) != "") {
221 $attributes = array("Href" => trim($a_href));
223 $this->dom,
224 $this->sec_node,
225 "ExtLink",
226 array(""),
227 "",
229 );
230 }
231 }
232
236 public function setIntLink(
237 string $a_type,
238 string $a_target,
239 string $a_target_frame
240 ): void {
241 $this->setNoLink();
242 $attributes = array("Type" => $a_type, "Target" => $a_target,
243 "TargetFrame" => $a_target_frame);
245 $this->dom,
246 $this->sec_node,
247 "IntLink",
248 array(""),
249 "",
251 );
252 }
253
254 public function getLink(): array
255 {
256 $childs = $this->sec_node->child_nodes();
257 foreach ($childs as $child) {
258 if ($child->node_name() == "ExtLink") {
259 return array("LinkType" => "ExtLink",
260 "Href" => $child->get_attribute("Href"));
261 }
262 if ($child->node_name() == "IntLink") {
263 return array("LinkType" => "IntLink",
264 "Target" => $child->get_attribute("Target"),
265 "Type" => $child->get_attribute("Type"),
266 "TargetFrame" => $child->get_attribute("TargetFrame"));
267 }
268 }
269 return array("LinkType" => "NoLink");
270 }
271
272
273 public function handleAccess(
274 string $a_html,
275 string $a_mode
276 ): string {
277 $ilAccess = $this->access;
278
279 while (($start = strpos($a_html, "{{{{{Section;Access;")) > 0) {
280 $end = strpos($a_html, "}}}}}", $start);
281 $access_attr = explode(";", substr($a_html, $start, $end - $start));
282 $id = explode("_", $access_attr[3]);
283 $section_nr = $access_attr[6];
284 $access = true;
285 if (in_array($id[1], array("", 0, IL_INST_ID)) && $id[3] > 0) {
286 if ($access_attr[5] == "no_read") {
287 $access = !$ilAccess->checkAccess("read", "", $id[3]);
288 } else {
289 $access = $ilAccess->checkAccess($access_attr[5], "", $id[3]);
290 }
291 }
292 if ($a_mode == ilPageObjectGUI::EDIT) {
293 $access = true;
294 }
295 $end_limiter = "{{{{{Section;AccessEnd;" . $section_nr . "}}}}}";
296 if ($access) {
297 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + 5);
298 $a_html = str_replace($end_limiter, "", $a_html);
299 } else {
300 $end = strpos($a_html, $end_limiter, $start);
301 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + strlen($end_limiter));
302 }
303 }
304
305 $a_html = str_replace("{{{{{Section;Access}}}}}", "", $a_html);
306 return $a_html;
307 }
308
309 public static function saveTimings(
310 ilPageObject $a_page
311 ): void {
312 global $DIC;
313
314 $ilDB = $DIC->database();
315
316 $ilDB->manipulate(
317 "DELETE FROM copg_section_timings WHERE " .
318 " page_id = " . $ilDB->quote($a_page->getId(), "integer") .
319 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
320 );
321
322 $xml = $a_page->getXMLFromDom();
323
324 $doc = domxml_open_mem($xml);
325
326 // media aliases
327 $xpc = xpath_new_context($doc);
328 $path = "//Section";
329 $res = xpath_eval($xpc, $path);
330 for ($i = 0; $i < count($res->nodeset); $i++) {
331 $from = $res->nodeset[$i]->get_attribute("ActiveFrom");
332 if ($from != "") {
333 $ilDB->replace(
334 "copg_section_timings",
335 array(
336 "page_id" => array("integer", $a_page->getId()),
337 "parent_type" => array("text", $a_page->getParentType()),
338 "unix_ts" => array("integer", $from)
339 ),
340 array()
341 );
342 }
343 $to = $res->nodeset[$i]->get_attribute("ActiveTo");
344 if ($to != "") {
345 $ilDB->replace(
346 "copg_section_timings",
347 array(
348 "page_id" => array("integer", $a_page->getId()),
349 "parent_type" => array("text", $a_page->getParentType()),
350 "unix_ts" => array("integer", $to)
351 ),
352 array()
353 );
354 }
355 }
356 }
357
363 public static function getCacheTriggerString(
364 ilPageObject $a_page
365 ): string {
366 global $DIC;
367
368 $ilDB = $DIC->database();
369
370 $set = $ilDB->query(
371 "SELECT * FROM copg_section_timings " .
372 " WHERE page_id = " . $ilDB->quote($a_page->getId(), "integer") .
373 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
374 );
375 $str = "1"; // changed to 1 to force cache miss for #24277
376 $current_ts = new ilDateTime(time(), IL_CAL_UNIX);
377 $current_ts = $current_ts->get(IL_CAL_UNIX);
378 while ($rec = $ilDB->fetchAssoc($set)) {
379 $unix_ts = $rec["unix_ts"];
380 if ($unix_ts < $current_ts) {
381 $unix_ts .= "a";
382 }
383 $str .= "-" . $unix_ts;
384 }
385
386 return $str;
387 }
388
393 public function insertTimings(
394 string $a_html
395 ): string {
396 $lng = $this->lng;
397
398 $end = 0;
399 $start = strpos($a_html, "{{{{{Section;ActiveFrom");
400 if (is_int($start)) {
401 $end = strpos($a_html, "}}}}}", $start);
402 }
403 $i = 1;
404 while ($end > 0) {
405 $param = substr($a_html, $start + 13, $end - $start - 13);
406 $param = explode(";", $param);
407 $from = $param[1];
408 $to = $param[3];
409 $html = "";
410 if ($from != "") {
412 $from = new ilDateTime($from, IL_CAL_UNIX);
413 $html .= $lng->txt("cont_active_from") . ": " . ilDatePresentation::formatDate($from);
414 }
415 if ($to != "") {
416 $to = new ilDateTime($to, IL_CAL_UNIX);
417 $html .= " " . $lng->txt("cont_active_to") . ": " . ilDatePresentation::formatDate($to);
418 }
419
420 $h2 = substr($a_html, 0, $start) .
421 $html .
422 substr($a_html, $end + 5);
423 $a_html = $h2;
424 $i++;
425
426 $start = strpos($a_html, "{{{{{Section;ActiveFrom;", $start + 5);
427 $end = 0;
428 if (is_int($start)) {
429 $end = strpos($a_html, "}}}}}", $start);
430 }
431 }
432 return $a_html;
433 }
434
435 public function getProtected(): bool
436 {
437 if (is_object($this->sec_node)) {
438 return ($this->sec_node->get_attribute("Protected") == "1");
439 }
440
441 return false;
442 }
443
444 public function setProtected(bool $val): void
445 {
446 if ($val) {
447 $this->sec_node->set_attribute("Protected", "1");
448 } else {
449 $this->sec_node->set_attribute("Protected", "0");
450 }
451 }
452
453 public function getModel(): ?stdClass
454 {
455 if ($this->sec_node->node_name() != "Section") {
456 return null;
457 }
458 $model = new stdClass();
459 $model->protected = $this->getProtected();
460
461 return $model;
462 }
463}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
const IL_INSERT_AFTER
Class ilCtrl provides processing control methods.
static deleteAllChildsByName(php4DOMElement $a_parent, array $a_node_names)
delete all childs of a node by names in $a_node_names
static setFirstOptionalElement(php4DOMDocument $doc, php4DOMElement $parent_node, string $a_node_name, array $a_successors, string $a_content, array $a_attributes, bool $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found,...
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
php4DOMElement $sec_node
getAttribute(string $a_attr)
setExtLink(string $a_href)
Set link of area to an external one.
setNode(php4DOMElement $a_node)
Set xml node of page content.
static getCacheTriggerString(ilPageObject $a_page)
Get page cache update trigger string.
setProtected(bool $val)
handleAccess(string $a_html, string $a_mode)
setCharacteristic(string $a_char)
insertTimings(string $a_html)
Insert timings (in edit mode)
init()
Init object.
ilLanguage $lng
static saveTimings(ilPageObject $a_page)
setPermissionRefId(int $a_ref_id)
setActiveTo(int $a_unix_ts)
Set activation to.
setIntLink(string $a_type, string $a_target, string $a_target_frame)
Set link of area to an internal one.
setAttribute(string $a_attr, string $a_val)
ilAccessHandler $access
setPermission(string $a_val)
Set permission.
setNoLink()
Set no link.
setActiveFrom(int $a_unix_ts)
static getLangVars()
Get lang vars needed for editing.
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
getModel()
Get model as needed for the front-end editor.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
getActiveFrom()
Get activation from.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getXMLFromDom(bool $a_incl_head=false, bool $a_append_mobs=false, bool $a_append_bib=false, string $a_append_str="", bool $a_omit_pageobject_tag=false, int $style_id=0)
get xml content of page from dom (use this, if any changes are made to the document)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$i
Definition: metadata.php:41
$attributes
Definition: metadata.php:248
$xml
Definition: metadata.php:351
$lng
$param
Definition: xapitoken.php:46