ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
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 
73  $a_mapping->addMapping("Modules/Glossary", "glo", $a_id, $newObj->getId());
74 
75  $this->current_glo = $newObj;
76  }
77  }
78 
85  function finalProcessing($a_mapping)
86  {
87 //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
88  // get all glossaries of the import
89  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
90  $maps = $a_mapping->getMappingsOfEntity("Modules/Glossary", "glo");
91  foreach ($maps as $old => $new)
92  {
93  if ($old != "new_id" && (int) $old > 0)
94  {
95  // get all new taxonomys of this object
96  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
97  $tax_ids = explode(":", $new_tax_ids);
98  foreach ($tax_ids as $tid)
99  {
100  ilObjTaxonomy::saveUsage($tid, $new);
101  }
102  }
103  }
104  }
105 
106 }
107 ?>