ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilContainerReferenceImporter.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  protected $ref = null;
18 
19 
20  public function init()
21  {
22  }
23 
28  protected function initReference($a_ref_id = 0)
29  {
30  $this->ref = ilObjectFactory::getInstanceByRefId($a_ref_id,true);
31  }
32 
36  abstract protected function getType();
37 
41  abstract protected function initParser($a_xml);
42 
47  protected function getReference()
48  {
49  return $this->ref;
50  }
51 
58  function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
59  {
60  include_once './Modules/Category/classes/class.ilObjCategory.php';
61  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_id))
62  {
63  $refs = ilObject::_getAllReferences($new_id);
64  $this->initReference(end($refs));
65  }
66  // Mapping for containers without subitems
67  elseif($new_id = $a_mapping->getMapping('Services/Container','refs',0))
68  {
69  $this->initReference($new_id);
70  }
71  elseif(!$this->getReference() instanceof ilContainerReference)
72  {
73  $this->initReference();
74  $this->getReference()->create(true);
75  }
76 
77  try
78  {
79  $parser = $this->initParser($a_xml);
80  $parser->setReference($this->getReference());
82  $parser->startParsing();
83 
84  $a_mapping->addMapping(
85  $GLOBALS['objDefinition']->getComponentForType($this->getType()),
86  $this->getType(),
87  $a_id,
88  $this->getReference()->getId()
89  );
90  }
91  catch(ilSaxParserException $e)
92  {
93  $GLOBALS['ilLog']->write(__METHOD__.': Parsing failed with message, "'.$e->getMessage().'".');
94  }
95  catch(Exception $e)
96  {
97  $GLOBALS['ilLog']->write(__METHOD__.': Parsing failed with message, "'.$e->getMessage().'".');
98  }
99  }
100 }
101 ?>
initParser($a_xml)
Init xml parser.
$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
getType()
Get reference type.
$parser
Definition: BPMN2Parser.php:24
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import XML.
Xml importer class.