ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCResources.php
Go to the documentation of this file.
1<?php
2
26{
27 public function init(): void
28 {
29 $this->setType("repobj");
30 }
31
32 public function create(
33 ilPageObject $a_pg_obj,
34 string $a_hier_id,
35 string $a_pc_id = ""
36 ): void {
37 $this->createInitialChildNode($a_hier_id, $a_pc_id, "Resources");
38 }
39
40 public function setResourceListType(string $a_type): void
41 {
42 if (!empty($a_type)) {
43 $this->dom_util->deleteAllChilds($this->getChildNode());
44 $list_node = $this->dom_doc->createElement("ResourceList");
45 $list_node = $this->getChildNode()->appendChild($list_node);
46 $list_node->setAttribute("Type", $a_type);
47 }
48 }
49
50 public function setItemGroupRefId(int $a_ref_id): void
51 {
52 if (!empty($a_ref_id)) {
53 $this->dom_util->deleteAllChilds($this->getChildNode());
54 $list_node = $this->dom_doc->createElement("ItemGroup");
55 $list_node = $this->getChildNode()->appendChild($list_node);
56 $list_node->setAttribute("RefId", $a_ref_id);
57 }
58 }
59
63 public function getResourceListType(): ?string
64 {
65 if (is_object($this->getChildNode())) {
66 $c = $this->getChildNode()->childNodes->item(0);
67 if (is_object($c) && $c->nodeName == "ResourceList") {
68 return $c->getAttribute("Type");
69 }
70 }
71 return null;
72 }
73
77 public function getItemGroupRefId(): ?int
78 {
79 if (is_object($this->getChildNode())) {
80 $c = $this->getChildNode()->childNodes->item(0);
81 if (is_object($c) && $c->nodeName == "ItemGroup") {
82 return (int) $c->getAttribute("RefId");
83 }
84 }
85 return null;
86 }
87
88 public function getMainType(): ?string
89 {
90 if (is_object($this->getChildNode())) {
91 $c = $this->getChildNode()->childNodes->item(0);
92 if (is_object($c)) {
93 return (string) $c->nodeName;
94 }
95 }
96 return null;
97 }
98
99 public static function modifyItemGroupRefIdsByMapping(
100 ilPageObject $a_page,
101 array $mappings
102 ): bool {
103 $dom = $a_page->getDomDoc();
105
106 $changed = false;
107 $xpath_temp = new DOMXPath($dom);
108 $igs = $xpath_temp->query("//Resources/ItemGroup");
109
110 foreach ($igs as $ig_node) {
111 $ref_id = $ig_node->getAttribute("RefId");
112 $log->debug(">>> Fix Item Group with import Ref Id:" . $ref_id);
113 $log->debug("Ref Id Mapping:" . print_r($mappings, true));
114 if (($mappings[$ref_id] ?? 0) > 0) {
115 $ig_node->setAttribute("RefId", $mappings[$ref_id]);
116 $changed = true;
117 }
118 }
119 return $changed;
120 }
121
122 public static function getLangVars(): array
123 {
124 return array("pc_res");
125 }
126
127 public static function resolveResources(
128 ilPageObject $page,
129 array $ref_mappings
130 ): bool {
131 return self::modifyItemGroupRefIdsByMapping($page, $ref_mappings);
132 }
133}
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setResourceListType(string $a_type)
static modifyItemGroupRefIdsByMapping(ilPageObject $a_page, array $mappings)
getResourceListType()
Get Resource List Type.
setItemGroupRefId(int $a_ref_id)
init()
Init object.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
getItemGroupRefId()
Get item group ref id.
static getLangVars()
Get lang vars needed for editing.
static resolveResources(ilPageObject $page, array $ref_mappings)
Content object of ilPageObject (see ILIAS DTD).
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
$c
Definition: deliver.php:25
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
$log
Definition: ltiresult.php:34