ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCSection.php
Go to the documentation of this file.
1<?php
2
25{
27 protected ilCtrl $ctrl;
28 protected ilLanguage $lng;
29
30 public function init(): void
31 {
32 global $DIC;
33
34 $this->access = $DIC->access();
35 $this->ctrl = $DIC->ctrl();
36 $this->lng = $DIC->language();
37 $this->setType("sec");
38 }
39
40 public function create(
41 ilPageObject $a_pg_obj,
42 string $a_hier_id,
43 string $a_pc_id = ""
44 ): void {
46 $a_hier_id,
47 $a_pc_id,
48 "Section",
49 ["Characteristic" => "Block"]
50 );
51 }
52
53 public function setCharacteristic(string $a_char): void
54 {
55 $this->dom_util->setAttribute($this->getChildNode(), "Characteristic", $a_char);
56 }
57
58 public function getCharacteristic(): string
59 {
60 if (is_object($this->getChildNode())) {
61 $char = $this->getChildNode()->getAttribute("Characteristic");
62 if (substr($char, 0, 4) == "ilc_") {
63 $char = substr($char, 4);
64 }
65 return $char;
66 }
67 return "";
68 }
69
70 public static function getLangVars(): array
71 {
72 return array("ed_insert_section");
73 }
74
78 public static function afterPageUpdate(
79 ilPageObject $a_page,
80 DOMDocument $a_domdoc,
81 string $a_xml,
82 bool $a_creation
83 ): void {
84 self::saveTimings($a_page);
85 }
86
90 public function modifyPageContentPostXsl(
91 string $a_output,
92 string $a_mode,
93 bool $a_abstract_only = false
94 ): string {
95 $a_output = self::insertTimings($a_output);
96 $a_output = $this->handleAccess($a_output, $a_mode);
97
98 return $a_output;
99 }
100
101 public function setActiveFrom(int $a_unix_ts): void
102 {
103 $a_unix_ts = ($a_unix_ts > 0) ? (string) $a_unix_ts : null;
104 $this->dom_util->setAttribute($this->getChildNode(), "ActiveFrom", $a_unix_ts);
105 }
106
110 public function getActiveFrom(): int
111 {
112 if (is_object($this->getChildNode())) {
113 return (int) $this->getChildNode()->getAttribute("ActiveFrom");
114 }
115 return 0;
116 }
117
121 public function setActiveTo(int $a_unix_ts): void
122 {
123 $a_unix_ts = ($a_unix_ts > 0) ? (string) $a_unix_ts : null;
124 $this->dom_util->setAttribute($this->getChildNode(), "ActiveTo", $a_unix_ts);
125 }
126
127 public function getActiveTo(): int
128 {
129 if (is_object($this->getChildNode())) {
130 return (int) $this->getChildNode()->getAttribute("ActiveTo");
131 }
132 return 0;
133 }
134
139 public function setPermission(string $a_val): void
140 {
141 $this->dom_util->setAttribute($this->getChildNode(), "Permission", $a_val);
142 }
143
144 public function getPermission(): string
145 {
146 return $this->getChildNode()->getAttribute("Permission");
147 }
148
149 public function setPermissionRefId(int $a_ref_id): void
150 {
151 $this->dom_util->setAttribute($this->getChildNode(), "PermissionRefId", "il__ref_" . $a_ref_id);
152 }
153
154 public function getPermissionRefId(): int
155 {
156 $id = explode("_", $this->getChildNode()->getAttribute("PermissionRefId"));
157 if (isset($id[3]) && in_array($id[1], array("", 0, IL_INST_ID))) {
158 return (int) $id[3];
159 }
160 return 0;
161 }
162
166 public function setNoLink(): void
167 {
168 $this->dom_util->deleteAllChildsByName($this->getChildNode(), ["IntLink", "ExtLink"]);
169 }
170
174 public function setExtLink(string $a_href): void
175 {
176 $this->setNoLink();
177 if (trim($a_href) != "") {
178 $attributes = array("Href" => trim($a_href));
179 $this->dom_util->setFirstOptionalElement(
180 $this->getChildNode(),
181 "ExtLink",
182 [],
183 "",
184 $attributes
185 );
186 }
187 }
188
192 public function setIntLink(
193 string $a_type,
194 string $a_target,
195 string $a_target_frame
196 ): void {
197 $this->setNoLink();
198 $attributes = array("Type" => $a_type, "Target" => $a_target,
199 "TargetFrame" => $a_target_frame);
200 $this->dom_util->setFirstOptionalElement(
201 $this->getChildNode(),
202 "IntLink",
203 [],
204 "",
205 $attributes
206 );
207 }
208
209 public function getLink(): array
210 {
211 $childs = $this->getChildNode()->childNodes;
212 foreach ($childs as $child) {
213 if ($child->nodeName === "ExtLink") {
214 return array("LinkType" => "ExtLink",
215 "Href" => $child->getAttribute("Href"));
216 }
217 if ($child->nodeName === "IntLink") {
218 return array("LinkType" => "IntLink",
219 "Target" => $child->getAttribute("Target"),
220 "Type" => $child->getAttribute("Type"),
221 "TargetFrame" => $child->getAttribute("TargetFrame"));
222 }
223 }
224 return array("LinkType" => "NoLink");
225 }
226
227
228 public function handleAccess(
229 string $a_html,
230 string $a_mode
231 ): string {
232 $ilAccess = $this->access;
233
234 while (($start = strpos($a_html, "{{{{{Section;Access;")) > 0) {
235 $end = strpos($a_html, "}}}}}", $start);
236 $access_attr = explode(";", substr($a_html, $start, $end - $start));
237 $id = explode("_", $access_attr[3]);
238 $section_nr = $access_attr[6];
239 $access = true;
240 if (in_array($id[1], array("", 0, IL_INST_ID)) && $id[3] > 0) {
241 if ($access_attr[5] == "no_read") {
242 $access = !$ilAccess->checkAccess("read", "", $id[3]);
243 } else {
244 $access = $ilAccess->checkAccess($access_attr[5], "", $id[3]);
245 }
246 }
247 if ($a_mode == ilPageObjectGUI::EDIT) {
248 $access = true;
249 }
250 $end_limiter = "{{{{{Section;AccessEnd;" . $section_nr . "}}}}}";
251 if ($access) {
252 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + 5);
253 $a_html = str_replace($end_limiter, "", $a_html);
254 } else {
255 $end = strpos($a_html, $end_limiter, $start);
256 $a_html = substr($a_html, 0, $start) . substr($a_html, $end + strlen($end_limiter));
257 }
258 }
259
260 $a_html = str_replace("{{{{{Section;Access}}}}}", "", $a_html);
261 return $a_html;
262 }
263
264 public static function saveTimings(
265 ilPageObject $a_page
266 ): void {
267 global $DIC;
268
269 $ilDB = $DIC->database();
270 $dom_util = $DIC->copage()->internal()->domain()->domUtil();
271
272 $ilDB->manipulate(
273 "DELETE FROM copg_section_timings WHERE " .
274 " page_id = " . $ilDB->quote($a_page->getId(), "integer") .
275 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
276 );
277
278 $doc = $a_page->getDomDoc();
279
280 // media aliases
281 $path = "//Section";
282 $nodes = $dom_util->path($doc, $path);
283 foreach ($nodes as $node) {
284 $from = $node->getAttribute("ActiveFrom");
285 if ($from != "") {
286 $ilDB->replace(
287 "copg_section_timings",
288 array(
289 "page_id" => array("integer", $a_page->getId()),
290 "parent_type" => array("text", $a_page->getParentType()),
291 "unix_ts" => array("integer", $from)
292 ),
293 array()
294 );
295 }
296 $to = $node->getAttribute("ActiveTo");
297 if ($to != "") {
298 $ilDB->replace(
299 "copg_section_timings",
300 array(
301 "page_id" => array("integer", $a_page->getId()),
302 "parent_type" => array("text", $a_page->getParentType()),
303 "unix_ts" => array("integer", $to)
304 ),
305 array()
306 );
307 }
308 }
309 }
310
316 public static function getCacheTriggerString(
317 ilPageObject $a_page
318 ): string {
319 global $DIC;
320
321 $ilDB = $DIC->database();
322
323 $set = $ilDB->query(
324 "SELECT * FROM copg_section_timings " .
325 " WHERE page_id = " . $ilDB->quote($a_page->getId(), "integer") .
326 " AND parent_type = " . $ilDB->quote($a_page->getParentType(), "text")
327 );
328 $str = "1"; // changed to 1 to force cache miss for #24277
329 $current_ts = new ilDateTime(time(), IL_CAL_UNIX);
330 $current_ts = $current_ts->get(IL_CAL_UNIX);
331 while ($rec = $ilDB->fetchAssoc($set)) {
332 $unix_ts = $rec["unix_ts"];
333 if ($unix_ts < $current_ts) {
334 $unix_ts .= "a";
335 }
336 $str .= "-" . $unix_ts;
337 }
338
339 return $str;
340 }
341
346 public function insertTimings(
347 string $a_html
348 ): string {
349 $lng = $this->lng;
350
351 $end = 0;
352 $start = strpos($a_html, "{{{{{Section;ActiveFrom");
353 if (is_int($start)) {
354 $end = strpos($a_html, "}}}}}", $start);
355 }
356 $i = 1;
357 while ($end > 0) {
358 $param = substr($a_html, $start + 13, $end - $start - 13);
359 $param = explode(";", $param);
360 $from = $param[1];
361 $to = $param[3];
362 $html = "";
363 if ($from != "") {
365 $from = new ilDateTime($from, IL_CAL_UNIX);
366 $html .= $lng->txt("cont_active_from") . ": " . ilDatePresentation::formatDate($from);
367 }
368 if ($to != "") {
369 $to = new ilDateTime($to, IL_CAL_UNIX);
370 $html .= " " . $lng->txt("cont_active_to") . ": " . ilDatePresentation::formatDate($to);
371 }
372
373 $h2 = substr($a_html, 0, $start) .
374 $html .
375 substr($a_html, $end + 5);
376 $a_html = $h2;
377 $i++;
378
379 $start = strpos($a_html, "{{{{{Section;ActiveFrom;", $start + 5);
380 $end = 0;
381 if (is_int($start)) {
382 $end = strpos($a_html, "}}}}}", $start);
383 }
384 }
385 return $a_html;
386 }
387
388 public function getProtected(): bool
389 {
390 if (is_object($this->getChildNode())) {
391 return ($this->getChildNode()->getAttribute("Protected") === "1");
392 }
393
394 return false;
395 }
396
397 public function setProtected(bool $val): void
398 {
399 if ($val) {
400 $this->getChildNode()->setAttribute("Protected", "1");
401 } else {
402 $this->getChildNode()->setAttribute("Protected", "0");
403 }
404 }
405
406 public function getModel(): ?stdClass
407 {
408 if ($this->getChildNode()->nodeName !== "Section") {
409 return null;
410 }
411 $model = new stdClass();
412 $model->protected = $this->getProtected();
413
414 return $model;
415 }
416}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
Class ilCtrl provides processing control methods.
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, ?ilObjUser $user=null,)
@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...
setExtLink(string $a_href)
Set link of area to an external one.
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.
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.
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getDomDoc()
Get dom doc (DOMDocument)
const IL_INST_ID
Definition: constants.php:40
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
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:30
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$param
Definition: xapitoken.php:46