ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
16  private $source = 0;
17  private $mapping = null;
18  private $xml = '';
19 
20  private $sxml = null;
21  private $root_id = 0;
22 
23  static public $style_map = array();
24 
28  public function __construct(ilImportMapping $mapping,$xml = '')
29  {
30  $this->mapping = $mapping;
31  $this->xml = $xml;
32  }
33 
39  public function getMapping()
40  {
41  return $this->mapping;
42  }
43 
44  public function parse($a_root_id)
45  {
46  $this->sxml = simplexml_load_string($this->xml);
47  $this->root_id = $a_root_id;
48 
49  foreach($this->sxml->Item as $item)
50  {
51  $this->initItem($item,$this->mapping->getTargetId());
52  }
53  }
54 
61  protected function initItem($item, $a_parent_node)
62  {
63  global $ilSetting;
64 
65  $title = (string) $item['Title'];
66  $ref_id = (string) $item['RefId'];
67  $obj_id = (string) $item['Id'];
68  $type = (string) $item['Type'];
69 
70 
71  $new_ref = $this->getMapping()->getMapping('Services/Container', 'refs', $ref_id);
72 
73  if(
74  !$new_ref &&
75  ($obj_id == $this->root_id)
76  )
77  {
78  // if container without subitems a dummy container has already been created
79  // see ilImportContainer::createDummy()
80  $new_ref = $this->mapping->getMapping('Services/Container', 'refs', 0);
81 
82  // see below and ilContainerImporter::finalProcessing()
83  $this->mapping->addMapping('Services/Container','objs', $obj_id, ilObject::_lookupObjId($new_ref));
84  }
85 
86  if(!$new_ref)
87  {
88  $new_ref = $this->createObject($ref_id,$obj_id,$type,$title,$a_parent_node);
89  }
90 
91  // Course item information
92  foreach($item->Timing as $timing)
93  {
94  $this->parseTiming($new_ref,$a_parent_node,$timing);
95  }
96 
97  foreach($item->Item as $subitem)
98  {
99  $this->initItem($subitem, $new_ref);
100  }
101 
102  $new_obj_id = $this->mapping->getMapping('Services/Container', 'objs', $obj_id);
103 
104  // style
105  if((int)$item['Style'])
106  {
107  self::$style_map[(int)$item['Style']][] = $new_obj_id;
108  }
109 
110  // pages
111  if($ilSetting->get('enable_cat_page_edit', false))
112  {
113  if((bool)$item['Page'])
114  {
115  $this->mapping->addMapping('Services/COPage', 'pg', 'cont:'.$obj_id, 'cont:'.$new_obj_id);
116  }
117 
118  if((bool)$item['StartPage'])
119  {
120  $this->mapping->addMapping('Services/COPage', 'pg', 'cstr:'.$obj_id, 'cstr:'.$new_obj_id);
121  }
122  }
123  }
124 
132  protected function parseTiming($a_ref_id,$a_parent_id,$timing)
133  {
134  $type = (string) $timing['Type'];
135  $visible = (string) $timing['Visible'];
136  $changeable = (string) $timing['Changeable'];
137 
138  include_once './Services/Object/classes/class.ilObjectActivation.php';
139  $crs_item = new ilObjectActivation();
140  $crs_item->setTimingType($type);
141  $crs_item->toggleVisible((bool) $visible);
142  $crs_item->toggleChangeable((bool) $changeable);
143 
144  foreach($timing->children() as $sub)
145  {
146  switch((string) $sub->getName())
147  {
148  case 'Start':
149  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
150  $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
151  break;
152 
153  case 'End':
154  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
155  $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
156  break;
157 
158  case 'SuggestionStart':
159  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
160  $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
161  break;
162 
163  case 'SuggestionEnd':
164  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
165  $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
166  break;
167 
168  case 'EarliestStart':
169  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
170  $crs_item->setEarliestStart($dt->get(IL_CAL_UNIX));
171  break;
172 
173  case 'LatestEnd':
174  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
175  $crs_item->setLatestEnd($dt->get(IL_CAL_UNIX));
176  break;
177  }
178  }
179 
180 
181  if($crs_item->getTimingStart())
182  {
183  $crs_item->update($a_ref_id, $a_parent_id);
184  }
185  }
186 
196  protected function createObject($ref_id,$obj_id,$type,$title,$parent_node)
197  {
198  global $objDefinition;
199 
200  // A mapping for this object already exists => create reference
201  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
202  if($new_obj_id)
203  {
204  include_once './Services/Object/classes/class.ilObjectFactory.php';
205  $obj = ilObjectFactory::getInstanceByObjId($new_obj_id,false);
206  if($obj instanceof ilObject)
207  {
208  $obj->createReference();
209  $obj->putInTree($parent_node);
210  $obj->setPermissions($parent_node);
211  $this->mapping->addMapping('Services/Container','refs',$ref_id,$obj->getRefId());
212  return $obj->getRefId();
213  }
214  }
215 
216  $class_name = "ilObj".$objDefinition->getClassName($type);
217  $location = $objDefinition->getLocation($type);
218 
219  include_once($location."/class.".$class_name.".php");
220  $new = new $class_name();
221  $new->setTitle($title);
222  $new->create(true);
223  $new->createReference();
224  $new->putInTree($parent_node);
225  $new->setPermissions($parent_node);
226 
227  $this->mapping->addMapping('Services/Container','objs', $obj_id, $new->getId());
228  $this->mapping->addMapping('Services/Container','refs',$ref_id,$new->getRefId());
229 
230  return $new->getRefId();
231  }
232 }
233 ?>
initItem($item, $a_parent_node)
Init Item.
const IL_CAL_DATETIME
__construct(ilImportMapping $mapping, $xml='')
Constructor.
$location
Definition: buildRTE.php:44
Class ilObject Basic functions for all objects.
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
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.
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:40
XML parser for container structure.
Class ilObjectActivation.