ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
40 const MODE_CREATE = 1;
41 const MODE_UPDATE = 2;
42
43 private $ref = null;
44 private $parent_id = 0;
45
54 public function __construct($a_xml, $a_parent_id = 0)
55 {
56 parent::__construct(null);
57
59 $this->setXMLContent($a_xml);
60 }
61
66 public function getParentId()
67 {
68 return $this->parent_id;
69 }
70
76 public function setHandlers($a_xml_parser)
77 {
78 xml_set_object($a_xml_parser,$this);
79 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
80 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
81 }
82
86 public function startParsing()
87 {
88 parent::startParsing();
89
90 if($this->ref instanceof ilContainerReference)
91 {
92 return $this->ref;
93 }
94 return 0;
95 }
96
97
101 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
102 {
103 global $ilErr;
104
105 switch($a_name)
106 {
107 case "ContainerReference":
108 break;
109
110 case 'Title':
111 switch($a_attribs['type'])
112 {
115 break;
116
117 default:
119 break;
120 }
121 break;
122
123 case 'Target':
124 $this->getReference()->setTargetId($a_attribs['id']);
125 break;
126 }
127 }
128
129
135 public function handlerEndTag($a_xml_parser, $a_name)
136 {
137 switch($a_name)
138 {
139 case "ContainerReference":
140 $this->save();
141 break;
142
143 case 'Title':
144 if($this->getReference()->getTitleType() == ilContainerReference::TITLE_TYPE_CUSTOM)
145 {
146 $this->getReference()->setTitle(trim($this->cdata));
147 }
148 break;
149 }
150 $this->cdata = '';
151 }
152
153
157 function handlerCharacterData($a_xml_parser, $a_data)
158 {
159 #$a_data = str_replace("<","&lt;",$a_data);
160 #$a_data = str_replace(">","&gt;",$a_data);
161
162 if(!empty($a_data))
163 {
164 $this->cdata .= $a_data;
165 }
166 }
167
172 protected function save()
173 {
177 include_once './Modules/Category/classes/class.ilCategoryXmlParser.php';
178 if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
179 {
180 $this->create();
181 $this->getReference()->create();
182 $this->getReference()->createReference();
183 $this->getReference()->putInTree($this->getParentId());
184 $this->getReference()->setPermissions($this->getParentId());
185 }
186 $this->getReference()->update();
187 return true;
188 }
189
190
191
192
197 public function setMode($mode)
198 {
199 $this->mode = $mode;
200 }
201
202
208 {
209 $this->ref = $ref;
210 }
211
216 public function getReference()
217 {
218 return $this->ref;
219 }
220}
221?>
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)