ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilContainerXmlParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Export/classes/class.ilExportOptions.php';
5
15{
19 protected $settings;
20
24 protected $obj_definition;
25
29 protected $cont_log;
30
31 private $source = 0;
32 private $mapping = null;
33 private $xml = '';
34
35 private $sxml = null;
36 private $root_id = 0;
37
38 public static $style_map = array();
39
44 {
45 global $DIC;
46
47 $this->settings = $DIC->settings();
48 $this->obj_definition = $DIC["objDefinition"];
49 $this->mapping = $mapping;
50 $this->xml = $xml;
51 $this->cont_log = ilLoggerFactory::getLogger('cont');
52 }
53
59 public function getMapping()
60 {
61 return $this->mapping;
62 }
63
64 public function parse($a_root_id)
65 {
66 $this->sxml = simplexml_load_string($this->xml);
67 $this->root_id = $a_root_id;
68
69 foreach ($this->sxml->Item as $item) {
70 $this->initItem($item, $this->mapping->getTargetId());
71 }
72 }
73
80 protected function initItem($item, $a_parent_node)
81 {
83
84 $title = (string) $item['Title'];
85 $ref_id = (string) $item['RefId'];
86 $obj_id = (string) $item['Id'];
87 $type = (string) $item['Type'];
88
89
90 $new_ref = $this->getMapping()->getMapping('Services/Container', 'refs', $ref_id);
91
92 if (
93 !$new_ref &&
94 ($obj_id == $this->root_id)
95 ) {
96 // if container without subitems a dummy container has already been created
97 // see ilImportContainer::createDummy()
98 $new_ref = $this->mapping->getMapping('Services/Container', 'refs', 0);
99
100 // see below and ilContainerImporter::finalProcessing()
101 $this->mapping->addMapping('Services/Container', 'objs', $obj_id, ilObject::_lookupObjId($new_ref));
102 }
103
104 if (!$new_ref) {
105 $new_ref = $this->createObject($ref_id, $obj_id, $type, $title, $a_parent_node);
106 }
107 if (!$new_ref) {
108 // e.g inactive plugin
109 return;
110 }
111
112 // Course item information
113 foreach ($item->Timing as $timing) {
114 $this->parseTiming($new_ref, $a_parent_node, $timing);
115 }
116
117 foreach ($item->Item as $subitem) {
118 $this->initItem($subitem, $new_ref);
119 }
120
121 $new_obj_id = $this->mapping->getMapping('Services/Container', 'objs', $obj_id);
122
123 // style
124 if ((int) $item['Style']) {
125 self::$style_map[(int) $item['Style']][] = $new_obj_id;
126 }
127
128 // pages
129 if ($ilSetting->get('enable_cat_page_edit', false)) {
130 if ($item['Page'] == "1") {
131 $this->mapping->addMapping('Services/COPage', 'pg', 'cont:' . $obj_id, 'cont:' . $new_obj_id);
132 $this->cont_log->debug("add pg cont mapping, old: " . $obj_id . ", new: " . $new_obj_id . ", Page: -" . $item['Page'] . "-");
133 }
134
135 if ($item['StartPage'] == "1") {
136 $this->mapping->addMapping('Services/COPage', 'pg', 'cstr:' . $obj_id, 'cstr:' . $new_obj_id);
137 }
138 }
139 }
140
148 protected function parseTiming($a_ref_id, $a_parent_id, $timing)
149 {
150 $type = (string) $timing['Type'];
151 $visible = (string) $timing['Visible'];
152 $changeable = (string) $timing['Changeable'];
153
154 include_once './Services/Object/classes/class.ilObjectActivation.php';
155 $crs_item = new ilObjectActivation();
156 $crs_item->setTimingType($type);
157 $crs_item->toggleVisible((bool) $visible);
158 $crs_item->toggleChangeable((bool) $changeable);
159
160 foreach ($timing->children() as $sub) {
161 switch ((string) $sub->getName()) {
162 case 'Start':
163 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
164 $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
165 break;
166
167 case 'End':
168 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
169 $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
170 break;
171
172 case 'SuggestionStart':
173 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
174 $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
175 break;
176
177 case 'SuggestionEnd':
178 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
179 $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
180 break;
181
182 case 'EarliestStart':
183 $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
184 $crs_item->setEarliestStart($dt->get(IL_CAL_UNIX));
185 break;
186
187 case 'LatestEnd':
188 break;
189 }
190 }
191
192
193 if ($crs_item->getTimingStart()) {
194 $crs_item->update($a_ref_id, $a_parent_id);
195 }
196 }
197
207 protected function createObject($ref_id, $obj_id, $type, $title, $parent_node) :? int
208 {
209 $objDefinition = $this->obj_definition;
210
211 // A mapping for this object already exists => create reference
212 $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
213 if ($new_obj_id) {
214 include_once './Services/Object/classes/class.ilObjectFactory.php';
215 $obj = ilObjectFactory::getInstanceByObjId($new_obj_id, false);
216 if ($obj instanceof ilObject) {
217 $obj->createReference();
218 $obj->putInTree($parent_node);
219 $obj->setPermissions($parent_node);
220 $this->mapping->addMapping('Services/Container', 'refs', $ref_id, $obj->getRefId());
221 return $obj->getRefId();
222 }
223 }
224
225 if (!$objDefinition->isAllowedInRepository($type) || $objDefinition->isInactivePlugin($type)) {
226 $this->cont_log->notice('Cannot import object of type: ' . $type);
227 return null;
228 }
229
230 $class_name = "ilObj" . $objDefinition->getClassName($type);
231 $location = $objDefinition->getLocation($type);
232
233 include_once($location . "/class." . $class_name . ".php");
234 $new = new $class_name();
235 $new->setTitle($title);
236 $new->create(true);
237 $new->createReference();
238 $new->putInTree($parent_node);
239 $new->setPermissions($parent_node);
240
241 $this->mapping->addMapping('Services/Container', 'objs', $obj_id, $new->getId());
242 $this->mapping->addMapping('Services/Container', 'refs', $ref_id, $new->getRefId());
243
244 return $new->getRefId();
245 }
246}
$location
Definition: buildRTE.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
XML parser for container structure.
initItem($item, $a_parent_node)
Init Item.
__construct(ilImportMapping $mapping, $xml='')
Constructor.
parseTiming($a_ref_id, $a_parent_id, $timing)
Parse timing info.
createObject($ref_id, $obj_id, $type, $title, $parent_node)
Create the objects.
getMapping()
Get ilImportMapping object.
@classDescription Date and time handling
static getLogger($a_component_id)
Get component logger.
Class ilObjectActivation.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObject Basic functions for all objects.
static _lookupObjId($a_id)
global $ilSetting
Definition: privfeed.php:17
$type
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46