ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilAssQuestionSkillAssignmentXmlParser.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  protected $parsingActive;
31 
36 
40  protected $curQuestionId;
41 
45  protected $curAssignment;
46 
50  protected $curExpression;
51 
55  protected $assignmentList;
56 
60  public function __construct(?string $xmlFile)
61  {
62  $this->parsingActive = false;
63  $this->characterDataBuffer = null;
64  $this->curQuestionId = null;
65  $this->curAssignment = null;
66  $this->curExpression = null;
67  $this->assignmentList = new ilAssQuestionSkillAssignmentImportList();
68  parent::__construct($xmlFile);
69  }
70 
71  public function isParsingActive(): bool
72  {
73  return $this->parsingActive;
74  }
75 
76  public function setParsingActive(bool $parsingActive): void
77  {
78  $this->parsingActive = $parsingActive;
79  }
80 
81  protected function getCharacterDataBuffer(): string
82  {
84  }
85 
89  protected function resetCharacterDataBuffer(): void
90  {
91  $this->characterDataBuffer = '';
92  }
93 
94  protected function appendToCharacterDataBuffer(string $characterData): void
95  {
96  $this->characterDataBuffer .= $characterData;
97  }
98 
99  public function getCurQuestionId(): int
100  {
101  return $this->curQuestionId;
102  }
103 
104  public function setCurQuestionId(?int $curQuestionId): void
105  {
106  $this->curQuestionId = (int) $curQuestionId;
107  }
108 
110  {
111  return $this->curAssignment;
112  }
113 
115  {
116  $this->curAssignment = $curAssignment;
117  }
118 
120  {
121  return $this->assignmentList;
122  }
123 
125  {
126  return $this->curExpression;
127  }
128 
130  {
131  $this->curExpression = $curExpression;
132  }
133 
134  public function setHandlers($a_xml_parser): void
135  {
136  xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
137  xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
138  }
139 
140  public function handlerBeginTag($xmlParser, $tagName, $tagAttributes): void
141  {
142  if ($tagName != 'QuestionSkillAssignments' && !$this->isParsingActive()) {
143  return;
144  }
145 
146  switch ($tagName) {
147  case 'QuestionSkillAssignments':
148  $this->setParsingActive(true);
149  break;
150 
151  case 'TriggerQuestion':
152  $this->setCurQuestionId((int) $tagAttributes['Id']);
153  break;
154 
155  case 'TriggeredSkill':
156  $assignment = new ilAssQuestionSkillAssignmentImport();
157  $assignment->setImportQuestionId($this->getCurQuestionId());
158  $assignment->setImportSkillBaseId((int) $tagAttributes['BaseId']);
159  $assignment->setImportSkillTrefId((int) $tagAttributes['TrefId']);
160  $assignment->initImportSolutionComparisonExpressionList();
161  $this->setCurAssignment($assignment);
162  break;
163 
164  case 'OriginalSkillPath':
165  case 'OriginalSkillTitle':
166  $this->resetCharacterDataBuffer();
167  break;
168 
169  case 'EvalByQuestionResult':
171  $this->getCurAssignment()->setSkillPoints((int) $tagAttributes['Points']);
172  break;
173 
174  case 'EvalByQuestionSolution':
176  break;
177 
178  case 'SolutionComparisonExpression':
180  $expression->setPoints((int) $tagAttributes['Points']);
181  $expression->setOrderIndex((int) $tagAttributes['Index']);
182  $this->setCurExpression($expression);
183  $this->resetCharacterDataBuffer();
184  break;
185  }
186  }
187 
188  public function handlerEndTag($xmlParser, $tagName): void
189  {
190  if (!$this->isParsingActive()) {
191  return;
192  }
193 
194  switch ($tagName) {
195  case 'QuestionSkillAssignments':
196  $this->setParsingActive(false);
197  break;
198 
199  case 'TriggerQuestion':
200  $this->setCurQuestionId(null);
201  break;
202 
203  case 'TriggeredSkill':
204  $this->getAssignmentList()->addAssignment($this->getCurAssignment());
205  $this->setCurAssignment(null);
206  break;
207 
208  case 'OriginalSkillTitle':
209  $this->getCurAssignment()->setImportSkillTitle($this->getCharacterDataBuffer());
210  $this->resetCharacterDataBuffer();
211  break;
212 
213  case 'OriginalSkillPath':
214  $this->getCurAssignment()->setImportSkillPath($this->getCharacterDataBuffer());
215  $this->resetCharacterDataBuffer();
216  break;
217 
218  case 'EvalByQuestionSolution':
219  case 'EvalByQuestionResult':
220  break;
221 
222  case 'SolutionComparisonExpression':
223  $this->getCurExpression()->setExpression($this->getCharacterDataBuffer());
224  $this->getCurAssignment()->getImportSolutionComparisonExpressionList()->addExpression($this->getCurExpression());
225  $this->setCurExpression(null);
226  $this->resetCharacterDataBuffer();
227  break;
228  }
229  }
230 
231  public function handlerCharacterData($xmlParser, $charData): void
232  {
233  if (!$this->isParsingActive()) {
234  return;
235  }
236 
237  if ($charData != "\n") {
238  // Replace multiple tabs with one space
239  $charData = preg_replace("/\t+/", " ", $charData);
240 
241  $this->appendToCharacterDataBuffer($charData);
242  }
243  }
244 }
setCurAssignment(?ilAssQuestionSkillAssignmentImport $curAssignment)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(Container $dic, ilPlugin $plugin)
setCurExpression(?ilAssQuestionSolutionComparisonExpressionImport $curExpression)