ILIAS  release_7 Revision v7.30-3-g800a261c036
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
34include_once './Services/Xml/classes/class.ilSaxParser.php';
35include_once('./webservice/soap/classes/class.ilObjectXMLException.php');
36
38{
39 public $object_data = array();
40
41 private $ref_id;
42 private $parent_id;
43
53 public function __construct($a_xml_data = '', $throwException = false)
54 {
56 $this->setXMLContent($a_xml_data);
57 }
58
59 public function getObjectData()
60 {
61 return $this->object_data ? $this->object_data : array();
62 }
63
71 public function parse($a_xml_parser, $a_fp = null)
72 {
73 parent::parse($a_xml_parser, $a_fp);
74 }
75
76
83 public 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 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
101 {
102 switch ($a_name) {
103 case 'Objects':
104 $this->curr_obj = -1;
105 break;
106
107 case 'Object':
108 ++$this->curr_obj;
109
110 $this->__addProperty('type', $a_attribs['type']);
111 $this->__addProperty('obj_id', is_numeric($a_attribs['obj_id'])?(int) $a_attribs["obj_id"] : ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID));
112 $this->__addProperty('offline', $a_attribs['offline']);
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 $this->time_target['starting_time'] = $a_attribs['starting_time'];
147 }
148 if (isset($a_attribs['ending_time'])) {
149 $this->time_target['ending_time'] = $a_attribs['ending_time'];
150 }
151
152 if ($a_attribs['ending_time'] < $a_attribs['starting_time']) {
153 throw new ilObjectXMLException('Starting time must be earlier than ending time.');
154 }
155 break;
156
157 case 'Suggestion':
158 $this->time_target['changeable'] = $a_attribs['changeable'];
159
160
161 if (isset($a_attribs['starting_time'])) {
162 $this->time_target['suggestion_start'] = $a_attribs['starting_time'];
163 }
164 if (isset($a_attribs['ending_time'])) {
165 $this->time_target['suggestion_end'] = $a_attribs['ending_time'];
166 }
167 break;
168
169 }
170 }
171
178 public function handlerEndTag($a_xml_parser, $a_name)
179 {
180 switch ($a_name) {
181 case 'Objects':
182 break;
183
184 case 'Object':
185 break;
186
187 case 'Title':
188 $this->__addProperty('title', trim($this->cdata));
189 break;
190
191 case 'Description':
192 $this->__addProperty('description', trim($this->cdata));
193 break;
194
195 case 'Owner':
196 $this->__addProperty('owner', trim($this->cdata));
197 break;
198
199 case 'CreateDate':
200 $this->__addProperty('create_date', trim($this->cdata));
201 break;
202
203 case 'LastUpdate':
204 $this->__addProperty('last_update', trim($this->cdata));
205 break;
206
207 case 'ImportId':
208 $this->__addProperty('import_id', trim($this->cdata));
209 break;
210
211 case 'References':
212 $this->__addReference($this->ref_id, $this->parent_id, $this->time_target);
213 break;
214 }
215
216 $this->cdata = '';
217
218 return;
219 }
220
227 public function handlerCharacterData($a_xml_parser, $a_data)
228 {
229 if ($a_data != "\n") {
230 // Replace multiple tabs with one space
231 $a_data = preg_replace("/\t+/", " ", $a_data);
232
233 $this->cdata .= $a_data;
234 }
235 }
236
237 // PRIVATE
238 public function __addProperty($a_name, $a_value)
239 {
240 $this->object_data[$this->curr_obj][$a_name] = $a_value;
241 }
242
246 public function __addReference($a_ref_id, $a_parent_id, $a_time_target)
247 {
248 $reference['ref_id'] = $a_ref_id;
249 $reference['parent_id'] = $a_parent_id;
250 $reference['time_target'] = $a_time_target;
251
252 if (isset($reference['time_target']['changeable']) and $reference['time_target']['changeable']) {
253 if (!isset($reference['time_target']['suggestion_start']) or !isset($reference['time_target']['suggestion_end'])) {
254 throw new ilObjectXMLException('Missing attributes: "starting_time" and "ending_time" required for attribute "changeable"');
255 }
256 }
257
258 $this->object_data[$this->curr_obj]['references'][] = $reference;
259 }
260}
An exception for terminatinating execution or to throw for unit testing.
Exception class for ObjectXMLWriter and ObjectXMLParser.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
__addProperty($a_name, $a_value)
__addReference($a_ref_id, $a_parent_id, $a_time_target)
setHandlers($a_xml_parser)
set event handlers
parse($a_xml_parser, $a_fp=null)
parse xml file
__construct($a_xml_data='', $throwException=false)
Constructor.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setXMLContent($a_xml_content)
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
const IL_INST_ID
Definition: constants.php:38
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc