ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 require_once 'Services/Xml/classes/class.ilSaxParser.php';
5 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignment.php';
6 require_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  {
65  return $this->parsingActive;
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  {
105  return $this->curQuestionId;
106  }
107 
112  {
113  $this->curQuestionId = $curQuestionId;
114  }
115 
119  public function getCurAssignment()
120  {
121  return $this->curAssignment;
122  }
123 
128  {
129  $this->curAssignment = $curAssignment;
130  }
131 
135  public function getAssignmentList()
136  {
137  return $this->assignmentList;
138  }
139 
143  public function getCurExpression()
144  {
145  return $this->curExpression;
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  {
167  return;
168  }
169 
170  switch($tagName)
171  {
172  case 'QuestionSkillAssignments':
173  $this->setParsingActive(true);
174  break;
175 
176  case 'TriggerQuestion':
177  $this->setCurQuestionId((int)$tagAttributes['Id']);
178  break;
179 
180  case 'TriggeredSkill':
181  $assignment = new ilAssQuestionSkillAssignmentImport();
182  $assignment->setImportQuestionId($this->getCurQuestionId());
183  $assignment->setImportSkillBaseId((int)$tagAttributes['BaseId']);
184  $assignment->setImportSkillTrefId((int)$tagAttributes['TrefId']);
185  $assignment->initImportSolutionComparisonExpressionList();
186  $this->setCurAssignment($assignment);
187  break;
188 
189  case 'OriginalSkillTitle':
190  $this->resetCharacterDataBuffer();
191  break;
192 
193  case 'OriginalSkillPath':
194  $this->resetCharacterDataBuffer();
195  break;
196 
197  case 'EvalByQuestionResult':
199  $this->getCurAssignment()->setSkillPoints((int)$tagAttributes['Points']);
200  break;
201 
202  case 'EvalByQuestionSolution':
204  break;
205 
206  case 'SolutionComparisonExpression':
208  $expression->setPoints((int)$tagAttributes['Points']);
209  $expression->setOrderIndex((int)$tagAttributes['Index']);
210  $this->setCurExpression($expression);
211  $this->resetCharacterDataBuffer();
212  break;
213  }
214  }
215 
216  public function handlerEndTag($xmlParser, $tagName)
217  {
218  if( !$this->isParsingActive() )
219  {
220  return;
221  }
222 
223  switch($tagName)
224  {
225  case 'QuestionSkillAssignments':
226  $this->setParsingActive(false);
227  break;
228 
229  case 'TriggerQuestion':
230  $this->setCurQuestionId(null);
231  break;
232 
233  case 'TriggeredSkill':
234  $this->getAssignmentList()->addAssignment($this->getCurAssignment());
235  $this->setCurAssignment(null);
236  break;
237 
238  case 'OriginalSkillTitle':
239  $this->getCurAssignment()->setImportSkillTitle($this->getCharacterDataBuffer());
240  $this->resetCharacterDataBuffer();
241  break;
242 
243  case 'OriginalSkillPath':
244  $this->getCurAssignment()->setImportSkillPath($this->getCharacterDataBuffer());
245  $this->resetCharacterDataBuffer();
246  break;
247 
248  case 'EvalByQuestionResult':
249  break;
250 
251  case 'EvalByQuestionSolution':
252  break;
253 
254  case 'SolutionComparisonExpression':
255  $this->getCurExpression()->setExpression($this->getCharacterDataBuffer());
256  $this->getCurAssignment()->getImportSolutionComparisonExpressionList()->addExpression($this->getCurExpression());
257  $this->setCurExpression(null);
258  $this->resetCharacterDataBuffer();
259  break;
260  }
261  }
262 
263  public function handlerCharacterData($xmlParser, $charData)
264  {
265  if( !$this->isParsingActive() )
266  {
267  return;
268  }
269 
270  if( $charData != "\n" )
271  {
272  // Replace multiple tabs with one space
273  $charData = preg_replace("/\t+/"," ",$charData);
274 
275  $this->appendToCharacterDataBuffer($charData);
276  }
277  }
278 }
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...