ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestSkillLevelThresholdXmlParser.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 'Modules/Test/classes/class.ilTestSkillLevelThresholdImport.php';
5 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImportList.php';
6 
14 {
18  protected $parsingActive = false;
19 
23  protected $characterDataBuffer = null;
24 
29 
33  protected $curSkillBaseId = null;
34 
38  protected $curSkillTrefId = null;
39 
43  protected $curSkillLevelThreshold = null;
44 
48  public function isParsingActive()
49  {
50  return $this->parsingActive;
51  }
52 
57  {
58  $this->parsingActive = $parsingActive;
59  }
60 
64  protected function getCharacterDataBuffer()
65  {
67  }
68 
72  protected function resetCharacterDataBuffer()
73  {
74  $this->characterDataBuffer = '';
75  }
76 
80  protected function appendToCharacterDataBuffer($characterData)
81  {
82  $this->characterDataBuffer .= $characterData;
83  }
84 
89  {
91  }
92 
96  {
97  global $DIC;
98  $ilDB = $DIC['ilDB'];
99  $this->skillLevelThresholdImportList = new ilTestSkillLevelThresholdImportList($ilDB);
100  }
101 
105  public function getCurSkillBaseId()
106  {
107  return $this->curSkillBaseId;
108  }
109 
114  {
115  $this->curSkillBaseId = $curSkillBaseId;
116  }
117 
121  public function getCurSkillTrefId()
122  {
123  return $this->curSkillTrefId;
124  }
125 
130  {
131  $this->curSkillTrefId = $curSkillTrefId;
132  }
133 
137  public function getCurSkillLevelThreshold()
138  {
140  }
141 
146  {
147  $this->curSkillLevelThreshold = $curSkillLevelThreshold;
148  }
149 
150  public function setHandlers($xmlParser)
151  {
152  xml_set_object($xmlParser, $this);
153  xml_set_element_handler($xmlParser, 'handlerBeginTag', 'handlerEndTag');
154  xml_set_character_data_handler($xmlParser, 'handlerCharacterData');
155  }
156 
157  public function handlerBeginTag($xmlParser, $tagName, $tagAttributes)
158  {
159  if ($tagName != 'SkillsLevelThresholds' && !$this->isParsingActive()) {
160  return;
161  }
162 
163  switch ($tagName) {
164  case 'SkillsLevelThresholds':
165  $this->setParsingActive(true);
167  break;
168 
169  case 'QuestionsAssignedSkill':
170  $this->setCurSkillBaseId($tagAttributes['BaseId']);
171  $this->setCurSkillTrefId($tagAttributes['TrefId']);
172  break;
173 
174  case 'OriginalSkillTitle':
175  $this->resetCharacterDataBuffer();
176  break;
177 
178  case 'OriginalSkillPath':
179  $this->resetCharacterDataBuffer();
180  break;
181 
182  case 'SkillLevel':
183  global $DIC;
184  $ilDB = $DIC['ilDB'];
185  $skillLevelThreshold = new ilTestSkillLevelThresholdImport($ilDB);
186  $skillLevelThreshold->setImportSkillBaseId($this->getCurSkillBaseId());
187  $skillLevelThreshold->setImportSkillTrefId($this->getCurSkillTrefId());
188  $skillLevelThreshold->setImportLevelId($tagAttributes['Id']);
189  $skillLevelThreshold->setOrderIndex($tagAttributes['Nr']);
190  $this->setCurSkillLevelThreshold($skillLevelThreshold);
191  break;
192 
193  case 'ThresholdPercentage':
194  $this->resetCharacterDataBuffer();
195  break;
196 
197  case 'OriginalLevelTitle':
198  $this->resetCharacterDataBuffer();
199  break;
200 
201  case 'OriginalLevelDescription':
202  $this->resetCharacterDataBuffer();
203  break;
204  }
205  }
206 
207  public function handlerEndTag($xmlParser, $tagName)
208  {
209  if (!$this->isParsingActive()) {
210  return;
211  }
212 
213  switch ($tagName) {
214  case 'SkillsLevelThresholds':
215  $this->setParsingActive(false);
216  break;
217 
218  case 'QuestionsAssignedSkill':
219  $this->setCurSkillBaseId(null);
220  $this->setCurSkillTrefId(null);
221  break;
222 
223  case 'OriginalSkillTitle':
224  $this->getSkillLevelThresholdImportList()->addOriginalSkillTitle(
225  $this->getCurSkillBaseId(),
226  $this->getCurSkillTrefId(),
227  $this->getCharacterDataBuffer()
228  );
229  $this->resetCharacterDataBuffer();
230  break;
231 
232  case 'OriginalSkillPath':
233  $this->getSkillLevelThresholdImportList()->addOriginalSkillPath(
234  $this->getCurSkillBaseId(),
235  $this->getCurSkillTrefId(),
236  $this->getCharacterDataBuffer()
237  );
238  $this->resetCharacterDataBuffer();
239  break;
240 
241  case 'SkillLevel':
242  $this->getSkillLevelThresholdImportList()->addSkillLevelThreshold(
244  );
245  $this->setCurSkillLevelThreshold(null);
246  break;
247 
248  case 'ThresholdPercentage':
249  $this->getCurSkillLevelThreshold()->setThreshold($this->getCharacterDataBuffer());
250  $this->resetCharacterDataBuffer();
251  break;
252 
253  case 'OriginalLevelTitle':
254  $this->getCurSkillLevelThreshold()->setOriginalLevelTitle($this->getCharacterDataBuffer());
255  $this->resetCharacterDataBuffer();
256  break;
257 
258  case 'OriginalLevelDescription':
259  $this->getCurSkillLevelThreshold()->setOriginalLevelDescription($this->getCharacterDataBuffer());
260  $this->resetCharacterDataBuffer();
261  break;
262  }
263  }
264 
265  public function handlerCharacterData($xmlParser, $charData)
266  {
267  if (!$this->isParsingActive()) {
268  return;
269  }
270 
271  if ($charData != "\n") {
272  // Replace multiple tabs with one space
273  $charData = preg_replace("/\t+/", " ", $charData);
274 
275  $this->appendToCharacterDataBuffer($charData);
276  }
277  }
278 }
global $DIC
Definition: saml.php:7
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
global $ilDB