ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCategoryImportParser.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");
25
35{
39 protected $rbacadmin;
40
44 protected $rbacreview;
45
49 protected $rbacsystem;
50
51 public $parent; // current parent ref id
52 public $withrol; // must have value '1' when creating a hierarchy of local roles
53
54 protected $cat_log;
55
56
64 public function __construct($a_xml_file, $a_parent, $withrol)
65 {
66 global $DIC;
67
68 $this->rbacadmin = $DIC->rbac()->admin();
69 $this->rbacreview = $DIC->rbac()->review();
70 $this->rbacsystem = $DIC->rbac()->system();
71 $this->parent_cnt = 0;
72 $this->parent[$this->parent_cnt] = $a_parent;
73 $this->parent_cnt++;
74 $this->withrol = $withrol;
75
76 parent::__construct($a_xml_file);
77 }
78
79
85 public function setHandlers($a_xml_parser)
86 {
87 xml_set_object($a_xml_parser, $this);
88 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
89 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
90 }
91
95 public function startParsing()
96 {
97 parent::startParsing();
98 }
99
107 public function buildTag($type, $name, $attr = "")
108 {
109 $tag = "<";
110
111 if ($type == "end") {
112 $tag .= "/";
113 }
114
115 $tag .= $name;
116
117 if (is_array($attr)) {
118 foreach ($attr as $k => $v) {
119 $tag .= " " . $k . "=\"$v\"";
120 }
121 }
122
123 $tag .= ">";
124
125 return $tag;
126 }
127
131 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
132 {
136
137 switch ($a_name) {
138 case "Category":
139 $cur_parent = $this->parent[$this->parent_cnt - 1];
140 require_once("Modules/Category/classes/class.ilObjCategory.php");
141 $this->category = new ilObjCategory;
142 $this->category->setImportId($a_attribs["Id"] . " (#" . $cur_parent . ")");
143 $this->default_language = $a_attribs["DefaultLanguage"];
144 $this->category->setTitle($a_attribs["Id"]);
145 $this->category->create();
146 $this->category->createReference();
147 $this->category->putInTree($cur_parent);
148 $this->parent[$this->parent_cnt++] = $this->category->getRefId();
149 break;
150
151 case "CategorySpec":
152 $this->cur_spec_lang = $a_attribs["Language"];
153 break;
154
155 }
156 }
157
158
162 public function handlerEndTag($a_xml_parser, $a_name)
163 {
164 switch ($a_name) {
165 case "Category":
166 unset($this->category);
167 unset($this->parent[$this->parent_cnt - 1]);
168 $this->parent_cnt--;
169 break;
170
171 case "CategorySpec":
172 $is_def = 0;
173 if ($this->cur_spec_lang == $this->default_language) {
174 $this->category->setTitle($this->cur_title);
175 $this->category->setDescription($this->cur_description);
176 $this->category->update();
177 $is_def = 1;
178 }
179 $this->category->addTranslation(
180 $this->cur_title,
181 $this->cur_description,
182 $this->cur_spec_lang,
183 $is_def
184 );
185 break;
186
187 case "Title":
188 $this->cur_title = $this->cdata;
189 break;
190
191 case "Description":
192 $this->cur_description = $this->cdata;
193 break;
194 }
195
196 $this->cdata = "";
197 }
198
202 public function handlerCharacterData($a_xml_parser, $a_data)
203 {
204 // i don't know why this is necessary, but
205 // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
206 // in character data, but we don't want that, because it's the
207 // way we mask user html in our content, so we convert back...
208 $a_data = str_replace("<", "&lt;", $a_data);
209 $a_data = str_replace(">", "&gt;", $a_data);
210
211 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
212 $a_data = preg_replace("/\n/", "", $a_data);
213 $a_data = preg_replace("/\t+/", "", $a_data);
214 if (!empty($a_data)) {
215 $this->cdata .= $a_data;
216 }
217 }
218}
An exception for terminatinating execution or to throw for unit testing.
handlerEndTag($a_xml_parser, $a_name)
handler for end 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
buildTag($type, $name, $attr="")
generate a tag with given name and attributes
__construct($a_xml_file, $a_parent, $withrol)
Constructor.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
Class ilObjCategory.
setImportId($a_import_id)
set import id
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
if(function_exists( 'posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35
$type
global $DIC
Definition: saml.php:7