ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilContainerXmlParser.php
Go to the documentation of this file.
1<?php
2
25{
29 private int $source = 0;
30 private ?ilImportMapping $mapping = null;
31 private string $xml = '';
32 private int $root_id = 0;
33 public static array $style_map = [];
34
35 public function __construct(
37 string $xml = ''
38 ) {
39 global $DIC;
40
41 $this->settings = $DIC->settings();
42 $this->obj_definition = $DIC["objDefinition"];
43 $this->mapping = $mapping;
44 $this->xml = $xml;
45 $this->cont_log = ilLoggerFactory::getLogger('cont');
46 }
47
48 public function getMapping(): ?ilImportMapping
49 {
50 return $this->mapping;
51 }
52
53 public function parse(string $a_root_id): void
54 {
55 $sxml = simplexml_load_string($this->xml);
56 $this->root_id = (int) $a_root_id;
57 foreach ($sxml->Item as $item) {
58 $this->initItem($item, $this->mapping->getTargetId());
59 }
60 }
61
62 protected function initItem(
63 SimpleXMLElement $item,
64 int $a_parent_node
65 ): void {
66 $ilSetting = $this->settings;
67
68 $title = (string) $item['Title'];
69 $ref_id = (string) $item['RefId'];
70 $obj_id = (string) $item['Id'];
71 $type = (string) $item['Type'];
72
73
74 $new_ref = $this->getMapping()->getMapping('components/ILIAS/Container', 'refs', $ref_id);
75
76 if (
77 !$new_ref &&
78 ($obj_id == $this->root_id)
79 ) {
80 // if container without subitems a dummy container has already been created
81 // see ilImportContainer::createDummy()
82 $new_ref = $this->mapping->getMapping('components/ILIAS/Container', 'refs', '0');
83
84 // see below and ilContainerImporter::finalProcessing()
85 $this->mapping->addMapping('components/ILIAS/Container', 'objs', $obj_id, (string) ilObject::_lookupObjId((int) $new_ref));
86 $this->mapping->addMapping('components/ILIAS/ILIASObject', 'obj', $obj_id, (string) ilObject::_lookupObjId((int) $new_ref));
87 }
88
89 if (!$new_ref) {
90 $new_ref = $this->createObject((int) $ref_id, (int) $obj_id, $type, $title, $a_parent_node);
91 }
92 if (!$new_ref) {
93 // e.g inactive plugin
94 return;
95 }
96
97 // Course item information
98 foreach ($item->Timing as $timing) {
99 $this->parseTiming($new_ref, $a_parent_node, $timing);
100 }
101
102 foreach ($item->Item as $subitem) {
103 $this->initItem($subitem, $new_ref);
104 }
105
106 $new_obj_id = $this->mapping->getMapping('components/ILIAS/Container', 'objs', $obj_id);
107
108 // style
109 if ((int) $item['Style']) {
110 self::$style_map[(int) $item['Style']][] = $new_obj_id;
111 }
112
113 // pages
114 if ($ilSetting->get('enable_cat_page_edit', '0')) {
115 if ($item['Page'] == "1") {
116 $this->mapping->addMapping('components/ILIAS/COPage', 'pg', 'cont:' . $obj_id, 'cont:' . $new_obj_id);
117 $this->cont_log->debug("add pg cont mapping, old: " . $obj_id . ", new: " . $new_obj_id . ", Page: -" . $item['Page'] . "-");
118 }
119
120 if ($item['StartPage'] == "1") {
121 $this->mapping->addMapping('components/ILIAS/COPage', 'pg', 'cstr:' . $obj_id, 'cstr:' . $new_obj_id);
122 }
123 }
124 }
125
126 // Parse timing info
127 protected function parseTiming(
128 int $a_ref_id,
129 int $a_parent_id,
130 SimpleXMLElement $timing
131 ): void {
132 $type = (string) $timing['Type'];
133 $visible = (string) $timing['Visible'];
134 $changeable = (string) $timing['Changeable'];
135
136 $crs_item = new ilObjectActivation();
137 $crs_item->setTimingType((int) $type);
138 $crs_item->toggleVisible((bool) $visible);
139 $crs_item->toggleChangeable((bool) $changeable);
140
141 foreach ($timing->children() as $sub) {
142 switch ($sub->getName()) {
143 case 'Start':
144 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
145 $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
146 break;
147
148 case 'End':
149 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
150 $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
151 break;
152
153 case 'SuggestionStart':
154 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
155 $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
156 break;
157
158 case 'SuggestionEnd':
159 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
160 $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
161 break;
162
163 case 'LatestEnd':
164 break;
165 }
166 }
167
168
169 if ($crs_item->getTimingStart()) {
170 $crs_item->update($a_ref_id, $a_parent_id);
171 }
172 }
173
174 protected function createObject(
175 int $ref_id,
176 int $obj_id,
177 string $type,
178 string $title,
179 int $parent_node
180 ): ?int {
181 $objDefinition = $this->obj_definition;
182
183 // A mapping for this object already exists => create reference
184 $new_obj_id = $this->getMapping()->getMapping('components/ILIAS/Container', 'objs', (string) $obj_id);
185 if ($new_obj_id) {
186 $obj = ilObjectFactory::getInstanceByObjId((int) $new_obj_id, false);
187 if ($obj instanceof ilObject) {
188 $obj->createReference();
189 $obj->putInTree($parent_node);
190 $obj->setPermissions($parent_node);
191 $this->mapping->addMapping('components/ILIAS/Container', 'refs', (string) $ref_id, (string) $obj->getRefId());
192 return $obj->getRefId();
193 }
194 }
195
196 if (!$objDefinition->isAllowedInRepository($type) || $objDefinition->isInactivePlugin($type)) {
197 $this->cont_log->notice('Cannot import object of type: ' . $type);
198 return null;
199 }
200
201 $class_name = "ilObj" . $objDefinition->getClassName($type);
202 $location = $objDefinition->getLocation($type);
203
204 $new = new $class_name();
205 $new->setTitle($title);
206 $new->create(true);
207 $new->createReference();
208 $new->putInTree($parent_node);
209 $new->setPermissions($parent_node);
210
211 $this->mapping->addMapping('components/ILIAS/Container', 'objs', (string) $obj_id, (string) $new->getId());
212 $this->mapping->addMapping('components/ILIAS/ILIASObject', 'obj', (string) $obj_id, (string) $new->getId());
213 $this->mapping->addMapping('components/ILIAS/Container', 'refs', (string) $ref_id, (string) $new->getRefId());
214
215 return $new->getRefId();
216 }
217}
$location
Definition: buildRTE.php:22
const IL_CAL_UNIX
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initItem(SimpleXMLElement $item, int $a_parent_node)
__construct(ilImportMapping $mapping, string $xml='')
parseTiming(int $a_ref_id, int $a_parent_id, SimpleXMLElement $timing)
createObject(int $ref_id, int $obj_id, string $type, string $title, int $parent_node)
ilObjectDefinition $obj_definition
@classDescription Date and time handling
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Class ilObjectActivation.
parses the objects.xml it handles the xml-description of all ilias objects
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObject Basic functions for all objects.
static _lookupObjId(int $ref_id)
ILIAS Setting Class.
$ref_id
Definition: ltiauth.php:66
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26