ILIAS  release_8 Revision v8.24
class.ilPCAMDForm.php
Go to the documentation of this file.
1<?php
2
24{
26 protected int $ref_id;
27 protected ilDBInterface $db;
28 protected ilLanguage $lng;
29
30 public function init(): void
31 {
32 global $DIC;
33
34 $this->db = $DIC->database();
35 $this->lng = $DIC->language();
36 $this->setType("amdfrm");
37
38 $request = $DIC->portfolio()
39 ->internal()
40 ->gui()
41 ->standardRequest();
42
43 $this->ref_id = $request->getRefId();
44 }
45
46 public static function getLangVars(): array
47 {
48 return array("ed_insert_amdfrm", "pc_amdfrm");
49 }
50
51 public function setNode(php4DOMElement $a_node): void
52 {
53 parent::setNode($a_node); // this is the PageContent node
54 $this->amdfrm_node = $a_node->first_child(); // this is the courses node
55 }
56
57 protected function isTemplate(): bool
58 {
59 return ($this->getPage()->getParentType() === "prtt");
60 }
61
62 public function create(
63 ilPageObject $a_pg_obj,
64 string $a_hier_id,
65 string $a_pc_id = ""
66 ): void {
67 $this->node = $this->createPageContentNode();
68 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
69 $this->amdfrm_node = $this->dom->create_element("AMDForm");
70 $this->amdfrm_node = $this->node->append_child($this->amdfrm_node);
71 }
72
73 public function setRecordIds(array $record_ids): void
74 {
75 $this->amdfrm_node->set_attribute("RecordIds", implode(",", $record_ids));
76 }
77
78 public function getRecordIds(): array
79 {
80 if (is_object($this->amdfrm_node)) {
81 return explode(",", $this->amdfrm_node->get_attribute("RecordIds"));
82 }
83 return [];
84 }
85
86
87 public function modifyPageContentPostXsl(
88 string $a_output,
89 string $a_mode,
90 bool $a_abstract_only = false
91 ): string {
92 $end = 0;
93 $start = strpos($a_output, "[[[[[AMDForm;");
94 if (is_int($start)) {
95 $end = strpos($a_output, "]]]]]", $start);
96 }
97 while ($end > 0) {
98 $parts = explode(";", substr($a_output, $start + 13, $end - $start - 13));
99 if ($this->isTemplate()) {
100 $portfolio = new ilObjPortfolioTemplate($this->getPage()->getPortfolioId(), false);
101 } else {
102 $portfolio = new ilObjPortfolio($this->getPage()->getPortfolioId(), false);
103 }
104
105 $mdgui = new ilObjectMetaDataGUI($portfolio, "pfpg", $this->getPage()->getId(), false);
106 $mdgui->setRecordFilter(explode(",", $parts[0]));
107 $insert_html = $mdgui->getBlockHTML();
108
109 $a_output = substr($a_output, 0, $start) .
110 $insert_html .
111 substr($a_output, $end + 5);
112
113 $start = strpos($a_output, "[[[[[AMDForm;", $start + 5);
114 $end = 0;
115 if (is_int($start)) {
116 $end = strpos($a_output, "]]]]]", $start);
117 }
118 }
119
120 return $a_output;
121 }
122
123 public static function handleCopiedContent(
124 DOMDocument $a_domdoc,
125 bool $a_self_ass = true,
126 bool $a_clone_mobs = false,
127 int $new_parent_id = 0,
128 int $obj_copy_id = 0
129 ): void {
130 if ($obj_copy_id > 0) {
131 $cp_options = ilCopyWizardOptions::_getInstance($obj_copy_id);
132 $mappings = $cp_options->getMappings();
133 $key = $new_parent_id . "_adv_rec";
134 if (is_array($mappings) && isset($mappings[$key])) {
135 $xpath = new DOMXPath($a_domdoc);
136 $nodes = $xpath->query("//AMDForm");
137 foreach ($nodes as $node) {
138 $old_ids = explode(",", (string) $node->getAttribute("RecordIds"));
139 // 36565: do not overwrite RecordIds that are not mapped
140 $new_ids = array_map(static function ($i) use ($mappings, $key) {
141 return $mappings[$key][(int) $i] ?? $i;
142 }, $old_ids);
143 $new_ids = implode(",", $new_ids);
144 if ($new_ids !== "") {
145 $node->setAttribute("RecordIds", $new_ids);
146 }
147 }
148 }
149 }
150 }
151}
const IL_INSERT_AFTER
static _getInstance(int $a_copy_id)
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
modifyPageContentPostXsl(string $a_output, string $a_mode, bool $a_abstract_only=false)
Modify page content after xsl.
static getLangVars()
Get lang vars needed for editing.
setRecordIds(array $record_ids)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
php4DOMElement $amdfrm_node
setNode(php4DOMElement $a_node)
Set xml node of page content.
init()
Init object.
ilDBInterface $db
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.
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
$i
Definition: metadata.php:41
string $key
Consumer key/client ID value.
Definition: System.php:193