ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public 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  public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
33  {
34  if ($a_entity == "glo") {
35  // case i container
36  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
37  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
38  }
39 
40  // in the new version (5.1) we are also here, but the following file should not exist
41  // if being exported with 5.1 or higher
42  $xml_file = $this->getImportDirectory() . '/' . basename($this->getImportDirectory()) . '.xml';
43  $GLOBALS['ilLog']->write(__METHOD__ . ': Using XML file ' . $xml_file);
44 
45  // old school import
46  if (file_exists($xml_file)) {
47  if (!is_object($newObj)) {
48  // create and insert object in objecttree
49  include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
50  $newObj = new ilObjGlossary();
51  $newObj->setType("glo");
52  $newObj->setTitle(basename($this->getImportDirectory()));
53  $newObj->create(true);
54  }
55 
56  include_once './Modules/LearningModule/classes/class.ilContObjParser.php';
57  $contParser = new ilContObjParser(
58  $newObj,
59  $xml_file,
60  basename($this->getImportDirectory())
61  );
62 
63  $contParser->startParsing();
64 
65  ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
66 
67  // write term map for taxonomies to mapping object
68  $term_map = $contParser->getGlossaryTermMap();
69  foreach ($term_map as $k => $v) {
70  $a_mapping->addMapping(
71  "Services/Taxonomy",
72  "tax_item",
73  "glo:term:" . $k,
74  $v
75  );
76 
77  // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
78  $a_mapping->addMapping(
79  "Services/Taxonomy",
80  "tax_item_obj_id",
81  "glo:term:" . $k,
82  $newObj->getId()
83  );
84 
85  $a_mapping->addMapping(
86  "Services/AdvancedMetaData",
87  "advmd_sub_item",
88  "advmd:term:" . $k,
89  $v
90  );
91  }
92 
93  $a_mapping->addMapping("Modules/Glossary", "glo", $a_id, $newObj->getId());
94  $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_id, $newObj->getId());
95 
96  $this->current_glo = $newObj;
97  } else {
98  // necessary?
99  // ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
100  include_once("./Services/DataSet/classes/class.ilDataSetImportParser.php");
102  $a_entity,
103  $this->getSchemaVersion(),
104  $a_xml,
105  $this->ds,
106  $a_mapping
107  );
108 
109  // in the new version the mapping above is done in the dataset
110  }
111  }
112  }
113 
120  public function finalProcessing($a_mapping)
121  {
122  //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
123  // get all glossaries of the import
124  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
125  $maps = $a_mapping->getMappingsOfEntity("Modules/Glossary", "glo");
126  foreach ($maps as $old => $new) {
127  if ($old != "new_id" && (int) $old > 0) {
128  // get all new taxonomys of this object
129  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
130  if ($new_tax_ids !== false) {
131  $tax_ids = explode(":", $new_tax_ids);
132  foreach ($tax_ids as $tid) {
133  ilObjTaxonomy::saveUsage($tid, $new);
134  }
135  }
136 
137  // advmd column order
138  if ($this->exportedFromSameInstallation()) {
139  include_once("./Modules/Glossary/classes/class.ilGlossaryAdvMetaDataAdapter.php");
140  $advmdco = $a_mapping->getMappingsOfEntity("Modules/Glossary", "advmd_col_order");
141  foreach ($advmdco as $id => $order) {
142  $id = explode(":", $id);
143  $field_glo_id = $id[0];
144  $field_id = $id[1];
145  if ($field_glo_id == $old) {
146  // #17454
147  $new_local_id = $a_mapping->getMapping("Services/AdvancedMetaData", "lfld", $field_id);
148  if ($new_local_id) {
149  $field_id = $new_local_id;
150  }
151  ilGlossaryAdvMetaDataAdapter::writeColumnOrder($new, $field_id, $order);
152  }
153  }
154  }
155  }
156  }
157  }
158 }
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
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.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
$parser
Definition: BPMN2Parser.php:23
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Xml importer class.