ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilGlossaryImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Export/classes/class.ilXmlImporter.php");
5 
14 {
18  function init()
19  {
20  include_once("./Modules/Glossary/classes/class.ilGlossaryDataSet.php");
21  $this->ds = new ilGlossaryDataSet();
22  $this->ds->setDSPrefix("ds");
23  $this->config = $this->getImport()->getConfig("Modules/Glossary");
24  }
25 
32  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
33  {
34  if ($a_entity == "glo")
35  {
36  // case i container
37  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
38  {
39  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
40  }
41 
42  // in the new version (5.1) we are also here, but the following file should not exist
43  // if being exported with 5.1 or higher
44  $xml_file = $this->getImportDirectory().'/'.basename($this->getImportDirectory()).'.xml';
45  $GLOBALS['ilLog']->write(__METHOD__.': Using XML file '.$xml_file);
46 
47  // old school import
48  if (file_exists($xml_file))
49  {
50  if (!is_object($newObj))
51  {
52  // create and insert object in objecttree
53  include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
54  $newObj = new ilObjGlossary();
55  $newObj->setType("glo");
56  $newObj->setTitle(basename($this->getImportDirectory()));
57  $newObj->create(true);
58  }
59 
60  include_once './Modules/LearningModule/classes/class.ilContObjParser.php';
61  $contParser = new ilContObjParser(
62  $newObj,
63  $xml_file,
64  basename($this->getImportDirectory())
65  );
66 
67  $contParser->startParsing();
68 
69  ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
70 
71  // write term map for taxonomies to mapping object
72  $term_map = $contParser->getGlossaryTermMap();
73  foreach ($term_map as $k => $v)
74  {
75  $a_mapping->addMapping("Services/Taxonomy", "tax_item",
76  "glo:term:".$k, $v);
77 
78  // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
79  $a_mapping->addMapping("Services/Taxonomy", "tax_item_obj_id",
80  "glo:term:".$k, $newObj->getId());
81 
82  $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item",
83  "advmd:term:".$k, $v);
84  }
85 
86  $a_mapping->addMapping("Modules/Glossary", "glo", $a_id, $newObj->getId());
87  $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_id, $newObj->getId());
88 
89  $this->current_glo = $newObj;
90  }
91  else
92  {
93  // necessary?
94  // ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
95  include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
96  $parser = new ilDataSetImportParser($a_entity, $this->getSchemaVersion(),
97  $a_xml, $this->ds, $a_mapping);
98 
99  // in the new version the mapping above is done in the dataset
100  }
101 
102 
103  }
104  }
105 
112  function finalProcessing($a_mapping)
113  {
114 //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
115  // get all glossaries of the import
116  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
117  $maps = $a_mapping->getMappingsOfEntity("Modules/Glossary", "glo");
118  foreach ($maps as $old => $new)
119  {
120  if ($old != "new_id" && (int) $old > 0)
121  {
122  // get all new taxonomys of this object
123  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
124  if($new_tax_ids !== false)
125  {
126  $tax_ids = explode(":", $new_tax_ids);
127  foreach ($tax_ids as $tid)
128  {
130  }
131  }
132 
133  // advmd column order
134  if ($this->exportedFromSameInstallation())
135  {
136  include_once("./Modules/Glossary/classes/class.ilGlossaryAdvMetaDataAdapter.php");
137  $advmdco = $a_mapping->getMappingsOfEntity("Modules/Glossary", "advmd_col_order");
138  foreach ($advmdco as $id => $order)
139  {
140  $id = explode(":", $id);
141  $field_glo_id = $id[0];
142  $field_id = $id[1];
143  if ($field_glo_id == $old)
144  {
145  // #17454
146  $new_local_id = $a_mapping->getMapping("Services/AdvancedMetaData", "lfld", $field_id);
147  if($new_local_id)
148  {
149  $field_id = $new_local_id;
150  }
152  }
153  }
154  }
155  }
156  }
157  }
158 
159 }
160 ?>
Content Object Parser.
getSchemaVersion()
Get schema version.
Class ilObjGlossary.
getImportDirectory()
Get import directory.
static writeColumnOrder($a_glo_id, $a_field_id, $a_order_nr)
Write single column order.
Importer class for files.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
Manifest parser for ILIAS standard export files.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
getImport()
Get import.
exportedFromSameInstallation()
Is exporting and importing installation identical?
Glossary Data set class.
finalProcessing($a_mapping)
Final processing.
$old
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$parser
Definition: BPMN2Parser.php:24
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Xml importer class.