ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectXMLParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 include_once './Services/Xml/classes/class.ilSaxParser.php';
35 include_once('./webservice/soap/classes/class.ilObjectXMLException.php');
36 
38 {
39  var $object_data = array();
40 
41  private $ref_id;
42  private $parent_id;
43 
53  function ilObjectXMLParser($a_xml_data = '', $throwException = false)
54  {
56  $this->setXMLContent($a_xml_data);
57  }
58 
59  function getObjectData()
60  {
61  return $this->object_data ? $this->object_data : array();
62  }
63 
71  function parse($a_xml_parser,$a_fp = null)
72  {
73  parent::parse($a_xml_parser,$a_fp);
74  }
75 
76 
83  function setHandlers($a_xml_parser)
84  {
85  xml_set_object($a_xml_parser,$this);
86  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
87  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
88  }
89 
90 
91 
92 
100  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
101  {
102  switch($a_name)
103  {
104  case 'Objects':
105  $this->curr_obj = -1;
106  break;
107 
108  case 'Object':
109  ++$this->curr_obj;
110 
111  $this->__addProperty('type',$a_attribs['type']);
112  $this->__addProperty('obj_id',is_numeric($a_attribs['obj_id'])?(int) $a_attribs["obj_id"] : ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID));
113  break;
114 
115  case 'Title':
116  break;
117 
118  case 'Description':
119  break;
120 
121  case 'Owner':
122  break;
123 
124  case 'CreateDate':
125  break;
126 
127  case 'LastUpdate':
128  break;
129 
130  case 'ImportId':
131  break;
132 
133  case 'References':
134  $this->time_target = array();
135  $this->ref_id = $a_attribs["ref_id"];
136  $this->parent_id = $a_attribs['parent_id'];
137  break;
138 
139  case 'TimeTarget':
140  $this->time_target['timing_type'] = $a_attribs['type'];
141  break;
142 
143  case 'Timing':
144  $this->time_target['timing_visibility'] = $a_attribs['visibility'];
145  if(isset($a_attribs['starting_time']))
146  {
147  $this->time_target['starting_time'] = $a_attribs['starting_time'];
148  }
149  if(isset($a_attribs['ending_time']))
150  {
151  $this->time_target['ending_time'] = $a_attribs['ending_time'];
152  }
153 
154  if($a_attribs['ending_time'] < $a_attribs['starting_time'])
155  throw new ilObjectXMLException('Starting time must be earlier than ending time.');
156  break;
157 
158  case 'Suggestion':
159  $this->time_target['changeable'] = $a_attribs['changeable'];
160 
161 
162  if(isset($a_attribs['starting_time']))
163  {
164  $this->time_target['suggestion_start'] = $a_attribs['starting_time'];
165  }
166  if(isset($a_attribs['ending_time']))
167  {
168  $this->time_target['suggestion_end'] = $a_attribs['ending_time'];
169  }
170  if(isset($a_attribs['earliest_start']))
171  {
172  $this->time_target['earliest_start'] = $a_attribs['earliest_start'];
173  }
174  if(isset($a_attribs['latest_end']))
175  {
176  $this->time_target['latest_end'] = $a_attribs['latest_end'];
177  }
178 
179  if($a_attribs['latest_end'] < $a_attribs['earliest_start'])
180  throw new ilObjectXMLException('Earliest start time must be earlier than latest ending time.');
181  if($a_attribs['ending_time'] < $a_attribs['starting_time'])
182  throw new ilObjectXMLException('Starting time must be earlier than ending time.');
183  break;
184 
185  }
186  }
187 
194  function handlerEndTag($a_xml_parser,$a_name)
195  {
196  switch($a_name)
197  {
198  case 'Objects':
199  break;
200 
201  case 'Object':
202  break;
203 
204  case 'Title':
205  $this->__addProperty('title',trim($this->cdata));
206  break;
207 
208  case 'Description':
209  $this->__addProperty('description',trim($this->cdata));
210  break;
211 
212  case 'Owner':
213  $this->__addProperty('owner',trim($this->cdata));
214  break;
215 
216  case 'CreateDate':
217  $this->__addProperty('create_date',trim($this->cdata));
218  break;
219 
220  case 'LastUpdate':
221  $this->__addProperty('last_update',trim($this->cdata));
222  break;
223 
224  case 'ImportId':
225  $this->__addProperty('import_id',trim($this->cdata));
226  break;
227 
228  case 'References':
229  $this->__addReference($this->ref_id,$this->parent_id,$this->time_target);
230  break;
231  }
232 
233  $this->cdata = '';
234 
235  return;
236  }
237 
244  function handlerCharacterData($a_xml_parser,$a_data)
245  {
246  if($a_data != "\n")
247  {
248  // Replace multiple tabs with one space
249  $a_data = preg_replace("/\t+/"," ",$a_data);
250 
251  $this->cdata .= $a_data;
252  }
253 
254 
255  }
256 
257  // PRIVATE
258  function __addProperty($a_name,$a_value)
259  {
260  $this->object_data[$this->curr_obj][$a_name] = $a_value;
261  }
262 
266  function __addReference($a_ref_id,$a_parent_id,$a_time_target)
267  {
268  $reference['ref_id'] = $a_ref_id;
269  $reference['parent_id'] = $a_parent_id;
270  $reference['time_target'] = $a_time_target;
271 
272  if(isset($reference['time_target']['changeable']) and $reference['time_target']['changeable'])
273  {
274  if(!isset($reference['time_target']['earliest_start']) or !isset($reference['time_target']['latest_end']))
275  {
276  throw new ilObjectXMLException('Missing attributes: "earliest_start" and "latest_end" required for attribute "changeable"');
277  }
278  if(!isset($reference['time_target']['suggestion_start']) or !isset($reference['time_target']['suggestion_end']))
279  {
280  throw new ilObjectXMLException('Missing attributes: "starting_time" and "ending_time" required for attribute "changeable"');
281  }
282  if(($reference['time_target']['earliest_start'] < $reference['time_target']['suggestion_start']) or
283  ($reference['time_target']['earliest_start'] > $reference['time_target']['suggestion_end']))
284  {
285  throw new ilObjectXMLException('Invalid attributes: "earliest_start" must be within "starting_time" and "ending_time"');
286  }
287  if(($reference['time_target']['latest_end'] < $reference['time_target']['suggestion_start']) or
288  ($reference['time_target']['latest_end'] > $reference['time_target']['suggestion_end']))
289  {
290  throw new ilObjectXMLException('Invalid attributes: "latest_end" must be within "starting_time" and "ending_time"');
291  }
292  }
293 
294  $this->object_data[$this->curr_obj]['references'][] = $reference;
295  }
296 
297 }
298 ?>