ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
25  public function __construct(ilImportMapping $mapping,$xml = '')
26  {
27  $this->mapping = $mapping;
28  $this->xml = $xml;
29  }
30 
36  public function getMapping()
37  {
38  return $this->mapping;
39  }
40 
41  public function parse()
42  {
43  $this->sxml = simplexml_load_string($this->xml);
44 
45  foreach($this->sxml->Item as $item)
46  {
47  $this->initItem($item,$this->mapping->getTargetId());
48  }
49  }
50 
57  protected function initItem($item, $a_parent_node)
58  {
59  $title = (string) $item['Title'];
60  $ref_id = (string) $item['RefId'];
61  $obj_id = (string) $item['Id'];
62  $type = (string) $item['Type'];
63 
64  $new_ref = $this->createObject($ref_id,$obj_id,$type,$title,$a_parent_node);
65 
66  // Course item information
67  foreach($item->Timing as $timing)
68  {
69  $this->parseTiming($new_ref,$a_parent_node,$timing);
70  }
71 
72  foreach($item->Item as $subitem)
73  {
74  $this->initItem($subitem, $new_ref);
75  }
76  }
77 
85  protected function parseTiming($a_ref_id,$a_parent_id,$timing)
86  {
87  $type = (string) $timing['Type'];
88  $visible = (string) $timing['Visible'];
89  $changeable = (string) $timing['Changeable'];
90 
91  include_once './Services/Object/classes/class.ilObjectActivation.php';
92  $crs_item = new ilObjectActivation();
93  $crs_item->setTimingType($type);
94  $crs_item->toggleVisible((bool) $visible);
95  $crs_item->toggleChangeable((bool) $changeable);
96 
97  foreach($timing->children() as $sub)
98  {
99  switch((string) $sub->getName())
100  {
101  case 'Start':
102  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
103  $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
104  break;
105 
106  case 'End':
107  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
108  $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
109  break;
110 
111  case 'SuggestionStart':
112  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
113  $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
114  break;
115 
116  case 'SuggestionEnd':
117  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
118  $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
119  break;
120 
121  case 'EarliestStart':
122  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
123  $crs_item->setEarliestStart($dt->get(IL_CAL_UNIX));
124  break;
125 
126  case 'LatestEnd':
127  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
128  $crs_item->setLatestEnd($dt->get(IL_CAL_UNIX));
129  break;
130  }
131  }
132 
133 
134  if($crs_item->getTimingStart())
135  {
136  $crs_item->update($a_ref_id, $a_parent_id);
137  }
138  }
139 
149  protected function createObject($ref_id,$obj_id,$type,$title,$parent_node)
150  {
151  global $objDefinition;
152 
153  // A mapping for this object already exists => create reference
154  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
155  if($new_obj_id)
156  {
157  include_once './Services/Object/classes/class.ilObjectFactory.php';
158  $obj = ilObjectFactory::getInstanceByObjId($new_obj_id,false);
159  if($obj instanceof ilObject)
160  {
161  $obj->createReference();
162  $obj->putInTree($parent_node);
163  $obj->setPermissions($parent_node);
164  $this->mapping->addMapping('Services/Container','refs',$ref_id,$obj->getRefId());
165  return $obj->getRefId();
166  }
167  }
168 
169  $class_name = "ilObj".$objDefinition->getClassName($type);
170  $location = $objDefinition->getLocation($type);
171 
172  include_once($location."/class.".$class_name.".php");
173  $new = new $class_name();
174  $new->setTitle($title);
175  $new->create(true);
176  $new->createReference();
177  $new->putInTree($parent_node);
178  $new->setPermissions($parent_node);
179 
180  $this->mapping->addMapping('Services/Container','objs', $obj_id, $new->getId());
181  $this->mapping->addMapping('Services/Container','refs',$ref_id,$new->getRefId());
182 
183  return $new->getRefId();
184  }
185 }
186 ?>