ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
53 protected $cat_log;
54
63 public function __construct($a_xml, $a_parent_id)
64 {
65 parent::__construct(null);
66
68 $this->parent_id = $a_parent_id;
69 $this->setXMLContent($a_xml);
70
71 $this->cat_log = ilLoggerFactory::getLogger("cat");
72 }
73
78 public function getParentId()
79 {
80 return $this->parent_id;
81 }
82
86 protected function getCurrentTranslation()
87 {
89 }
90
91
92
98 public function setHandlers($a_xml_parser)
99 {
100 xml_set_object($a_xml_parser,$this);
101 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
102 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
103 }
104
108 public function startParsing()
109 {
110 parent::startParsing();
111
112 if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
113 {
114 return is_object($this->cat) ? $this->cat->getRefId() : false;
115 }
116 else
117 {
118 return is_object($this->cat) ? $this->cat->update() : false;
119 }
120 }
121
122
126 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
127 {
128 global $ilErr;
129
130 switch($a_name)
131 {
132 case "Category":
133 break;
134
135 case 'Translations':
136 $this->getCategory()->removeTranslations();
137 break;
138
139 case 'Translation':
140 $this->current_translation = array();
141 $this->current_translation['default'] = $a_attribs['default'] ? 1 : 0;
142 $this->current_translation['lang'] = $a_attribs['language'];
143 break;
144
145 case 'Sorting':
146 case 'Sort':
147 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
149 break;
150
151 case 'ContainerSetting':
152 $this->current_container_setting = $a_attribs['id'];
153 break;
154 }
155 }
156
157
163 public function handlerEndTag($a_xml_parser, $a_name)
164 {
165 switch($a_name)
166 {
167 case "Category":
168 $this->save();
169 break;
170
171 case 'Title':
172 $this->current_translation['title'] = trim($this->cdata);
173
174 if($this->current_translation['default'])
175 {
176 $this->getCategory()->setTitle(trim($this->cdata));
177 }
178
179 break;
180
181 case 'Description':
182 $this->current_translation['description'] = trim($this->cdata);
183
184 if($this->current_translation['default'])
185 {
186 $this->getCategory()->setDescription(trim($this->cdata));
187 }
188
189 break;
190
191 case 'Translation':
192 // Add translation
193 $this->getCategory()->addTranslation(
194 (string) $this->current_translation['title'],
195 (string) $this->current_translation['description'],
196 (string) $this->current_translation['lang'],
197 (int) $this->current_translation['default']
198 );
199 break;
200
201 case 'ContainerSetting':
202 if($this->current_container_setting)
203 {
204 $this->cat_log->debug("Write container Setting, ID: ".$this->getCategory()->getId().", setting: ".
205 $this->current_container_setting.", data: ".$this->cdata);
207 $this->getCategory()->getId(),
208 $this->current_container_setting,
209 $this->cdata);
210 }
211 break;
212
213 case 'ContainerSettings':
214 $this->cat->readContainerSettings(); // read container settings to member vars (call getter/setter), see #0019870
215 break;
216 }
217 $this->cdata = '';
218 }
219
220
224 function handlerCharacterData($a_xml_parser, $a_data)
225 {
226 #$a_data = str_replace("<","&lt;",$a_data);
227 #$a_data = str_replace(">","&gt;",$a_data);
228
229 if(!empty($a_data))
230 {
231 $this->cdata .= $a_data;
232 }
233 }
234
239 protected function save()
240 {
241
245 if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
246 {
247 $this->create();
248 $this->getCategory()->create();
249 $this->getCategory()->createReference();
250 $this->getCategory()->putInTree($this->getParentId());
251 $this->getCategory()->setPermissions($this->getParentId());
252 }
253 $this->getCategory()->update();
254 return true;
255 }
256
257
258
259
264 public function setMode($mode)
265 {
266 $this->mode = $mode;
267 }
268
273 public function setCategory($cat)
274 {
275 $this->cat = $cat;
276 }
277
278 public function getCategory()
279 {
280 return $this->cat;
281 }
282}
283?>
An exception for terminatinating execution or to throw for unit testing.
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
static _writeContainerSetting($a_id, $a_keyword, $a_value)
static getLogger($a_component_id)
Get component logger.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setXMLContent($a_xml_content)
global $ilErr
Definition: raiseError.php:16