ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPageContent.php
Go to the documentation of this file.
1<?php
2
21
28abstract class ilPageContent
29{
30 protected DOMDocument $dom_doc;
31 protected \ILIAS\COPage\InternalDomainService $domain;
32 protected string $pcid;
33 protected string $type = "";
35 public string $hier_id = "";
36 public ?DOMNode $dom_node = null;
37 public string $page_lang = "";
38 // needed for post processing (e.g. content includes)
39 protected string $file_download_link = '';
40 // needed for post processing (e.g. content includes)
41 protected string $fullscreen_link = '';
42 // needed for post processing (e.g. content includes)
43 protected string $sourcecode_download_script = '';
44 protected ilLogger $log;
45 protected string $profile_back_url = "";
46
47 protected \ILIAS\COPage\Dom\DomUtil $dom_util;
50
51 final public function __construct(
52 ilPageObject $a_pg_obj,
54 ?ObjectAdapterInterface $object_adapter = null
55 ) {
56 global $DIC;
57
58 $this->log = ilLoggerFactory::getLogger('copg');
59 $this->setPage($a_pg_obj);
60 $this->dom_doc = $a_pg_obj->getDomDoc();
61 //$this->dom = $a_pg_obj->getDom();
62 $this->domain = $DIC->copage()->internal()->domain();
63 $this->init();
64 if ($this->getType() == "") {
65 die("Error: ilPageContent::init() did not set type");
66 }
67 $this->page_manager = $page_manager ?? $DIC->copage()
68 ->internal()
69 ->domain()
70 ->page();
71 $this->object = $object_adapter ?? $DIC->copage()
72 ->internal()
73 ->domain()
74 ->object();
75 $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
76 }
77
79 {
81 }
82
83 public function setPage(ilPageObject $a_val): void
84 {
85 $this->pg_obj = $a_val;
86 }
87
88 public function getPage(): ilPageObject
89 {
90 return $this->pg_obj;
91 }
92
97 abstract public function init(): void;
98
103 final protected function setType(string $a_type): void
104 {
105 $this->type = $a_type;
106 }
107
108 public function getType(): string
109 {
110 return $this->type;
111 }
112
113 public function getDomNode(): ?DOMNode
114 {
115 return $this->dom_node;
116 }
117
118 public function getDomDoc(): DOMDocument
119 {
120 return $this->dom_doc;
121 }
122
123 public function setDomNode(DOMNode $node): void
124 {
125 $this->dom_node = $node;
126 }
127
128 public function getChildNode(): ?DOMNode
129 {
130 return $this->getDomNode()?->firstChild;
131 }
132
133 public function getJavascriptFiles(string $a_mode): array
134 {
135 return array();
136 }
137
138 public function getCssFiles(string $a_mode): array
139 {
140 return [];
141 }
142
143 public function getOnloadCode(string $a_mode): array
144 {
145 return array();
146 }
147
148 public function setHierId(string $a_hier_id): void
149 {
150 $this->hier_id = $a_hier_id;
151 }
152
153 public function getHierId(): string
154 {
155 return $this->hier_id;
156 }
157
158 // Get hierarchical id from dom
159 public function lookupHierId(): string
160 {
161 return $this->getDomNode()->getAttribute("HierId");
162 }
163
164 protected function hasNode(): bool
165 {
166 return is_object($this->dom_node);
167 }
168
169 public function readHierId(): string
170 {
171 if ($this->hasNode()) {
172 return $this->getDomNode()->getAttribute("HierId");
173 }
174 return "";
175 }
176
177 public function setPcId(string $a_pcid): void
178 {
179 $this->pcid = $a_pcid;
180 }
181
182 public function getPCId(): string
183 {
184 return $this->pcid;
185 }
186
187 public function setFileDownloadLink(string $a_download_link): void
188 {
189 $this->file_download_link = $a_download_link;
190 }
191
192 public function getFileDownloadLink(): string
193 {
195 }
196
197 public function setProfileBackUrl(string $url): void
198 {
199 $this->profile_back_url = $url;
200 }
201
202 public function getProfileBackUrl(): string
203 {
205 }
206
207 public function setFullscreenLink(string $a_fullscreen_link): void
208 {
209 $this->fullscreen_link = $a_fullscreen_link;
210 }
211
212 public function getFullscreenLink(): string
213 {
215 }
216
217 public function setSourcecodeDownloadScript(string $script_name): void
218 {
219 $this->sourcecode_download_script = $script_name;
220 }
221
222 public function getSourcecodeDownloadScript(): string
223 {
225 }
226
227 public function readPCId(): string
228 {
229 if ($this->hasNode()) {
230 return $this->getDomNode()->getAttribute("PCID");
231 }
232 return "";
233 }
234
235 public function writePCId(string $a_pc_id): void
236 {
237 if ($this->hasNode()) {
238 $this->getDomNode()->setAttribute("PCID", $a_pc_id);
239 }
240 }
241
245 public static function sortHierIds(array $a_array): array
246 {
247 uasort($a_array, array("ilPageContent", "isGreaterHierId"));
248 return $a_array;
249 }
250
254 public static function isGreaterHierId(string $a, string $b): int
255 {
256 $a_arr = explode("_", $a);
257 $b_arr = explode("_", $b);
258 for ($i = 0; $i < count($a_arr); $i++) {
259 if ((int) $a_arr[$i] > (int) $b_arr[$i]) {
260 return +1;
261 } elseif ((int) $a_arr[$i] < (int) $b_arr[$i]) {
262 return -1;
263 }
264 }
265 return 0;
266 }
267
272 public function setEnabled(string $value): void
273 {
274 if ($this->hasNode()) {
275 $this->getDomNode()->setAttribute("Enabled", $value);
276 }
277 }
278
279 public function enable(): void
280 {
281 $this->setEnabled("True");
282 }
283
284 public function disable(): void
285 {
286 $this->setEnabled("False");
287 }
288
289 final public function isEnabled(): bool
290 {
291 if ($this->hasNode() && $this->getDomNode()->hasAttribute("Enabled")) {
292 $compare = $this->getDomNode()->getAttribute("Enabled");
293 } else {
294 $compare = "True";
295 }
296
297 return strcasecmp($compare, "true") == 0;
298 }
299
303 public function createPageContentNode(bool $a_set_this_node = true): DomNode
304 {
305 $node = $this->dom_doc->createElement("PageContent");
306 if ($a_set_this_node) {
307 $this->setDomNode($node);
308 }
309 return $node;
310 }
311
312 public function getNewPageContentNode(): DOMNode
313 {
314 return $this->dom_doc->createElement("PageContent");
315 }
316
317 protected function createInitialChildNode(
318 string $hier_id,
319 string $pc_id,
320 string $child,
321 array $child_attributes = []
322 ): void {
323 $this->createPageContentNode();
324 $node = $this->dom_doc->createElement($child);
325 $node = $this->getDomNode()->appendChild($node);
326 foreach ($child_attributes as $att => $value) {
327 $node->setAttribute($att, $value);
328 }
329 $this->getPage()->insertContent($this, $hier_id, IL_INSERT_AFTER, $pc_id);
330 }
331
336 public static function getLangVars(): array
337 {
338 return array();
339 }
340
350 public static function handleCopiedContent(
351 DOMDocument $a_domdoc,
352 bool $a_self_ass = true,
353 bool $a_clone_mobs = false,
354 int $new_parent_id = 0,
355 int $obj_copy_id = 0
356 ): void {
357 }
358
362 public function modifyPageContentPostXsl(
363 string $a_output,
364 string $a_mode,
365 bool $a_abstract_only = false
366 ): string {
367 return $a_output;
368 }
369
373 public static function afterPageUpdate(
374 ilPageObject $a_page,
375 DOMDocument $a_domdoc,
376 string $a_xml,
377 bool $a_creation
378 ): void {
379 }
380
385 public static function beforePageDelete(
386 ilPageObject $a_page
387 ): void {
388 }
389
393 public static function afterRepositoryCopy(ilPageObject $page, array $mapping, int $source_ref_id): void
394 {
395 }
396
400 public static function afterPageHistoryEntry(
401 ilPageObject $a_page,
402 DOMDocument $a_old_domdoc,
403 string $a_old_xml,
404 int $a_old_nr
405 ): void {
406 }
407
411 public function getModel(): ?stdClass
412 {
413 return null;
414 }
415
419 public static function deleteHistoryLowerEqualThan(
420 string $parent_type,
421 int $page_id,
422 string $lang,
423 int $delete_lower_than_nr
424 ): void {
425 }
426}
const IL_INSERT_AFTER
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Content object of ilPageObject (see ILIAS DTD).
ilPageObject $pg_obj
getCssFiles(string $a_mode)
setHierId(string $a_hier_id)
setSourcecodeDownloadScript(string $script_name)
DOMDocument $dom_doc
writePCId(string $a_pc_id)
static afterPageHistoryEntry(ilPageObject $a_page, DOMDocument $a_old_domdoc, string $a_old_xml, int $a_old_nr)
After page history entry has been created.
getJavascriptFiles(string $a_mode)
setFileDownloadLink(string $a_download_link)
setProfileBackUrl(string $url)
init()
Init object.
static afterPageUpdate(ilPageObject $a_page, DOMDocument $a_domdoc, string $a_xml, bool $a_creation)
After page has been updated (or created)
static sortHierIds(array $a_array)
Sort an array of Hier IDS in ascending order.
static deleteHistoryLowerEqualThan(string $parent_type, int $page_id, string $lang, int $delete_lower_than_nr)
Overwrite in derived classes, if old history entries are being deleted.
ILIAS COPage InternalDomainService $domain
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setPage(ilPageObject $a_val)
setPcId(string $a_pcid)
setFullscreenLink(string $a_fullscreen_link)
string $sourcecode_download_script
static handleCopiedContent(DOMDocument $a_domdoc, bool $a_self_ass=true, bool $a_clone_mobs=false, int $new_parent_id=0, int $obj_copy_id=0)
Handle copied content.
__construct(ilPageObject $a_pg_obj, ?PageManagerInterface $page_manager=null, ?ObjectAdapterInterface $object_adapter=null)
ObjectAdapterInterface $object
static isGreaterHierId(string $a, string $b)
Check whether Hier ID $a is greater than Hier ID $b.
setDomNode(DOMNode $node)
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
ILIAS COPage Dom DomUtil $dom_util
setEnabled(string $value)
Set Enabled value for page content component.
getOnloadCode(string $a_mode)
setType(string $a_type)
Set Type.
PageManagerInterface $page_manager
static getLangVars()
Get lang vars needed for editing.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getDomDoc()
Get dom doc (DOMDocument)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68
$lang
Definition: xapiexit.php:25