ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCategoryImporter.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.ilXmlImporter.php");
5 
16 {
17  private $category = null;
18 
19 
20  public function init()
21  {
22  }
23 
30  public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
31  {
32  include_once './Modules/Category/classes/class.ilObjCategory.php';
33  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
34  $refs = ilObject::_getAllReferences($new_id);
35  $this->category = ilObjectFactory::getInstanceByRefId(end($refs), false);
36  }
37  // Mapping for containers without subitems
38  elseif ($new_id = $a_mapping->getMapping('Services/Container', 'refs', 0)) {
39  $this->category = ilObjectFactory::getInstanceByRefId($new_id, false);
40  } elseif (!$this->category instanceof ilObjCategory) {
41  $this->category = new ilObjCategory();
42  $this->category->create(true);
43  }
44 
45  include_once './Modules/Category/classes/class.ilCategoryXmlParser.php';
46 
47  try {
48  $parser = new ilCategoryXmlParser($a_xml, 0);
49  $parser->setCategory($this->category);
51  $parser->startParsing();
52  $a_mapping->addMapping('Modules/Category', 'cat', $a_id, $this->category->getId());
53  } catch (ilSaxParserException $e) {
54  $GLOBALS['ilLog']->write(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
55  } catch (Exception $e) {
56  $GLOBALS['ilLog']->write(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
57  }
58 
59  foreach ($a_mapping->getMappingsOfEntity('Services/Container', 'objs') as $old => $new) {
61 
62  // see ilGlossaryImporter::importXmlRepresentation()
63  // see ilTaxonomyDataSet::importRecord()
64 
65  $a_mapping->addMapping(
66  "Services/Taxonomy",
67  "tax_item",
68  $type . ":obj:" . $old,
69  $new
70  );
71 
72  // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
73  $a_mapping->addMapping(
74  "Services/Taxonomy",
75  "tax_item_obj_id",
76  $type . ":obj:" . $old,
77  $new
78  );
79  }
80  }
81 
88  public function finalProcessing($a_mapping)
89  {
90  //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
91  // get all categories of the import
92  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
93  $maps = $a_mapping->getMappingsOfEntity("Modules/Category", "cat");
94  foreach ($maps as $old => $new) {
95  if ($old != "new_id" && (int) $old > 0) {
96  // get all new taxonomys of this object
97  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
98  $tax_ids = explode(":", $new_tax_ids);
99  foreach ($tax_ids as $tid) {
100  ilObjTaxonomy::saveUsage($tid, $new);
101  }
102  }
103  }
104  }
105 }
$type
finalProcessing($a_mapping)
Final processing.
SaxParserException thrown by ilSaxParser if property throwException is set.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilObjCategory.
$parser
Definition: BPMN2Parser.php:23
static saveUsage($a_tax_id, $a_obj_id)
Save Usage.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Xml importer class.