ILIAS  release_8 Revision v8.24
class.ilPCResources.php
Go to the documentation of this file.
1<?php
2
26{
28
29 public function init(): void
30 {
31 $this->setType("repobj");
32 }
33
34 public function setNode(php4DOMElement $a_node): void
35 {
36 parent::setNode($a_node); // this is the PageContent node
37 $this->res_node = $a_node->first_child(); // this is the Resources node
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->res_node = $this->dom->create_element("Resources");
48 $this->res_node = $this->node->append_child($this->res_node);
49 }
50
51 public function setResourceListType(string $a_type): void
52 {
53 if (!empty($a_type)) {
54 $children = $this->res_node->child_nodes();
55 for ($i = 0; $i < count($children); $i++) {
56 $this->res_node->remove_child($children[$i]);
57 }
58 $list_node = $this->dom->create_element("ResourceList");
59 $list_node = $this->res_node->append_child($list_node);
60 $list_node->set_attribute("Type", $a_type);
61 }
62 }
63
64 public function setItemGroupRefId(int $a_ref_id): void
65 {
66 if (!empty($a_ref_id)) {
67 $children = $this->res_node->child_nodes();
68 for ($i = 0; $i < count($children); $i++) {
69 $this->res_node->remove_child($children[$i]);
70 }
71 $list_node = $this->dom->create_element("ItemGroup");
72 $list_node = $this->res_node->append_child($list_node);
73 $list_node->set_attribute("RefId", $a_ref_id);
74 }
75 }
76
80 public function getResourceListType(): ?string
81 {
82 if (is_object($this->res_node)) {
83 $children = $this->res_node->child_nodes();
84 if (is_object($children[0]) && $children[0]->node_name() == "ResourceList") {
85 return $children[0]->get_attribute("Type");
86 }
87 }
88 return null;
89 }
90
94 public function getItemGroupRefId(): ?int
95 {
96 if (is_object($this->res_node)) {
97 $children = $this->res_node->child_nodes();
98 if (is_object($children[0]) && $children[0]->node_name() == "ItemGroup") {
99 return (int) $children[0]->get_attribute("RefId");
100 }
101 }
102 return null;
103 }
104
105 public function getMainType(): ?string
106 {
107 if (is_object($this->res_node)) {
108 $children = $this->res_node->child_nodes();
109 if (is_object($children[0])) {
110 return (string) $children[0]->node_name();
111 }
112 }
113 return null;
114 }
115
116 public static function modifyItemGroupRefIdsByMapping(
117 ilPageObject $a_page,
118 array $mappings
119 ): bool {
120 $dom = $a_page->getDom();
122
123 if ($dom instanceof php4DOMDocument) {
124 $dom = $dom->myDOMDocument;
125 }
126 $changed = false;
127 $xpath_temp = new DOMXPath($dom);
128 $igs = $xpath_temp->query("//Resources/ItemGroup");
129
130 foreach ($igs as $ig_node) {
131 $ref_id = $ig_node->getAttribute("RefId");
132 $log->debug(">>> Fix Item Group with import Ref Id:" . $ref_id);
133 $log->debug("Ref Id Mapping:" . print_r($mappings, true));
134 if (($mappings[$ref_id] ?? 0) > 0) {
135 $ig_node->setAttribute("RefId", $mappings[$ref_id]);
136 $changed = true;
137 }
138 }
139 return $changed;
140 }
141
142 public static function getLangVars(): array
143 {
144 return array("pc_res");
145 }
146
147 public static function resolveResources(
148 ilPageObject $page,
149 array $ref_mappings
150 ): bool {
151 return self::modifyItemGroupRefIdsByMapping($page, $ref_mappings);
152 }
153}
const IL_INSERT_AFTER
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)
setNode(php4DOMElement $a_node)
Set xml node of page content.
init()
Init object.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
getItemGroupRefId()
Get item group ref id.
php4DOMElement $res_node
static getLangVars()
Get lang vars needed for editing.
static resolveResources(ilPageObject $page, array $ref_mappings)
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
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
$ref_id
Definition: ltiauth.php:67
$i
Definition: metadata.php:41
$log
Definition: result.php:33