ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCategoryXmlParser.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
24require_once("./Services/Xml/classes/class.ilSaxParser.php");
25require_once('./Services/User/classes/class.ilObjUser.php');
26include_once('./Services/Calendar/classes/class.ilDateTime.php');
27
28
39{
40 const MODE_CREATE = 1;
41 const MODE_UPDATE = 2;
42
43 private $cat = null;
44 private $parent_id = 0;
45
46 private $current_translation = array();
48
49
58 public function __construct($a_xml, $a_parent_id)
59 {
60 parent::__construct(null);
61
63 $this->parent_id = $a_parent_id;
64 $this->setXMLContent($a_xml);
65 }
66
71 public function getParentId()
72 {
73 return $this->parent_id;
74 }
75
79 protected function getCurrentTranslation()
80 {
82 }
83
84
85
91 public function setHandlers($a_xml_parser)
92 {
93 xml_set_object($a_xml_parser,$this);
94 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
95 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
96 }
97
101 public function startParsing()
102 {
103 parent::startParsing();
104
105 if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
106 {
107 return is_object($this->cat) ? $this->cat->getRefId() : false;
108 }
109 else
110 {
111 return is_object($this->cat) ? $this->cat->update() : false;
112 }
113 }
114
115
119 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
120 {
121 global $ilErr;
122
123 switch($a_name)
124 {
125 case "Category":
126 break;
127
128 case 'Translations':
129 $this->getCategory()->removeTranslations();
130 break;
131
132 case 'Translation':
133 $this->current_translation = array();
134 $this->current_translation['default'] = $a_attribs['default'] ? 1 : 0;
135 $this->current_translation['lang'] = $a_attribs['language'];
136 break;
137
138 case 'Sorting':
139 case 'Sort':
140 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
142 break;
143
144 case 'ContainerSetting':
145 $this->current_container_setting = $a_attribs['id'];
146 break;
147 }
148 }
149
150
156 public function handlerEndTag($a_xml_parser, $a_name)
157 {
158 switch($a_name)
159 {
160 case "Category":
161 $this->save();
162 break;
163
164 case 'Title':
165 $this->current_translation['title'] = trim($this->cdata);
166
167 if($this->current_translation['default'])
168 {
169 $this->getCategory()->setTitle(trim($this->cdata));
170 }
171
172 break;
173
174 case 'Description':
175 $this->current_translation['description'] = trim($this->cdata);
176
177 if($this->current_translation['default'])
178 {
179 $this->getCategory()->setDescription(trim($this->cdata));
180 }
181
182 break;
183
184 case 'Translation':
185 // Add translation
186 $this->getCategory()->addTranslation(
187 (string) $this->current_translation['title'],
188 (string) $this->current_translation['description'],
189 (string) $this->current_translation['lang'],
190 (int) $this->current_translation['default']
191 );
192 break;
193
194 case 'ContainerSetting':
195 if($this->current_container_setting)
196 {
198 $this->getCategory()->getId(),
199 $this->current_container_setting,
200 $this->cdata);
201 }
202 break;
203 }
204 $this->cdata = '';
205 }
206
207
211 function handlerCharacterData($a_xml_parser, $a_data)
212 {
213 #$a_data = str_replace("<","&lt;",$a_data);
214 #$a_data = str_replace(">","&gt;",$a_data);
215
216 if(!empty($a_data))
217 {
218 $this->cdata .= $a_data;
219 }
220 }
221
226 protected function save()
227 {
228
232 if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
233 {
234 $this->create();
235 $this->getCategory()->create();
236 $this->getCategory()->createReference();
237 $this->getCategory()->putInTree($this->getParentId());
238 $this->getCategory()->setPermissions($this->getParentId());
239 }
240 $this->getCategory()->update();
241 return true;
242 }
243
244
245
246
251 public function setMode($mode)
252 {
253 $this->mode = $mode;
254 }
255
260 public function setCategory($cat)
261 {
262 $this->cat = $cat;
263 }
264
265 public function getCategory()
266 {
267 return $this->cat;
268 }
269}
270?>
setCategory($cat)
Set category object.
handlerEndTag($a_xml_parser, $a_name)
Handler end tag.
__construct($a_xml, $a_parent_id)
Constructor.
setMode($mode)
Set import mode.
getCurrentTranslation()
Get current translation.
save()
Save category object.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
_writeContainerSetting($a_id, $a_keyword, $a_value)
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setXMLContent($a_xml_content)