ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCLauncher.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const PCTYPE = 'lsolauncher';
27 public const PCELEMENT = 'Launcher';
28 public const PLACEHOLDER = '[[[LAUNCHER]]]';
29 public const PROVIDING_TYPES = ['lso'];
30
31 public function init(): void
32 {
33 $this->setType(self::PCTYPE);
34 }
35
36 public function create(
37 ilPageObject $a_pg_obj,
38 string $a_hier_id,
39 string $a_pc_id = ""
40 ): void {
41 $this->createPageContentNode();
42 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
43 $cach_node = $this->dom_doc->createElement(self::PCELEMENT);
44 $this->getDomNode()->appendChild($cach_node);
45 }
46
50 public function modifyPageContentPostXsl(
51 string $a_output,
52 string $a_mode,
53 bool $a_abstract_only = false
54 ): string {
55 if ($a_mode == 'edit') {
56 return $a_output;
57 }
58
59 $parent_obj_id = (int) $this->getPage()->getParentId();
60 if ($this->supportsLauncher($parent_obj_id)) {
61 $a_output = $this->replaceWithRenderedButtons($parent_obj_id, $a_output);
62 }
63
64 return $a_output;
65 }
66
67 protected function supportsLauncher(int $parent_obj_id): bool
68 {
69 $parent_obj_type = \ilObject::_lookupType($parent_obj_id);
70 return in_array($parent_obj_type, self::PROVIDING_TYPES);
71 }
72
73 protected function replaceWithRenderedButtons(int $obj_id, $html): string
74 {
76 $rendered_buttons = $lso->getCurrentUserLaunchButtons();
77 return str_replace(self::PLACEHOLDER, $rendered_buttons, $html);
78 }
79}
const IL_INSERT_AFTER
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType(int $id, bool $reference=false)
LSO Startbutton for PageEditor.
supportsLauncher(int $parent_obj_id)
replaceWithRenderedButtons(int $obj_id, $html)
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
init()
Init object.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
Content object of ilPageObject (see ILIAS DTD).
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)
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('../ilias.ini.php'))