ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContainerReferenceImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 protected ?ilContainerReference $ref = null;
29
30 public function init(): void
31 {
32 }
33
34 protected function initReference(int $a_ref_id = 0): void
35 {
38 $this->ref = $ref;
39 }
40
44 abstract protected function getType(): string;
45
46 abstract protected function initParser(string $a_xml): ilContainerReferenceXmlParser;
47
48 protected function getReference(): ilContainerReference
49 {
50 return $this->ref;
51 }
52
53 public function importXmlRepresentation(
54 string $a_entity,
55 string $a_id,
56 string $a_xml,
57 ilImportMapping $a_mapping
58 ): void {
59 global $DIC;
60
61 $objDefinition = $DIC["objDefinition"];
62 $log = $DIC->logger()->root();
63
64 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
65 $refs = ilObject::_getAllReferences((int) $new_id);
66 $this->initReference(end($refs));
67 }
68 // Mapping for containers without subitems
69 elseif ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'refs', '0')) {
70 $this->initReference((int) $new_id);
71 } elseif (!$this->getReference() instanceof ilContainerReference) {
72 $this->initReference();
73 $this->getReference()->create();
74 }
75
76 try {
78 $parser = $this->initParser($a_xml);
79 $parser->setImportMapping($a_mapping);
80 $parser->setReference($this->getReference());
82 $parser->startParsing();
83
84 $a_mapping->addMapping(
85 $objDefinition->getComponentForType($this->getType()),
86 $this->getType(),
87 $a_id,
88 (string) $this->getReference()->getId()
89 );
90 } catch (ilSaxParserException | Exception $e) {
91 $log->error(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
92 }
93 }
94}
getType()
Get reference type.
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Xml importer class.
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
$log
Definition: ltiresult.php:34
global $DIC
Definition: shib_login.php:26