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