ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCOPageExporter.php
Go to the documentation of this file.
1<?php
2
24{
27
43 protected array $plugin_dependencies = array();
44
48 public function init(): void
49 {
50 global $DIC;
52 $component_repository = $DIC["component.repository"];
53
54 $this->ds = new ilCOPageDataSet();
55 $this->ds->initByExporter($this);
56 $this->ds->setDSPrefix("ds");
58 $config = $this->getExport()->getExportConfigs()->getElementByComponent('components/ILIAS/COPage');
59 $this->config = $config;
60 if ($this->config->getMasterLanguageOnly()) {
61 $this->ds->setMasterLanguageOnly(true);
62 }
63
64 // collect all page component plugins that have their own exporter
65 foreach ($component_repository->getPluginSlotById("pgcp")->getActivePlugins() as $plugin) {
66 $plugin_name = $plugin->getName();
67 if ($plugin->supportsExport()) {
68 $this->plugin_dependencies[$plugin_name] = array(
69 "component" => "Plugins/" . $plugin_name,
70 "entity" => "pgcp",
71 "ids" => array()
72 );
73 }
74 }
75 }
76
78 string $a_entity,
79 string $a_target_release,
80 array $a_ids
81 ): array {
82 if ($a_entity == "pg") {
83 // get all media objects and files of the page
84 $mob_ids = array();
85 $file_ids = array();
86 foreach ($a_ids as $pg_id) {
87 $pg_id = explode(":", $pg_id);
88
89 $lang = ($this->config->getMasterLanguageOnly())
90 ? "-"
91 : "";
92
93 // get media objects
94 if ($this->config->getIncludeMedia()) {
95 $mids = ilObjMediaObject::_getMobsOfObject($pg_id[0] . ":pg", $pg_id[1], 0, $lang);
96 foreach ($mids as $mid) {
97 if (ilObject::_lookupType($mid) == "mob") {
98 $mob_ids[] = $mid;
99 }
100 }
101 }
102
103 // get files
104 $files = ilObjFile::_getFilesOfObject($pg_id[0] . ":pg", $pg_id[1], 0, $lang);
105 foreach ($files as $file) {
106 if (ilObject::_lookupType($file) == "file") {
107 $file_ids[] = $file;
108 }
109 }
110 }
111
112 return array(
113 array(
114 "component" => "components/ILIAS/MediaObjects",
115 "entity" => "mob",
116 "ids" => $mob_ids),
117 array(
118 "component" => "components/ILIAS/File",
119 "entity" => "file",
120 "ids" => $file_ids)
121 );
122 }
123
124 return array();
125 }
126
128 string $a_entity,
129 string $a_target_release,
130 array $a_ids
131 ): array {
132 if ($a_entity == "pgtp") {
133 $pg_ids = array();
134 foreach ($a_ids as $id) {
135 $pg_ids[] = "stys:" . $id;
136 }
137
138 return array(
139 array(
140 "component" => "components/ILIAS/COPage",
141 "entity" => "pg",
142 "ids" => $pg_ids)
143 );
144 }
145
146 if (!empty($this->plugin_dependencies)) {
147 // use numeric keys instead plugin names
148 return array_values($this->plugin_dependencies);
149 }
150
151 return array();
152 }
153
154 public function getXmlRepresentation(
155 string $a_entity,
156 string $a_schema_version,
157 string $a_id
158 ): string {
159 if ($a_entity == "pg") {
160 $id = explode(":", $a_id);
161
162 $langs = array("-");
163 if (!$this->config->getMasterLanguageOnly()) {
165 foreach ($trans as $t) {
166 if ($t != "-") {
167 $langs[] = $t;
168 }
169 }
170 }
171
172 $xml = "";
173 foreach ($langs as $l) {
174 $page_object = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $l);
175 $page_object->buildDom();
176 $page_object->insertInstIntoIDs(IL_INST_ID);
177 $this->extractPluginProperties($page_object);
178 $pxml = $page_object->getXMLFromDom(false, false, false, "", true);
179 $pxml = str_replace("&", "&amp;", $pxml);
180 $a_media = ($this->config->getIncludeMedia())
181 ? ""
182 : 'WithoutMedia="1"';
183 $xml .= '<PageObject Language="' . $l . '" Active="' . $page_object->getActive() . '" ActivationStart="' . $page_object->getActivationStart() . '" ActivationEnd="' .
184 $page_object->getActivationEnd() . '" ShowActivationInfo="' . $page_object->getShowActivationInfo() . '" ' . $a_media . '>';
185 $xml .= $pxml;
186 $xml .= "</PageObject>";
187 $page_object->freeDom();
188 }
189
190 return $xml;
191 }
192 if ($a_entity == "pgtp") {
193 return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, [$a_id], "", true, true);
194 }
195 return "";
196 }
197
198 public function getValidSchemaVersions(
199 string $a_entity
200 ): array {
201 if ($a_entity == "pg") {
202 return array(
203 "4.2.0" => array(
204 "namespace" => "https://www.ilias.de/Services/COPage/pg/4_2",
205 "xsd_file" => "ilias_pg_4_2.xsd",
206 "min" => "4.2.0",
207 "max" => ""),
208 "4.1.0" => array(
209 "namespace" => "https://www.ilias.de/Services/COPage/pg/4_1",
210 "xsd_file" => "ilias_pg_4_1.xsd",
211 "min" => "4.1.0",
212 "max" => "4.1.99")
213 );
214 }
215 if ($a_entity == "pgtp") {
216 return array(
217 "4.2.0" => array(
218 "namespace" => "https://www.ilias.de/Services/COPage/pgtp/4_1",
219 "xsd_file" => "ilias_pgtp_4_1.xsd",
220 "uses_dataset" => true,
221 "min" => "4.2.0",
222 "max" => "")
223 );
224 }
225 return [];
226 }
227
236 protected function extractPluginProperties(
237 ilPageObject $a_page
238 ): void {
239 if (empty($this->plugin_dependencies)) {
240 return;
241 }
242
243 $a_page->buildDom();
244 $domdoc = $a_page->getDomDoc();
245 $xpath = new DOMXPath($domdoc);
246 $nodes = $xpath->query("//PageContent[child::Plugged]");
247
249 foreach ($nodes as $pcnode) {
250 // page content id (unique in the page)
251 $pc_id = $pcnode->getAttribute('PCID');
252 $plnode = $pcnode->childNodes->item(0);
253 $plugin_name = $plnode->getAttribute('PluginName');
254 $plugin_version = $plnode->getAttribute('PluginVersion');
255
256 // dependency should be exported
257 if (isset($this->plugin_dependencies[$plugin_name])) {
258 // construct a unique dependency id of the plugged page content
259 $id = $a_page->getParentType()
260 . ':' . $a_page->getId()
261 . ':' . $a_page->getLanguage()
262 . ':' . $pc_id;
263
264 $properties = array();
266 foreach ($plnode->childNodes as $child) {
267 $properties[$child->getAttribute('Name')] = $child->nodeValue;
268 }
269
270 // statical provision of content to the exporter classes
273
274 // each plugin exporter gets only the ids of its own content
275 $this->plugin_dependencies[$plugin_name]['ids'][] = $id;
276 }
277 }
278 }
279}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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...
setMasterLanguageOnly(bool $a_val, bool $a_include_media=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlRepresentation(string $a_entity, string $a_schema_version, string $a_id)
getXmlExportHeadDependencies(string $a_entity, string $a_target_release, array $a_ids)
Get head dependencies.
ilCOPageExportConfig $config
getXmlExportTailDependencies(string $a_entity, string $a_target_release, array $a_ids)
Get tail dependencies.
getValidSchemaVersions(string $a_entity)
Returns schema versions that the component can export to.
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
static _lookupType(int $id, bool $reference=false)
static setPCProperties(string $a_id, array $a_properties)
Set the properties of a plugged page content This method is used by ilCOPageExporter to provide the p...
static setPCVersion(string $a_id, string $a_version)
Set the version of a plugged page content This method is used by ilCOPageExporter to provide the vers...
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static lookupTranslations(string $a_parent_type, int $a_id)
Lookup translations.
Xml Exporter class.
const IL_INST_ID
Definition: constants.php:40
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25