ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_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 
43  public function __construct(ilImportMapping $mapping, $xml = '')
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 
108  // Course item information
109  foreach ($item->Timing as $timing) {
110  $this->parseTiming($new_ref, $a_parent_node, $timing);
111  }
112 
113  foreach ($item->Item as $subitem) {
114  $this->initItem($subitem, $new_ref);
115  }
116 
117  $new_obj_id = $this->mapping->getMapping('Services/Container', 'objs', $obj_id);
118 
119  // style
120  if ((int) $item['Style']) {
121  self::$style_map[(int) $item['Style']][] = $new_obj_id;
122  }
123 
124  // pages
125  if ($ilSetting->get('enable_cat_page_edit', false)) {
126  if ($item['Page'] == "1") {
127  $this->mapping->addMapping('Services/COPage', 'pg', 'cont:' . $obj_id, 'cont:' . $new_obj_id);
128  $this->cont_log->debug("add pg cont mapping, old: " . $obj_id . ", new: " . $new_obj_id . ", Page: -" . $item['Page'] . "-");
129  }
130 
131  if ($item['StartPage'] == "1") {
132  $this->mapping->addMapping('Services/COPage', 'pg', 'cstr:' . $obj_id, 'cstr:' . $new_obj_id);
133  }
134  }
135  }
136 
144  protected function parseTiming($a_ref_id, $a_parent_id, $timing)
145  {
146  $type = (string) $timing['Type'];
147  $visible = (string) $timing['Visible'];
148  $changeable = (string) $timing['Changeable'];
149 
150  include_once './Services/Object/classes/class.ilObjectActivation.php';
151  $crs_item = new ilObjectActivation();
152  $crs_item->setTimingType($type);
153  $crs_item->toggleVisible((bool) $visible);
154  $crs_item->toggleChangeable((bool) $changeable);
155 
156  foreach ($timing->children() as $sub) {
157  switch ((string) $sub->getName()) {
158  case 'Start':
159  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
160  $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
161  break;
162 
163  case 'End':
164  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
165  $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
166  break;
167 
168  case 'SuggestionStart':
169  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
170  $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
171  break;
172 
173  case 'SuggestionEnd':
174  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
175  $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
176  break;
177 
178  case 'EarliestStart':
179  $dt = new ilDateTime((string) $sub, IL_CAL_DATETIME, ilTimeZone::UTC);
180  $crs_item->setEarliestStart($dt->get(IL_CAL_UNIX));
181  break;
182 
183  case 'LatestEnd':
184  break;
185  }
186  }
187 
188 
189  if ($crs_item->getTimingStart()) {
190  $crs_item->update($a_ref_id, $a_parent_id);
191  }
192  }
193 
203  protected function createObject($ref_id, $obj_id, $type, $title, $parent_node)
204  {
205  $objDefinition = $this->obj_definition;
206 
207  // A mapping for this object already exists => create reference
208  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
209  if ($new_obj_id) {
210  include_once './Services/Object/classes/class.ilObjectFactory.php';
211  $obj = ilObjectFactory::getInstanceByObjId($new_obj_id, false);
212  if ($obj instanceof ilObject) {
213  $obj->createReference();
214  $obj->putInTree($parent_node);
215  $obj->setPermissions($parent_node);
216  $this->mapping->addMapping('Services/Container', 'refs', $ref_id, $obj->getRefId());
217  return $obj->getRefId();
218  }
219  }
220 
221  $class_name = "ilObj" . $objDefinition->getClassName($type);
222  $location = $objDefinition->getLocation($type);
223 
224  include_once($location . "/class." . $class_name . ".php");
225  $new = new $class_name();
226  $new->setTitle($title);
227  $new->create(true);
228  $new->createReference();
229  $new->putInTree($parent_node);
230  $new->setPermissions($parent_node);
231 
232  $this->mapping->addMapping('Services/Container', 'objs', $obj_id, $new->getId());
233  $this->mapping->addMapping('Services/Container', 'refs', $ref_id, $new->getRefId());
234 
235  return $new->getRefId();
236  }
237 }
settings()
Definition: settings.php:2
initItem($item, $a_parent_node)
Init Item.
const IL_CAL_DATETIME
__construct(ilImportMapping $mapping, $xml='')
Constructor.
$type
global $DIC
Definition: saml.php:7
$location
Definition: buildRTE.php:44
getMapping()
Get ilImportMapping object.
const IL_CAL_UNIX
static _lookupObjId($a_id)
createObject($ref_id, $obj_id, $type, $title, $parent_node)
Create the objects.
Date and time handling
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
parseTiming($a_ref_id, $a_parent_id, $timing)
Parse timing info.
global $ilSetting
Definition: privfeed.php:17
XML parser for container structure.
static getLogger($a_component_id)
Get component logger.
Class ilObjectActivation.