ILIAS  Release_4_1_x_branch Revision 61804
 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 './Modules/Course/classes/class.ilCourseItems.php';
92  $crs_items = new ilCourseItems($a_parent_id,$a_parent_id);
93  $crs_items->setTimingType($type);
94  $crs_items->toggleVisible((bool) $visible);
95  $crs_items->toggleChangeable((bool) $changeable);
96  $crs_items->setItemId($a_ref_id);
97 
98  foreach($timing->children() as $sub)
99  {
100  switch((string) $sub->getName())
101  {
102  case 'Start':
103  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
104  $crs_items->setTimingStart($dt->get(IL_CAL_UNIX));
105  break;
106 
107  case 'End':
108  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
109  $crs_items->setTimingEnd($dt->get(IL_CAL_UNIX));
110  break;
111 
112  case 'SuggestionStart':
113  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
114  $crs_items->setSuggestionStart($dt->get(IL_CAL_UNIX));
115  break;
116 
117  case 'SuggestionEnd':
118  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
119  $crs_items->setSuggestionEnd($dt->get(IL_CAL_UNIX));
120  break;
121 
122  case 'EarliestStart':
123  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
124  $crs_items->setEarliestStart($dt->get(IL_CAL_UNIX));
125  break;
126 
127  case 'LatestEnd':
128  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
129  $crs_items->setLatestEnd($dt->get(IL_CAL_UNIX));
130  break;
131  }
132  }
133 
134 
135  if($crs_items->getTimingStart())
136  {
137  $crs_items->update($a_ref_id);
138  }
139  }
140 
150  protected function createObject($ref_id,$obj_id,$type,$title,$parent_node)
151  {
152  global $objDefinition;
153 
154  // A mapping for this object already exists => create reference
155  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
156  if($new_obj_id)
157  {
158  include_once './classes/class.ilObjectFactory.php';
159  $obj = ilObjectFactory::getInstanceByObjId($new_obj_id,false);
160  if($obj instanceof ilObject)
161  {
162  $obj->createReference();
163  $obj->putInTree($parent_node);
164  $obj->setPermissions($parent_node);
165  $this->mapping->addMapping('Services/Container','refs',$ref_id,$obj->getRefId());
166  return $obj->getRefId();
167  }
168  }
169 
170  $class_name = "ilObj".$objDefinition->getClassName($type);
171  $location = $objDefinition->getLocation($type);
172 
173  include_once($location."/class.".$class_name.".php");
174  $new = new $class_name();
175  $new->setTitle($title);
176  $new->create(true);
177  $new->createReference();
178  $new->putInTree($parent_node);
179  $new->setPermissions($parent_node);
180 
181  $this->mapping->addMapping('Services/Container','objs', $obj_id, $new->getId());
182  $this->mapping->addMapping('Services/Container','refs',$ref_id,$new->getRefId());
183 
184  if($type == 'svy')
185  {
186  $pool = $this->createSurveyPool($title,$parent_node);
187  $this->mapping->addMapping('Services/Container', 'spl', $new->getId(), $pool->getRefId());
188  }
189 
190  return $new->getRefId();
191  }
192 
199  protected function createSurveyPool($title,$parent_node)
200  {
201  global $objDefinition;
202 
203  $class_name = "ilObj".$objDefinition->getClassName('spl');
204  $location = $objDefinition->getLocation('spl');
205 
206  include_once($location."/class.".$class_name.".php");
207  $new = new $class_name();
208  $new->setTitle($title);
209  $new->create(true);
210  $new->createReference();
211  $new->putInTree($parent_node);
212  $new->setPermissions($parent_node);
213 
214  return $new;
215  }
216 }
217 ?>