ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCOPageExporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Export/classes/class.ilXmlExporter.php");
5 
14 {
15  private $ds;
19  protected $config;
20 
36  protected $plugin_dependencies = array();
37 
41  public function init()
42  {
43  global $DIC;
45  $ilPluginAdmin = $DIC['ilPluginAdmin'];
46 
47  include_once("./Services/COPage/classes/class.ilCOPageDataSet.php");
48  $this->ds = new ilCOPageDataSet();
49  $this->ds->setExportDirectories($this->dir_relative, $this->dir_absolute);
50  $this->ds->setDSPrefix("ds");
51  $this->config = $this->getExport()->getConfig("Services/COPage");
52  if ($this->config->getMasterLanguageOnly()) {
53  $this->ds->setMasterLanguageOnly(true);
54  }
55 
56  // collect all page component plugins that have their own exporter
57  require_once('Services/COPage/classes/class.ilPageComponentPluginExporter.php');
58  foreach (ilPluginAdmin::getActivePluginsForSlot(IL_COMP_SERVICE, "COPage", "pgcp") as $plugin_name) {
59  if ($ilPluginAdmin->supportsExport(IL_COMP_SERVICE, "COPage", "pgcp", $plugin_name)) {
60  require_once('Customizing/global/plugins/Services/COPage/PageComponent/'
61  . $plugin_name . '/classes/class.il' . $plugin_name . 'Exporter.php');
62 
63  $this->plugin_dependencies[$plugin_name] = array(
64  "component" => "Plugins/" . $plugin_name,
65  "entity" => "pgcp",
66  "ids" => array()
67  );
68  }
69  }
70  }
71 
72 
81  public function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids)
82  {
83  if ($a_entity == "pg") {
84  // get all media objects and files of the page
85  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
86  include_once("./Modules/File/classes/class.ilObjFile.php");
87  $mob_ids = array();
88  $file_ids = array();
89  foreach ($a_ids as $pg_id) {
90  $pg_id = explode(":", $pg_id);
91 
92  $lang = ($this->config->getMasterLanguageOnly())
93  ? "-"
94  : "";
95 
96  // get media objects
97  if ($this->config->getIncludeMedia()) {
98  $mids = ilObjMediaObject::_getMobsOfObject($pg_id[0] . ":pg", $pg_id[1], 0, $lang);
99  foreach ($mids as $mid) {
100  if (ilObject::_lookupType($mid) == "mob") {
101  $mob_ids[] = $mid;
102  }
103  }
104  }
105 
106  // get files
107  $files = ilObjFile::_getFilesOfObject($pg_id[0] . ":pg", $pg_id[1], 0, $lang);
108  foreach ($files as $file) {
109  if (ilObject::_lookupType($file) == "file") {
110  $file_ids[] = $file;
111  }
112  }
113  }
114 
115  return array(
116  array(
117  "component" => "Services/MediaObjects",
118  "entity" => "mob",
119  "ids" => $mob_ids),
120  array(
121  "component" => "Modules/File",
122  "entity" => "file",
123  "ids" => $file_ids)
124  );
125  }
126 
127  return array();
128  }
129 
138  public function getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids)
139  {
140  if ($a_entity == "pgtp") {
141  $pg_ids = array();
142  foreach ($a_ids as $id) {
143  $pg_ids[] = "stys:" . $id;
144  }
145 
146  return array(
147  array(
148  "component" => "Services/COPage",
149  "entity" => "pg",
150  "ids" => $pg_ids)
151  );
152  }
153 
154  if (!empty($this->plugin_dependencies)) {
155  // use numeric keys instead plugin names
156  return array_values($this->plugin_dependencies);
157  }
158 
159  return array();
160  }
161 
162 
171  public function getXmlRepresentation($a_entity, $a_schema_version, $a_id)
172  {
173  if ($a_entity == "pg") {
174  include_once("./Services/COPage/classes/class.ilPageObject.php");
175 
176  $id = explode(":", $a_id);
177 
178  $langs = array("-");
179  if (!$this->config->getMasterLanguageOnly()) {
180  $trans = ilPageObject::lookupTranslations($id[0], $id[1]);
181  foreach ($trans as $t) {
182  if ($t != "-") {
183  $langs[] = $t;
184  }
185  }
186  }
187 
188  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
189  $xml = "";
190  foreach ($langs as $l) {
191  $page_object = ilPageObjectFactory::getInstance($id[0], $id[1], 0, $l);
192  $page_object->buildDom();
193  $page_object->insertInstIntoIDs(IL_INST_ID);
194  $this->extractPluginProperties($page_object);
195  $pxml = $page_object->getXMLFromDom(false, false, false, "", true);
196  $pxml = str_replace("&", "&amp;", $pxml);
197  $a_media = ($this->config->getIncludeMedia())
198  ? ""
199  : 'WithoutMedia="1"';
200  $xml.= '<PageObject Language="' . $l . '" Active="' . $page_object->getActive() . '" ActivationStart="' . $page_object->getActivationStart() . '" ActivationEnd="' .
201  $page_object->getActivationEnd() . '" ShowActivationInfo="' . $page_object->getShowActivationInfo() . '" ' . $a_media . '>';
202  $xml.= $pxml;
203  $xml.= "</PageObject>";
204  $page_object->freeDom();
205  }
206 
207  return $xml;
208  }
209  if ($a_entity == "pgtp") {
210  return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, $a_id, "", true, true);
211  }
212  }
213 
221  public function getValidSchemaVersions($a_entity)
222  {
223  if ($a_entity == "pg") {
224  return array(
225  "4.2.0" => array(
226  "namespace" => "http://www.ilias.de/Services/COPage/pg/4_2",
227  "xsd_file" => "ilias_pg_4_2.xsd",
228  "min" => "4.2.0",
229  "max" => ""),
230  "4.1.0" => array(
231  "namespace" => "http://www.ilias.de/Services/COPage/pg/4_1",
232  "xsd_file" => "ilias_pg_4_1.xsd",
233  "min" => "4.1.0",
234  "max" => "4.1.99")
235  );
236  }
237  if ($a_entity == "pgtp") {
238  return array(
239  "4.2.0" => array(
240  "namespace" => "http://www.ilias.de/Services/COPage/pgtp/4_1",
241  "xsd_file" => "ilias_pgtp_4_1.xsd",
242  "uses_dataset" => true,
243  "min" => "4.2.0",
244  "max" => "")
245  );
246  }
247  }
248 
259  protected function extractPluginProperties($a_page)
260  {
261  if (empty($this->plugin_dependencies)) {
262  return;
263  }
264 
265  $a_page->buildDom();
266  $domdoc = $a_page->getDomDoc();
267  $xpath = new DOMXPath($domdoc);
268  $nodes = $xpath->query("//PageContent[child::Plugged]");
269 
271  foreach ($nodes as $pcnode) {
272  // page content id (unique in the page)
273  $pc_id = $pcnode->getAttribute('PCID');
274  $plnode = $pcnode->childNodes->item(0);
275  $plugin_name = $plnode->getAttribute('PluginName');
276  $plugin_version = $plnode->getAttribute('PluginVersion');
277 
278  // dependency should be exported
279  if (isset($this->plugin_dependencies[$plugin_name])) {
280  // construct a unique dependency id of the plugged page content
281  $id = $a_page->getParentType()
282  . ':' . $a_page->getId()
283  . ':' . $a_page->getLanguage()
284  . ':' . $pc_id;
285 
286  $properties = array();
288  foreach ($plnode->childNodes as $child) {
289  $properties[$child->getAttribute('Name')] = $child->nodeValue;
290  }
291 
292  // statical provision of content to the exporter classes
295 
296  // each plugin exporter gets only the ids of its own content
297  $this->plugin_dependencies[$plugin_name]['ids'][] = $id;
298  }
299  }
300  }
301 }
$files
Definition: add-vimline.php:18
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
global $DIC
Definition: saml.php:7
getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids)
Get head dependencies.
if(!array_key_exists('StateId', $_REQUEST)) $id
getXmlExportTailDependencies($a_entity, $a_target_release, $a_ids)
Get tail dependencies.
COPage Data set class.
getValidSchemaVersions($a_entity)
Returns schema versions that the component can export to.
Xml Exporter class.
$xml
Definition: metadata.php:240
getXmlRepresentation($a_entity, $a_schema_version, $a_id)
Get xml representation.
static _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_usage_lang="-")
get all files of an object
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
global $l
Definition: afr.php:30
static lookupTranslations($a_parent_type, $a_id)
Lookup translations.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Exporter class for meta data.
const IL_COMP_SERVICE
static setPCVersion($a_id, $a_version)
Set the version of a plugged page content This method is used by ilCOPageExporter to provide the vers...
static setPCProperties($a_id, $a_properties)
Set the properties of a plugged page content This method is used by ilCOPageExporter to provide the p...
getExport()
Get export.