ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4include_once("./Services/Export/classes/class.ilXmlImporter.php");
5
14{
21 function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
22 {
23 if ($a_entity == "glo")
24 {
25 // case i container
26 if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
27 {
28 $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
29
30 $xml_file = $this->getImportDirectory().'/'.basename($this->getImportDirectory()).'.xml';
31 $GLOBALS['ilLog']->write(__METHOD__.': Using XML file '.$xml_file);
32
33 }
34 else if ($new_id = $a_mapping->getMapping('Modules/Glossary','glo', "new_id")) // this mapping is only set by ilObjGlossaryGUI
35 {
36 $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
37
38 $xml_file = $this->getImportDirectory().'/'.basename($this->getImportDirectory()).'.xml';
39 $GLOBALS['ilLog']->write(__METHOD__.': Using XML file '.$xml_file);
40 }
41 else
42 {
43 // Shouldn't happen
44 $GLOBALS['ilLog']->write(__METHOD__.': Called in non container mode');
45 $GLOBALS['ilLog']->logStack();
46 return false;
47 }
48
49 if(!file_exists($xml_file))
50 {
51 $GLOBALS['ilLog']->write(__METHOD__.': ERROR Cannot find '.$xml_file);
52 return false;
53 }
54
55 include_once './Modules/LearningModule/classes/class.ilContObjParser.php';
56 $contParser = new ilContObjParser(
57 $newObj,
58 $xml_file,
59 basename($this->getImportDirectory())
60 );
61
62 $contParser->startParsing();
63 ilObject::_writeImportId($newObj->getId(), $newObj->getImportId());
64
65 // write term map for taxonomies to mapping object
66 $term_map = $contParser->getGlossaryTermMap();
67 foreach ($term_map as $k => $v)
68 {
69 $a_mapping->addMapping("Services/Taxonomy", "tax_item",
70 "glo:term:".$k, $v);
71
72 // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
73 $a_mapping->addMapping("Services/Taxonomy", "tax_item_obj_id",
74 "glo:term:".$k, $newObj->getId());
75
76 $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item",
77 "advmd:term:".$k, $v);
78 }
79
80 // ???
81 $a_mapping->addMapping("Services/Taxonomy", "tax_item",
82 "glo:term:".$k, $v);
83
84 $a_mapping->addMapping("Modules/Glossary", "glo", $a_id, $newObj->getId());
85 $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_id, $newObj->getId());
86
87 $this->current_glo = $newObj;
88 }
89 }
90
97 function finalProcessing($a_mapping)
98 {
99//echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
100 // get all glossaries of the import
101 include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
102 $maps = $a_mapping->getMappingsOfEntity("Modules/Glossary", "glo");
103 foreach ($maps as $old => $new)
104 {
105 if ($old != "new_id" && (int) $old > 0)
106 {
107 // get all new taxonomys of this object
108 $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
109 if($new_tax_ids !== false)
110 {
111 $tax_ids = explode(":", $new_tax_ids);
112 foreach ($tax_ids as $tid)
113 {
114 ilObjTaxonomy::saveUsage($tid, $new);
115 }
116 }
117 }
118 }
119 }
120
121}
122?>
Content Object Parser.
Importer class for files.
finalProcessing($a_mapping)
Final processing.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
_writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Xml importer class.
getImportDirectory()
Get import directory.
$GLOBALS['ct_recipient']