ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCategoryImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private ?ilObject $category = null;
29
30 public function init(): void
31 {
32 }
33
38 public function importXmlRepresentation(
39 string $a_entity,
40 string $a_id,
41 string $a_xml,
42 ilImportMapping $a_mapping
43 ): void {
44 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
45 $refs = ilObject::_getAllReferences((int) $new_id);
46 $this->category = ilObjectFactory::getInstanceByRefId(end($refs), false);
47 }
48 // Mapping for containers without subitems
49 elseif ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'refs', '0')) {
50 $this->category = ilObjectFactory::getInstanceByRefId((int) $new_id, false);
51 } elseif (!$this->category instanceof ilObjCategory) {
52 $this->category = new ilObjCategory();
53 $this->category->create();
54 }
55
56 try {
57 $parser = new ilCategoryXmlParser($a_xml, 0);
58 $parser->setCategory($this->category);
59 $parser->setMode(ilCategoryXmlParser::MODE_UPDATE);
60 $parser->startParsing();
61 $a_mapping->addMapping('components/ILIAS/Category', 'cat', $a_id, (string) $this->category->getId());
62 } catch (ilSaxParserException | Exception $e) {
63 $GLOBALS['ilLog']->write(__METHOD__ . ': Parsing failed with message, "' . $e->getMessage() . '".');
64 }
65
66 foreach ($a_mapping->getMappingsOfEntity('components/ILIAS/Container', 'objs') as $old => $new) {
67 $type = ilObject::_lookupType((int) $new);
68
69 // see ilGlossaryImporter::importXmlRepresentation()
70 // see ilTaxonomyDataSet::importRecord()
71
72 $a_mapping->addMapping(
73 "components/ILIAS/Taxonomy",
74 "tax_item",
75 $type . ":obj:" . $old,
76 $new
77 );
78
79 // this is since 4.3 does not export these ids but 4.4 tax node assignment needs it
80 $a_mapping->addMapping(
81 "components/ILIAS/Taxonomy",
82 "tax_item_obj_id",
83 $type . ":obj:" . $old,
84 $new
85 );
86 }
87 }
88
89 public function finalProcessing(
90 ilImportMapping $a_mapping
91 ): void {
92 $maps = $a_mapping->getMappingsOfEntity("components/ILIAS/Category", "cat");
93 foreach ($maps as $old => $new) {
94 if ($old !== "new_id" && (int) $old > 0) {
95 // get all new taxonomys of this object
96 $new_tax_ids = $a_mapping->getMapping("components/ILIAS/Taxonomy", "tax_usage_of_obj", (string) $old);
97 $tax_ids = explode(":", (string) $new_tax_ids);
98 foreach ($tax_ids as $tid) {
99 ilObjTaxonomy::saveUsage((int) $tid, (int) $new);
100 }
101 }
102 }
103 }
104}
finalProcessing(ilImportMapping $a_mapping)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
Class ilObjCategory.
static saveUsage(int $a_tax_id, int $a_obj_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
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.
if(!file_exists('../ilias.ini.php'))
$GLOBALS["DIC"]
Definition: wac.php:54