ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  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  {
35  $refs = ilObject::_getAllReferences($new_id);
36  $this->category = ilObjectFactory::getInstanceByRefId(end($refs),false);
37  }
38  // Mapping for containers without subitems
39  elseif($new_id = $a_mapping->getMapping('Services/Container','refs',0))
40  {
41  $this->category = ilObjectFactory::getInstanceByRefId($new_id,false);
42  }
43  elseif(!$this->category instanceof ilObjCategory)
44  {
45  $this->category = new ilObjCategory();
46  $this->category->create(true);
47  }
48 
49  include_once './Modules/Category/classes/class.ilCategoryXmlParser.php';
50 
51  try
52  {
53  $parser = new ilCategoryXmlParser($a_xml,0);
54  $parser->setCategory($this->category);
56  $parser->startParsing();
57  $a_mapping->addMapping('Modules/Category','cat',$a_id,$this->category->getId());
58  }
59  catch(ilSaxParserException $e)
60  {
61  $GLOBALS['ilLog']->write(__METHOD__.': Parsing failed with message, "'.$e->getMessage().'".');
62  }
63  catch(Exception $e)
64  {
65  $GLOBALS['ilLog']->write(__METHOD__.': Parsing failed with message, "'.$e->getMessage().'".');
66  }
67 
68  foreach($a_mapping->getMappingsOfEntity('Services/Container', 'objs') as $old => $new)
69  {
70  $type = ilObject::_lookupType($new);
71 
72  // see ilGlossaryImporter::importXmlRepresentation()
73  // see ilTaxonomyDataSet::importRecord()
74 
75  $a_mapping->addMapping("Services/Taxonomy", "tax_item",
76  $type.":obj:".$old, $new);
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  $type.":obj:".$old, $new);
81 
82  }
83  }
84 
91  function finalProcessing($a_mapping)
92  {
93 //echo "<pre>".print_r($a_mapping, true)."</pre>"; exit;
94  // get all categories of the import
95  include_once("./Services/Taxonomy/classes/class.ilObjTaxonomy.php");
96  $maps = $a_mapping->getMappingsOfEntity("Modules/Category", "cat");
97  foreach ($maps as $old => $new)
98  {
99  if ($old != "new_id" && (int) $old > 0)
100  {
101  // get all new taxonomys of this object
102  $new_tax_ids = $a_mapping->getMapping("Services/Taxonomy", "tax_usage_of_obj", $old);
103  $tax_ids = explode(":", $new_tax_ids);
104  foreach ($tax_ids as $tid)
105  {
107  }
108  }
109  }
110  }
111 
112 }
113 ?>
finalProcessing($a_mapping)
Final processing.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
SaxParserException thrown by ilSaxParser if property throwException is set.
static _getAllReferences($a_id)
get all reference ids of object
$old
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilObjCategory.
$parser
Definition: BPMN2Parser.php:24
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
Xml importer class.