ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
20  protected $cont_log;
21 
22  private $source = 0;
23  private $mapping = null;
24  private $xml = '';
25 
26  private $sxml = null;
27  private $root_id = 0;
28 
29  static public $style_map = array();
30 
34  public function __construct(ilImportMapping $mapping,$xml = '')
35  {
36  $this->mapping = $mapping;
37  $this->xml = $xml;
38  $this->cont_log = ilLoggerFactory::getLogger('cont');
39  }
40 
46  public function getMapping()
47  {
48  return $this->mapping;
49  }
50 
51  public function parse($a_root_id)
52  {
53  $this->sxml = simplexml_load_string($this->xml);
54  $this->root_id = $a_root_id;
55 
56  foreach($this->sxml->Item as $item)
57  {
58  $this->initItem($item,$this->mapping->getTargetId());
59  }
60  }
61 
68  protected function initItem($item, $a_parent_node)
69  {
70  global $ilSetting;
71 
72  $title = (string) $item['Title'];
73  $ref_id = (string) $item['RefId'];
74  $obj_id = (string) $item['Id'];
75  $type = (string) $item['Type'];
76 
77 
78  $new_ref = $this->getMapping()->getMapping('Services/Container', 'refs', $ref_id);
79 
80  if(
81  !$new_ref &&
82  ($obj_id == $this->root_id)
83  )
84  {
85  // if container without subitems a dummy container has already been created
86  // see ilImportContainer::createDummy()
87  $new_ref = $this->mapping->getMapping('Services/Container', 'refs', 0);
88 
89  // see below and ilContainerImporter::finalProcessing()
90  $this->mapping->addMapping('Services/Container','objs', $obj_id, ilObject::_lookupObjId($new_ref));
91  }
92 
93  if(!$new_ref)
94  {
95  $new_ref = $this->createObject($ref_id,$obj_id,$type,$title,$a_parent_node);
96  }
97 
98  // Course item information
99  foreach($item->Timing as $timing)
100  {
101  $this->parseTiming($new_ref,$a_parent_node,$timing);
102  }
103 
104  foreach($item->Item as $subitem)
105  {
106  $this->initItem($subitem, $new_ref);
107  }
108 
109  $new_obj_id = $this->mapping->getMapping('Services/Container', 'objs', $obj_id);
110 
111  // style
112  if((int)$item['Style'])
113  {
114  self::$style_map[(int)$item['Style']][] = $new_obj_id;
115  }
116 
117  // pages
118  if($ilSetting->get('enable_cat_page_edit', false))
119  {
120  if($item['Page'] == "1")
121  {
122  $this->mapping->addMapping('Services/COPage', 'pg', 'cont:'.$obj_id, 'cont:'.$new_obj_id);
123  $this->cont_log->debug("add pg cont mapping, old: ".$obj_id.", new: ".$new_obj_id.", Page: -".$item['Page']."-");
124  }
125 
126  if($item['StartPage'] == "1")
127  {
128  $this->mapping->addMapping('Services/COPage', 'pg', 'cstr:'.$obj_id, 'cstr:'.$new_obj_id);
129  }
130  }
131  }
132 
140  protected function parseTiming($a_ref_id,$a_parent_id,$timing)
141  {
142  $type = (string) $timing['Type'];
143  $visible = (string) $timing['Visible'];
144  $changeable = (string) $timing['Changeable'];
145 
146  include_once './Services/Object/classes/class.ilObjectActivation.php';
147  $crs_item = new ilObjectActivation();
148  $crs_item->setTimingType($type);
149  $crs_item->toggleVisible((bool) $visible);
150  $crs_item->toggleChangeable((bool) $changeable);
151 
152  foreach($timing->children() as $sub)
153  {
154  switch((string) $sub->getName())
155  {
156  case 'Start':
157  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
158  $crs_item->setTimingStart($dt->get(IL_CAL_UNIX));
159  break;
160 
161  case 'End':
162  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
163  $crs_item->setTimingEnd($dt->get(IL_CAL_UNIX));
164  break;
165 
166  case 'SuggestionStart':
167  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
168  $crs_item->setSuggestionStart($dt->get(IL_CAL_UNIX));
169  break;
170 
171  case 'SuggestionEnd':
172  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
173  $crs_item->setSuggestionEnd($dt->get(IL_CAL_UNIX));
174  break;
175 
176  case 'EarliestStart':
177  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
178  $crs_item->setEarliestStart($dt->get(IL_CAL_UNIX));
179  break;
180 
181  case 'LatestEnd':
182  $dt = new ilDateTime((string) $sub,IL_CAL_DATETIME,ilTimeZone::UTC);
183  $crs_item->setLatestEnd($dt->get(IL_CAL_UNIX));
184  break;
185  }
186  }
187 
188 
189  if($crs_item->getTimingStart())
190  {
191  $crs_item->update($a_ref_id, $a_parent_id);
192  }
193  }
194 
204  protected function createObject($ref_id,$obj_id,$type,$title,$parent_node)
205  {
206  global $objDefinition;
207 
208  // A mapping for this object already exists => create reference
209  $new_obj_id = $this->getMapping()->getMapping('Services/Container', 'objs', $obj_id);
210  if($new_obj_id)
211  {
212  include_once './Services/Object/classes/class.ilObjectFactory.php';
213  $obj = ilObjectFactory::getInstanceByObjId($new_obj_id,false);
214  if($obj instanceof ilObject)
215  {
216  $obj->createReference();
217  $obj->putInTree($parent_node);
218  $obj->setPermissions($parent_node);
219  $this->mapping->addMapping('Services/Container','refs',$ref_id,$obj->getRefId());
220  return $obj->getRefId();
221  }
222  }
223 
224  $class_name = "ilObj".$objDefinition->getClassName($type);
225  $location = $objDefinition->getLocation($type);
226 
227  include_once($location."/class.".$class_name.".php");
228  $new = new $class_name();
229  $new->setTitle($title);
230  $new->create(true);
231  $new->createReference();
232  $new->putInTree($parent_node);
233  $new->setPermissions($parent_node);
234 
235  $this->mapping->addMapping('Services/Container','objs', $obj_id, $new->getId());
236  $this->mapping->addMapping('Services/Container','refs',$ref_id,$new->getRefId());
237 
238  return $new->getRefId();
239  }
240 }
241 ?>
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.
Add rich text string
The name of the decorator.
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
Create styles array
The data for the language used.
parseTiming($a_ref_id, $a_parent_id, $timing)
Parse timing info.
$ref_id
Definition: sahs_server.php:39
global $ilSetting
Definition: privfeed.php:17
XML parser for container structure.
static getLogger($a_component_id)
Get component logger.
Class ilObjectActivation.