ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
24 require_once("./Services/Xml/classes/class.ilSaxParser.php");
25 require_once('./Services/User/classes/class.ilObjUser.php');
26 include_once('./Services/Calendar/classes/class.ilDateTime.php');
27 
28 
39 {
43  protected $error;
44 
45  const MODE_CREATE = 1;
46  const MODE_UPDATE = 2;
47 
48  private $cat = null;
49  private $parent_id = 0;
50 
53 
54 
58  protected $cat_log;
59 
68  public function __construct($a_xml, $a_parent_id)
69  {
70  global $DIC;
71 
72  $this->error = $DIC["ilErr"];
73  parent::__construct(null);
74 
76  $this->parent_id = $a_parent_id;
77  $this->setXMLContent($a_xml);
78 
79  $this->cat_log = ilLoggerFactory::getLogger("cat");
80  }
81 
86  public function getParentId()
87  {
88  return $this->parent_id;
89  }
90 
94  protected function getCurrentTranslation()
95  {
97  }
98 
99 
100 
106  public function setHandlers($a_xml_parser)
107  {
108  xml_set_object($a_xml_parser, $this);
109  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
110  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
111  }
112 
116  public function startParsing()
117  {
118  parent::startParsing();
119 
120  if ($this->mode == ilCategoryXmlParser::MODE_CREATE) {
121  return is_object($this->cat) ? $this->cat->getRefId() : false;
122  } else {
123  return is_object($this->cat) ? $this->cat->update() : false;
124  }
125  }
126 
127 
131  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
132  {
134 
135  switch ($a_name) {
136  case "Category":
137  break;
138 
139  case 'Translations':
140  $this->getCategory()->removeTranslations();
141  break;
142 
143  case 'Translation':
144  $this->current_translation = array();
145  $this->current_translation['default'] = $a_attribs['default'] ? 1 : 0;
146  $this->current_translation['lang'] = $a_attribs['language'];
147  break;
148 
149  case 'Sorting':
150  case 'Sort':
151  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
153  break;
154 
155  case 'ContainerSetting':
156  $this->current_container_setting = $a_attribs['id'];
157  break;
158  }
159  }
160 
161 
167  public function handlerEndTag($a_xml_parser, $a_name)
168  {
169  switch ($a_name) {
170  case "Category":
171  $this->save();
172  break;
173 
174  case 'Title':
175  $this->current_translation['title'] = trim($this->cdata);
176 
177  if ($this->current_translation['default']) {
178  $this->getCategory()->setTitle(trim($this->cdata));
179  }
180 
181  break;
182 
183  case 'Description':
184  $this->current_translation['description'] = trim($this->cdata);
185 
186  if ($this->current_translation['default']) {
187  $this->getCategory()->setDescription(trim($this->cdata));
188  }
189 
190  break;
191 
192  case 'Translation':
193  // Add translation
194  $this->getCategory()->addTranslation(
195  (string) $this->current_translation['title'],
196  (string) $this->current_translation['description'],
197  (string) $this->current_translation['lang'],
198  (int) $this->current_translation['default']
199  );
200  break;
201 
202  case 'ContainerSetting':
203  if ($this->current_container_setting) {
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  }
212  break;
213 
214  case 'ContainerSettings':
215  $this->cat->readContainerSettings(); // read container settings to member vars (call getter/setter), see #0019870
216  break;
217  }
218  $this->cdata = '';
219  }
220 
221 
225  public function handlerCharacterData($a_xml_parser, $a_data)
226  {
227  #$a_data = str_replace("<","&lt;",$a_data);
228  #$a_data = str_replace(">","&gt;",$a_data);
229 
230  if (!empty($a_data)) {
231  $this->cdata .= $a_data;
232  }
233  }
234 
239  protected function save()
240  {
241 
245  if ($this->mode == ilCategoryXmlParser::MODE_CREATE) {
246  $this->create();
247  $this->getCategory()->create();
248  $this->getCategory()->createReference();
249  $this->getCategory()->putInTree($this->getParentId());
250  $this->getCategory()->setPermissions($this->getParentId());
251  }
252  $this->getCategory()->update();
253  return true;
254  }
255 
256 
257 
258 
263  public function setMode($mode)
264  {
265  $this->mode = $mode;
266  }
267 
272  public function setCategory($cat)
273  {
274  $this->cat = $cat;
275  }
276 
277  public function getCategory()
278  {
279  return $this->cat;
280  }
281 }
global $ilErr
Definition: raiseError.php:16
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
global $DIC
Definition: saml.php:7
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
handlerEndTag($a_xml_parser, $a_name)
Handler end tag.
__construct($a_xml, $a_parent_id)
Constructor.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
getCurrentTranslation()
Get current translation.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setCategory($cat)
Set category object.
save()
Save category object.
Create styles array
The data for the language used.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class private
static _writeContainerSetting($a_id, $a_keyword, $a_value)
static getLogger($a_component_id)
Get component logger.
setXMLContent($a_xml_content)
setMode($mode)
Set import mode.