ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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->initByExporter($this);
56  $this->ds->setDSPrefix("ds");
57  $this->config = $this->getExport()->getConfig("components/ILIAS/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  $this->plugin_dependencies[$plugin_name] = array(
67  "component" => "Plugins/" . $plugin_name,
68  "entity" => "pgcp",
69  "ids" => array()
70  );
71  }
72  }
73  }
74 
76  string $a_entity,
77  string $a_target_release,
78  array $a_ids
79  ): array {
80  if ($a_entity == "pg") {
81  // get all media objects and files of the page
82  $mob_ids = array();
83  $file_ids = array();
84  foreach ($a_ids as $pg_id) {
85  $pg_id = explode(":", $pg_id);
86 
87  $lang = ($this->config->getMasterLanguageOnly())
88  ? "-"
89  : "";
90 
91  // get media objects
92  if ($this->config->getIncludeMedia()) {
93  $mids = ilObjMediaObject::_getMobsOfObject($pg_id[0] . ":pg", $pg_id[1], 0, $lang);
94  foreach ($mids as $mid) {
95  if (ilObject::_lookupType($mid) == "mob") {
96  $mob_ids[] = $mid;
97  }
98  }
99  }
100 
101  // get files
102  $files = ilObjFile::_getFilesOfObject($pg_id[0] . ":pg", $pg_id[1], 0, $lang);
103  foreach ($files as $file) {
104  if (ilObject::_lookupType($file) == "file") {
105  $file_ids[] = $file;
106  }
107  }
108  }
109 
110  return array(
111  array(
112  "component" => "components/ILIAS/MediaObjects",
113  "entity" => "mob",
114  "ids" => $mob_ids),
115  array(
116  "component" => "components/ILIAS/File",
117  "entity" => "file",
118  "ids" => $file_ids)
119  );
120  }
121 
122  return array();
123  }
124 
126  string $a_entity,
127  string $a_target_release,
128  array $a_ids
129  ): array {
130  if ($a_entity == "pgtp") {
131  $pg_ids = array();
132  foreach ($a_ids as $id) {
133  $pg_ids[] = "stys:" . $id;
134  }
135 
136  return array(
137  array(
138  "component" => "components/ILIAS/COPage",
139  "entity" => "pg",
140  "ids" => $pg_ids)
141  );
142  }
143 
144  if (!empty($this->plugin_dependencies)) {
145  // use numeric keys instead plugin names
146  return array_values($this->plugin_dependencies);
147  }
148 
149  return array();
150  }
151 
152  public function getXmlRepresentation(
153  string $a_entity,
154  string $a_schema_version,
155  string $a_id
156  ): string {
157  if ($a_entity == "pg") {
158  $id = explode(":", $a_id);
159 
160  $langs = array("-");
161  if (!$this->config->getMasterLanguageOnly()) {
162  $trans = ilPageObject::lookupTranslations($id[0], $id[1]);
163  foreach ($trans as $t) {
164  if ($t != "-") {
165  $langs[] = $t;
166  }
167  }
168  }
169 
170  $xml = "";
171  foreach ($langs as $l) {
172  $page_object = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $l);
173  $page_object->buildDom();
174  $page_object->insertInstIntoIDs(IL_INST_ID);
175  $this->extractPluginProperties($page_object);
176  $pxml = $page_object->getXMLFromDom(false, false, false, "", true);
177  $pxml = str_replace("&", "&amp;", $pxml);
178  $a_media = ($this->config->getIncludeMedia())
179  ? ""
180  : 'WithoutMedia="1"';
181  $xml .= '<PageObject Language="' . $l . '" Active="' . $page_object->getActive() . '" ActivationStart="' . $page_object->getActivationStart() . '" ActivationEnd="' .
182  $page_object->getActivationEnd() . '" ShowActivationInfo="' . $page_object->getShowActivationInfo() . '" ' . $a_media . '>';
183  $xml .= $pxml;
184  $xml .= "</PageObject>";
185  $page_object->freeDom();
186  }
187 
188  return $xml;
189  }
190  if ($a_entity == "pgtp") {
191  return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, [$a_id], "", true, true);
192  }
193  return "";
194  }
195 
196  public function getValidSchemaVersions(
197  string $a_entity
198  ): array {
199  if ($a_entity == "pg") {
200  return array(
201  "4.2.0" => array(
202  "namespace" => "https://www.ilias.de/Services/COPage/pg/4_2",
203  "xsd_file" => "ilias_pg_4_2.xsd",
204  "min" => "4.2.0",
205  "max" => ""),
206  "4.1.0" => array(
207  "namespace" => "https://www.ilias.de/Services/COPage/pg/4_1",
208  "xsd_file" => "ilias_pg_4_1.xsd",
209  "min" => "4.1.0",
210  "max" => "4.1.99")
211  );
212  }
213  if ($a_entity == "pgtp") {
214  return array(
215  "4.2.0" => array(
216  "namespace" => "https://www.ilias.de/Services/COPage/pgtp/4_1",
217  "xsd_file" => "ilias_pgtp_4_1.xsd",
218  "uses_dataset" => true,
219  "min" => "4.2.0",
220  "max" => "")
221  );
222  }
223  return [];
224  }
225 
234  protected function extractPluginProperties(
235  ilPageObject $a_page
236  ): void {
237  if (empty($this->plugin_dependencies)) {
238  return;
239  }
240 
241  $a_page->buildDom();
242  $domdoc = $a_page->getDomDoc();
243  $xpath = new DOMXPath($domdoc);
244  $nodes = $xpath->query("//PageContent[child::Plugged]");
245 
247  foreach ($nodes as $pcnode) {
248  // page content id (unique in the page)
249  $pc_id = $pcnode->getAttribute('PCID');
250  $plnode = $pcnode->childNodes->item(0);
251  $plugin_name = $plnode->getAttribute('PluginName');
252  $plugin_version = $plnode->getAttribute('PluginVersion');
253 
254  // dependency should be exported
255  if (isset($this->plugin_dependencies[$plugin_name])) {
256  // construct a unique dependency id of the plugged page content
257  $id = $a_page->getParentType()
258  . ':' . $a_page->getId()
259  . ':' . $a_page->getLanguage()
260  . ':' . $pc_id;
261 
262  $properties = array();
264  foreach ($plnode->childNodes as $child) {
265  $properties[$child->getAttribute('Name')] = $child->nodeValue;
266  }
267 
268  // statical provision of content to the exporter classes
271 
272  // each plugin exporter gets only the ids of its own content
273  $this->plugin_dependencies[$plugin_name]['ids'][] = $id;
274  }
275  }
276  }
277 }
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...
getDomDoc()
Get dom doc (DOMDocument)
static lookupTranslations(string $a_parent_type, int $a_id)
Lookup translations.
getValidSchemaVersions(string $a_entity)
Export configuration class parent class.
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)
global $DIC
Definition: shib_login.php:22
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
$lang
Definition: xapiexit.php:25
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...