ILIAS  release_7 Revision v7.30-3-g800a261c036
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
54 protected $logger;
55
59 protected $import_mapping;
60
69 public function __construct($a_xml, $a_parent_id = 0)
70 {
71 global $DIC;
72
73 $this->error = $DIC["ilErr"];
75
77 $this->setXMLContent($a_xml);
78
79 $this->logger = $DIC->logger()->exp();
80 }
81
85 public function setImportMapping(ilImportMapping $mapping)
86 {
87 $this->import_mapping = $mapping;
88 }
89
94 public function getParentId()
95 {
96 return $this->parent_id;
97 }
98
104 public function setHandlers($a_xml_parser)
105 {
106 xml_set_object($a_xml_parser, $this);
107 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
108 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
109 }
110
114 public function startParsing()
115 {
116 parent::startParsing();
117
118 if ($this->ref instanceof ilContainerReference) {
119 return $this->ref;
120 }
121 return 0;
122 }
123
124
128 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
129 {
130 $a_attribs = $this->trimAndStripAttribs($a_attribs);
132
133 switch ($a_name) {
134 case "ContainerReference":
135 break;
136
137 case 'Title':
138 switch ($a_attribs['type']) {
141 break;
142
143 default:
145 break;
146 }
147 break;
148
149 case 'Target':
150 $target_id = $this->parseTargetId(isset($a_attribs['id']) ? (string) $a_attribs['id'] : '');
151 if ($target_id) {
152 $this->logger->debug('Using mapped target_id: ' . $target_id);
153 $this->getReference()->setTargetId($target_id);
154 } else {
155 $this->logger->info('No mapping found for: ' . $a_attribs['id']);
156 $this->getReference()->setTargetId(0);
157 }
158 break;
159 }
160 }
161
166 protected function parseTargetId(string $attribute_target) : int
167 {
168 if (!strlen($attribute_target)) {
169 $this->logger->debug('No target id provided');
170 return 0;
171 }
172 if (!$this->import_mapping instanceof ilImportMapping) {
173 return 0;
174 }
175 $obj_mapping_id = $this->import_mapping->getMapping('Services/Container', 'objs', $attribute_target);
176 if (!$obj_mapping_id) {
177 $this->logger->debug('Cannot find object mapping for target_id: ' . $attribute_target);
178 return 0;
179 }
180 return $obj_mapping_id;
181 }
182
183
189 public function handlerEndTag($a_xml_parser, $a_name)
190 {
191 $this->cdata = $this->trimAndStrip((string) $this->cdata);
192 switch ($a_name) {
193 case "ContainerReference":
194 $this->save();
195 break;
196
197 case 'Title':
198 if ($this->getReference()->getTitleType() == ilContainerReference::TITLE_TYPE_CUSTOM) {
199 $this->getReference()->setTitle(trim($this->cdata));
200 }
201 break;
202 }
203 $this->cdata = '';
204 }
205
206
210 public function handlerCharacterData($a_xml_parser, $a_data)
211 {
212 #$a_data = str_replace("<","&lt;",$a_data);
213 #$a_data = str_replace(">","&gt;",$a_data);
214
215 if (!empty($a_data)) {
216 $this->cdata .= $a_data;
217 }
218 }
219
224 protected function save()
225 {
229 include_once './Modules/Category/classes/class.ilCategoryXmlParser.php';
230 if ($this->mode == ilCategoryXmlParser::MODE_CREATE) {
231 $this->create();
232 $this->getReference()->create();
233 $this->getReference()->createReference();
234 $this->getReference()->putInTree($this->getParentId());
235 $this->getReference()->setPermissions($this->getParentId());
236 }
237 $this->getReference()->update();
238 return true;
239 }
240
241
242
243
248 public function setMode($mode)
249 {
250 $this->mode = $mode;
251 }
252
253
259 {
260 $this->ref = $ref;
261 }
262
267 public function getReference()
268 {
269 return $this->ref;
270 }
271}
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
setXMLContent($a_xml_content)
global $DIC
Definition: goto.php:24
$target_id
Definition: goto.php:51
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ilErr
Definition: raiseError.php:18