ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4include_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 public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
59 {
60 global $DIC;
61
62 $objDefinition = $DIC["objDefinition"];
63 $log = $DIC->logger()->root();
64
65 include_once './Modules/Category/classes/class.ilObjCategory.php';
66 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) {
67 $refs = ilObject::_getAllReferences($new_id);
68 $this->initReference(end($refs));
69 }
70 // Mapping for containers without subitems
71 elseif ($new_id = $a_mapping->getMapping('Services/Container', 'refs', 0)) {
72 $this->initReference($new_id);
73 } elseif (!$this->getReference() instanceof ilContainerReference) {
74 $this->initReference();
75 $this->getReference()->create(true);
76 }
77
78 try {
82 $parser = $this->initParser($a_xml);
83 $parser->setImportMapping($a_mapping);
84 $parser->setReference($this->getReference());
86 $parser->startParsing();
87
88 $a_mapping->addMapping(
89 $objDefinition->getComponentForType($this->getType()),
90 $this->getType(),
91 $a_id,
92 $this->getReference()->getId()
93 );
94 } catch (ilSaxParserException $e) {
95 $log->error(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
96 } catch (Exception $e) {
97 $log->error(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
98 }
99 }
100}
$parser
Definition: BPMN2Parser.php:23
An exception for terminatinating execution or to throw for unit testing.
initParser($a_xml)
Init xml parser.
getType()
Get reference type.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences($a_id)
get all reference ids of object
SaxParserException thrown by ilSaxParser if property throwException is set.
Xml importer class.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
Import xml representation.
$log
Definition: result.php:15
$DIC
Definition: xapitoken.php:46