ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilPCPRGStatusInfo.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 = 'prgstatusinfo';
29  public const PCELEMENT = 'PRGStatusInfo';
30  public const PLACEHOLDER = '[[[PRG_STATUS_INFO]]]';
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 
54  public function modifyPageContentPostXsl(
55  string $a_output,
56  string $a_mode,
57  bool $a_abstract_only = false
58  ): string {
59  $parent_obj_id = $this->getPage()->getParentId();
60  $end = 0;
61  $start = strpos($a_output, "[[[PRG_STATUS_INFO");
62 
63  if (is_int($start)) {
64  $end = strpos($a_output, "]]]", $start);
65  }
66 
67  if ($a_mode === 'edit') {
68  while ($end > 0) {
69  if ($this->supportsType($parent_obj_id)) {
70  $html = $this->getTemplate();
71 
72  $a_output = substr($a_output, 0, $start) .
73  $html .
74  substr($a_output, $end + 3);
75 
76  $start = strpos($a_output, "[[[PRG_STATUS_INFO", $start + 3);
77  $end = 0;
78  if (is_int($start)) {
79  $end = strpos($a_output, "]]]", $start);
80  }
81  }
82  }
83  return $a_output;
84  }
85 
86  $parent_obj_id = (int) $this->getPage()->getParentId();
87  if ($this->supportsType($parent_obj_id)) {
88  $a_output = $this->replaceWithRendered($parent_obj_id, $a_output);
89  }
90  return $a_output;
91  }
92 
93  protected function supportsType(int $parent_obj_id): bool
94  {
95  $parent_obj_type = \ilObject::_lookupType($parent_obj_id);
96  return in_array($parent_obj_type, self::PROVIDING_TYPES);
97  }
98 
99  protected function replaceWithRendered(int $obj_id, $html): string
100  {
102  $builder = $dic['pc.statusinfo'];
103  $rendered = $builder->getStatusInfoFor($obj_id);
104  return str_replace(self::PLACEHOLDER, $rendered, $html);
105  }
106 
107  protected function getTemplate(): string
108  {
109  $template = new ilTemplate("tpl.statusinfo_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_statusinfo_label"));
115 
116  return $template->get();
117  }
118 }
replaceWithRendered(int $obj_id, $html)
setType(string $a_type)
Set Type.
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
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
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
global $DIC
Definition: shib_login.php:26
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 "Status Information" for PageEditor in PRGs.
supportsType(int $parent_obj_id)
$dic
Definition: result.php:31
static _lookupType(int $id, bool $reference=false)