ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPCPRGActionNote.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 #[AllowDynamicProperties]
26 {
27  protected ilLanguage $lng;
28  public const PCTYPE = 'prgactionnote';
29  public const PCELEMENT = 'PRGActionNote';
30  public const PLACEHOLDER = '[[[PRG_ACTION_NOTE]]]';
31  public const PROVIDING_TYPES = ['prg'];
32 
33  public function init(): void
34  {
35  global $DIC;
36  $this->lng = $DIC->language();
37  $this->setType(self::PCTYPE);
38  }
39 
40  public function create(
41  ilPageObject $a_pg_obj,
42  string $a_hier_id,
43  string $a_pc_id = ""
44  ): void {
45  $this->node = $this->createPageContentNode();
46  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
47  $this->cache_node = $this->dom_doc->createElement(self::PCELEMENT);
48  $this->cache_node = $this->node->appendChild($this->cache_node);
49  }
50 
51  public function modifyPageContentPostXsl(
52  string $a_output,
53  string $a_mode,
54  bool $a_abstract_only = false
55  ): string {
56  $parent_obj_id = $this->getPage()->getParentId();
57  $end = 0;
58  $start = strpos($a_output, "[[[PRG_ACTION_NOTE");
59 
60  if (is_int($start)) {
61  $end = strpos($a_output, "]]]", $start);
62  }
63 
64  if ($a_mode === 'edit') {
65  while ($end > 0) {
66  if ($this->supportsType($parent_obj_id)) {
67  $html = $this->getTemplate();
68 
69  $a_output = substr($a_output, 0, $start) .
70  $html .
71  substr($a_output, $end + 3);
72 
73  $start = strpos($a_output, "[[[PRG_ACTION_NOTE", $start + 3);
74  $end = 0;
75  if (is_int($start)) {
76  $end = strpos($a_output, "]]]", $start);
77  }
78 
79  }
80  }
81 
82  return $a_output;
83  }
84 
85  $parent_obj_id = (int) $this->getPage()->getParentId();
86  if ($this->supportsType($parent_obj_id)) {
87  $a_output = $this->replaceWithRendered($parent_obj_id, $a_output);
88  }
89 
90  return $a_output;
91  }
92 
93  protected function supportsType(int $parent_obj_id): bool
94  {
95  $parent_obj_id = ilObject::_lookupType($parent_obj_id);
96  return in_array($parent_obj_id, self::PROVIDING_TYPES);
97  }
98 
99  protected function replaceWithRendered(int $obj_id, $html): string
100  {
102  $builder = $dic['pc.actionnote'];
103  $rendered = $builder->getNoteFor($obj_id);
104  return str_replace(self::PLACEHOLDER, $rendered, $html);
105  }
106 
107  protected function getTemplate(): string
108  {
109  $template = new ilTemplate("tpl.action_note_poeditor_element.html", true, true, 'components/ILIAS/StudyProgramme');
110  $icon = "./assets/images/standard/icon_prg.svg";
111 
112  $template->setVariable("ICON", $icon);
113  $template->setVariable("ICON_TEXT", $this->lng->txt("study_programme_icon"));
114  $template->setVariable("LABEL", $this->lng->txt("pc_prg_action_note_label"));
115 
116  return $template->get();
117  }
118 }
setType(string $a_type)
Set Type.
replaceWithRendered(int $obj_id, $html)
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
Content object of ilPageObject (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
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:22
const IL_INSERT_AFTER
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
PageComponent "Note" for PageEditor in PRGs.
$dic
Definition: result.php:31
static _lookupType(int $id, bool $reference=false)
supportsType(int $parent_obj_id)