19 declare(strict_types=1);
52 $this->dom_util = $DIC->copage()
57 $this->generator = $generator ?? $DIC->copage()
60 ->contentIdGenerator();
78 $dom = $this->page->getDomDoc();
81 foreach (self::ID_ELEMENTS as $el) {
82 $path .= $sep .
"//" . $el;
86 $nodes = $this->dom_util->path($dom,
$path);
88 foreach ($nodes as $node) {
90 $ctag = $cnode->nodeName;
94 while ($cnode = $cnode->previousSibling) {
95 if (($cnode->nodeType == XML_ELEMENT_NODE)
96 && $cnode->hasAttribute(
"HierId")) {
97 $sib_hier_id = $cnode->getAttribute(
"HierId");
102 if ($sib_hier_id !=
"") {
103 $node_hier_id = $this->
incEdId($sib_hier_id);
104 $node->setAttribute(
"HierId", $node_hier_id);
105 $this->hier_ids[] = $node_hier_id;
110 while ($cnode = $cnode->parentNode) {
111 if (($cnode->nodeType == XML_ELEMENT_NODE)
112 && $cnode->hasAttribute(
"HierId")) {
113 $par_hier_id = $cnode->getAttribute(
"HierId");
117 if (($par_hier_id !=
"") && ($par_hier_id !=
"pg")) {
118 $node_hier_id = $par_hier_id .
"_1";
119 $node->setAttribute(
"HierId", $node_hier_id);
120 $this->hier_ids[] = $node_hier_id;
123 $node->setAttribute(
"HierId", $node_hier_id);
124 $this->hier_ids[] = $node_hier_id;
130 $path =
"//PageObject";
131 $nodes = $this->dom_util->path($dom,
$path);
132 foreach ($nodes as $node) {
133 $node->setAttribute(
"HierId",
"pg");
134 $this->hier_ids[] =
"pg";
148 $this->hier_ids = [];
149 $dom = $this->page->getDomDoc();
151 if (is_object($dom)) {
152 $path =
"//*[@HierId]";
153 $nodes = $this->dom_util->path($dom,
$path);
154 foreach ($nodes as $node) {
155 if ($node->hasAttribute(
"HierId")) {
156 $node->removeAttribute(
"HierId");
168 protected function incEdId(
string $ed_id): string
170 $id = explode(
"_", $ed_id);
172 return implode(
"_",
$id);
180 protected function decEdId(
string $ed_id): string
182 $id = explode(
"_", $ed_id);
184 return implode(
"_",
$id);
189 return $this->generator->generate();
194 $this->page->buildDom();
195 $dom = $this->page->getDomDoc();
199 foreach (self::ID_ELEMENTS as $el) {
200 $path .= $sep .
"//" . $el .
"[not(@PCID)]";
202 $path .= $sep .
"//" . $el .
"[@PCID='']";
205 $nodes = $this->dom_util->path($dom,
$path);
206 foreach ($nodes as $node) {
208 $node->setAttribute(
"PCID",
$id);
214 $this->page->buildDom();
215 $dom = $this->page->getDomDoc();
221 foreach (self::ID_ELEMENTS as $el) {
222 $path .= $sep .
"//" . $el .
"[@PCID]";
227 $nodes = $this->dom_util->path($dom,
$path);
228 foreach ($nodes as $node) {
229 $pc_id = $node->getAttribute(
"PCID");
231 if (isset($pcids[$pc_id])) {
232 $duplicates[] = $pc_id;
234 $pcids[$pc_id] = $pc_id;
243 return count($duplicates) > 0;
248 $dom = $this->page->getDomDoc();
249 if (is_object($dom)) {
250 $path =
"//*[@PCID]";
251 $nodes = $this->dom_util->path($dom,
$path);
252 foreach ($nodes as $node) {
253 if ($node->hasAttribute(
"PCID")) {
254 $node->removeAttribute(
"PCID");
264 $dom = $page->getDomDoc();
267 foreach (self::ID_ELEMENTS as $el) {
268 $path .= $sep .
"//" . $el .
"[not(@PCID)]";
270 $path .= $sep .
"//" . $el .
"[@PCID='']";
272 $nodes = $this->dom_util->path($dom,
$path);
273 if (count($nodes) > 0) {
283 $dom = $page->getDomDoc();
288 foreach (self::ID_ELEMENTS as $el) {
289 $path .= $sep .
"//" . $el .
"[@PCID]";
294 $nodes = $this->dom_util->path($dom,
$path);
295 foreach ($nodes as $node) {
296 $pcids[] = $node->getAttribute(
"PCID");
304 if (!is_array($a_pc_ids) || count($a_pc_ids) == 0) {
309 $dom = $this->page->getDomDoc();
310 if (is_object($dom)) {
311 $path =
"//*[@PCID]";
312 $nodes = $this->dom_util->path($dom,
$path);
313 foreach ($nodes as $node) {
314 $pc_id = $node->getAttribute(
"PCID");
315 if (in_array($pc_id, $a_pc_ids)) {
316 $ret[$pc_id] = $node->getAttribute(
"HierId");
326 return $hier_ids[$pcid] ??
"";
333 if (!is_array($hier_ids) || count($hier_ids) == 0) {
337 if (is_object($dom)) {
339 $path =
"//*[@HierId]";
340 $nodes = $this->dom_util->path($dom,
$path);
341 foreach ($nodes as $node) {
342 $hier_id = $node->getAttribute(
"HierId");
343 if (in_array($hier_id, $hier_ids)) {
344 $ret[$hier_id] = $node->getAttribute(
"PCID");
354 return ($hier_ids[$hier_id] ??
"");
buildDom(bool $a_force=false)
getHierIdsForPCIds(array $a_pc_ids)
addHierIDsToDom()
Add hierarchical ID (e.g.
getDomDoc()
Get dom doc (DOMDocument)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getPCIdForHierId(string $hier_id)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
decEdId(string $ed_id)
Decreases an hierarchical editing id at lowest level (last number)
incEdId(string $ed_id)
Increases an hierarchical editing id at lowest level (last number)
getPCIdsForHierIds(array $hier_ids)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
__construct(\ilPageObject $page, ?ContentIdGeneratorInterface $generator=null)
getHierIds()
get all hierarchical ids
ContentIdGenerator $generator
getHierIdForPcId(string $pcid)