ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilContainerReferenceXmlParser.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{
43 protected $error;
44
45 const MODE_CREATE = 1;
46 const MODE_UPDATE = 2;
47
48 private $ref = null;
49 private $parent_id = 0;
50
59 public function __construct($a_xml, $a_parent_id = 0)
60 {
61 global $DIC;
62
63 $this->error = $DIC["ilErr"];
64 parent::__construct(null);
65
67 $this->setXMLContent($a_xml);
68 }
69
74 public function getParentId()
75 {
76 return $this->parent_id;
77 }
78
84 public function setHandlers($a_xml_parser)
85 {
86 xml_set_object($a_xml_parser, $this);
87 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
88 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
89 }
90
94 public function startParsing()
95 {
96 parent::startParsing();
97
98 if ($this->ref instanceof ilContainerReference) {
99 return $this->ref;
100 }
101 return 0;
102 }
103
104
108 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
109 {
111
112 switch ($a_name) {
113 case "ContainerReference":
114 break;
115
116 case 'Title':
117 switch ($a_attribs['type']) {
120 break;
121
122 default:
124 break;
125 }
126 break;
127
128 case 'Target':
129 $this->getReference()->setTargetId($a_attribs['id']);
130 break;
131 }
132 }
133
134
140 public function handlerEndTag($a_xml_parser, $a_name)
141 {
142 switch ($a_name) {
143 case "ContainerReference":
144 $this->save();
145 break;
146
147 case 'Title':
148 if ($this->getReference()->getTitleType() == ilContainerReference::TITLE_TYPE_CUSTOM) {
149 $this->getReference()->setTitle(trim($this->cdata));
150 }
151 break;
152 }
153 $this->cdata = '';
154 }
155
156
160 public function handlerCharacterData($a_xml_parser, $a_data)
161 {
162 #$a_data = str_replace("<","&lt;",$a_data);
163 #$a_data = str_replace(">","&gt;",$a_data);
164
165 if (!empty($a_data)) {
166 $this->cdata .= $a_data;
167 }
168 }
169
174 protected function save()
175 {
179 include_once './Modules/Category/classes/class.ilCategoryXmlParser.php';
180 if ($this->mode == ilCategoryXmlParser::MODE_CREATE) {
181 $this->create();
182 $this->getReference()->create();
183 $this->getReference()->createReference();
184 $this->getReference()->putInTree($this->getParentId());
185 $this->getReference()->setPermissions($this->getParentId());
186 }
187 $this->getReference()->update();
188 return true;
189 }
190
191
192
193
198 public function setMode($mode)
199 {
200 $this->mode = $mode;
201 }
202
203
209 {
210 $this->ref = $ref;
211 }
212
217 public function getReference()
218 {
219 return $this->ref;
220 }
221}
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
handlerEndTag($a_xml_parser, $a_name)
Handler end tag.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
__construct($a_xml, $a_parent_id=0)
Constructor.
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
setReference(ilContainerReference $ref)
Set container reference.
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
global $DIC
Definition: saml.php:7