ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAssQuestionSkillAssignmentXmlParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Xml/classes/class.ilSaxParser.php';
5require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignment.php';
6require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportList.php';
7
15{
19 protected $parsingActive;
20
25
29 protected $curQuestionId;
30
34 protected $curAssignment;
35
39 protected $curExpression;
40
44 protected $assignmentList;
45
49 public function __construct($xmlFile)
50 {
51 $this->parsingActive = false;
52 $this->characterDataBuffer = null;
53 $this->curQuestionId = null;
54 $this->curAssignment = null;
55 $this->curExpression = null;
56 $this->assignmentList = new ilAssQuestionSkillAssignmentImportList();
57 return parent::__construct($xmlFile);
58 }
59
63 public function isParsingActive()
64 {
66 }
67
72 {
73 $this->parsingActive = $parsingActive;
74 }
75
79 protected function getCharacterDataBuffer()
80 {
82 }
83
87 protected function resetCharacterDataBuffer()
88 {
89 $this->characterDataBuffer = '';
90 }
91
95 protected function appendToCharacterDataBuffer($characterData)
96 {
97 $this->characterDataBuffer .= $characterData;
98 }
99
103 public function getCurQuestionId()
104 {
106 }
107
112 {
113 $this->curQuestionId = $curQuestionId;
114 }
115
119 public function getCurAssignment()
120 {
122 }
123
128 {
129 $this->curAssignment = $curAssignment;
130 }
131
135 public function getAssignmentList()
136 {
138 }
139
143 public function getCurExpression()
144 {
146 }
147
152 {
153 $this->curExpression = $curExpression;
154 }
155
156 public function setHandlers($xmlParser)
157 {
158 xml_set_object($xmlParser, $this);
159 xml_set_element_handler($xmlParser, 'handlerBeginTag', 'handlerEndTag');
160 xml_set_character_data_handler($xmlParser, 'handlerCharacterData');
161 }
162
163 public function handlerBeginTag($xmlParser, $tagName, $tagAttributes)
164 {
165 if ($tagName != 'QuestionSkillAssignments' && !$this->isParsingActive()) {
166 return;
167 }
168
169 switch ($tagName) {
170 case 'QuestionSkillAssignments':
171 $this->setParsingActive(true);
172 break;
173
174 case 'TriggerQuestion':
175 $this->setCurQuestionId((int) $tagAttributes['Id']);
176 break;
177
178 case 'TriggeredSkill':
179 $assignment = new ilAssQuestionSkillAssignmentImport();
180 $assignment->setImportQuestionId($this->getCurQuestionId());
181 $assignment->setImportSkillBaseId((int) $tagAttributes['BaseId']);
182 $assignment->setImportSkillTrefId((int) $tagAttributes['TrefId']);
183 $assignment->initImportSolutionComparisonExpressionList();
184 $this->setCurAssignment($assignment);
185 break;
186
187 case 'OriginalSkillTitle':
189 break;
190
191 case 'OriginalSkillPath':
193 break;
194
195 case 'EvalByQuestionResult':
197 $this->getCurAssignment()->setSkillPoints((int) $tagAttributes['Points']);
198 break;
199
200 case 'EvalByQuestionSolution':
202 break;
203
204 case 'SolutionComparisonExpression':
206 $expression->setPoints((int) $tagAttributes['Points']);
207 $expression->setOrderIndex((int) $tagAttributes['Index']);
208 $this->setCurExpression($expression);
210 break;
211 }
212 }
213
214 public function handlerEndTag($xmlParser, $tagName)
215 {
216 if (!$this->isParsingActive()) {
217 return;
218 }
219
220 switch ($tagName) {
221 case 'QuestionSkillAssignments':
222 $this->setParsingActive(false);
223 break;
224
225 case 'TriggerQuestion':
226 $this->setCurQuestionId(null);
227 break;
228
229 case 'TriggeredSkill':
230 $this->getAssignmentList()->addAssignment($this->getCurAssignment());
231 $this->setCurAssignment(null);
232 break;
233
234 case 'OriginalSkillTitle':
235 $this->getCurAssignment()->setImportSkillTitle($this->getCharacterDataBuffer());
237 break;
238
239 case 'OriginalSkillPath':
240 $this->getCurAssignment()->setImportSkillPath($this->getCharacterDataBuffer());
242 break;
243
244 case 'EvalByQuestionResult':
245 break;
246
247 case 'EvalByQuestionSolution':
248 break;
249
250 case 'SolutionComparisonExpression':
251 $this->getCurExpression()->setExpression($this->getCharacterDataBuffer());
252 $this->getCurAssignment()->getImportSolutionComparisonExpressionList()->addExpression($this->getCurExpression());
253 $this->setCurExpression(null);
255 break;
256 }
257 }
258
259 public function handlerCharacterData($xmlParser, $charData)
260 {
261 if (!$this->isParsingActive()) {
262 return;
263 }
264
265 if ($charData != "\n") {
266 // Replace multiple tabs with one space
267 $charData = preg_replace("/\t+/", " ", $charData);
268
269 $this->appendToCharacterDataBuffer($charData);
270 }
271 }
272}
An exception for terminatinating execution or to throw for unit testing.
setHandlers($xmlParser)
set event handler should be overwritten by inherited class @access private
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc