ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilDB;
98  $this->skillLevelThresholdImportList = new ilTestSkillLevelThresholdImportList($ilDB);
99  }
100 
104  public function getCurSkillBaseId()
105  {
106  return $this->curSkillBaseId;
107  }
108 
113  {
114  $this->curSkillBaseId = $curSkillBaseId;
115  }
116 
120  public function getCurSkillTrefId()
121  {
122  return $this->curSkillTrefId;
123  }
124 
129  {
130  $this->curSkillTrefId = $curSkillTrefId;
131  }
132 
136  public function getCurSkillLevelThreshold()
137  {
139  }
140 
145  {
146  $this->curSkillLevelThreshold = $curSkillLevelThreshold;
147  }
148 
149  public function setHandlers($xmlParser)
150  {
151  xml_set_object($xmlParser, $this);
152  xml_set_element_handler($xmlParser, 'handlerBeginTag', 'handlerEndTag');
153  xml_set_character_data_handler($xmlParser, 'handlerCharacterData');
154  }
155 
156  public function handlerBeginTag($xmlParser, $tagName, $tagAttributes)
157  {
158  if ($tagName != 'SkillsLevelThresholds' && !$this->isParsingActive())
159  {
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 $ilDB;
184  $skillLevelThreshold = new ilTestSkillLevelThresholdImport($ilDB);
185  $skillLevelThreshold->setImportSkillBaseId($this->getCurSkillBaseId());
186  $skillLevelThreshold->setImportSkillTrefId($this->getCurSkillTrefId());
187  $skillLevelThreshold->setImportLevelId($tagAttributes['Id']);
188  $skillLevelThreshold->setOrderIndex($tagAttributes['Nr']);
189  $this->setCurSkillLevelThreshold($skillLevelThreshold);
190  break;
191 
192  case 'ThresholdPercentage':
193  $this->resetCharacterDataBuffer();
194  break;
195 
196  case 'OriginalLevelTitle':
197  $this->resetCharacterDataBuffer();
198  break;
199 
200  case 'OriginalLevelDescription':
201  $this->resetCharacterDataBuffer();
202  break;
203  }
204  }
205 
206  public function handlerEndTag($xmlParser, $tagName)
207  {
208  if( !$this->isParsingActive() )
209  {
210  return;
211  }
212 
213  switch($tagName)
214  {
215  case 'SkillsLevelThresholds':
216  $this->setParsingActive(false);
217  break;
218 
219  case 'QuestionsAssignedSkill':
220  $this->setCurSkillBaseId(null);
221  $this->setCurSkillTrefId(null);
222  break;
223 
224  case 'OriginalSkillTitle':
225  $this->getSkillLevelThresholdImportList()->addOriginalSkillTitle(
226  $this->getCurSkillBaseId(), $this->getCurSkillTrefId(), $this->getCharacterDataBuffer()
227  );
228  $this->resetCharacterDataBuffer();
229  break;
230 
231  case 'OriginalSkillPath':
232  $this->getSkillLevelThresholdImportList()->addOriginalSkillPath(
233  $this->getCurSkillBaseId(), $this->getCurSkillTrefId(), $this->getCharacterDataBuffer()
234  );
235  $this->resetCharacterDataBuffer();
236  break;
237 
238  case 'SkillLevel':
239  $this->getSkillLevelThresholdImportList()->addSkillLevelThreshold(
241  );
242  $this->setCurSkillLevelThreshold(null);
243  break;
244 
245  case 'ThresholdPercentage':
246  $this->getCurSkillLevelThreshold()->setThreshold($this->getCharacterDataBuffer());
247  $this->resetCharacterDataBuffer();
248  break;
249 
250  case 'OriginalLevelTitle':
251  $this->getCurSkillLevelThreshold()->setOriginalLevelTitle($this->getCharacterDataBuffer());
252  $this->resetCharacterDataBuffer();
253  break;
254 
255  case 'OriginalLevelDescription':
256  $this->getCurSkillLevelThreshold()->setOriginalLevelDescription($this->getCharacterDataBuffer());
257  $this->resetCharacterDataBuffer();
258  break;
259  }
260  }
261 
262  public function handlerCharacterData($xmlParser, $charData)
263  {
264  if( !$this->isParsingActive() )
265  {
266  return;
267  }
268 
269  if( $charData != "\n" )
270  {
271  // Replace multiple tabs with one space
272  $charData = preg_replace("/\t+/"," ",$charData);
273 
274  $this->appendToCharacterDataBuffer($charData);
275  }
276  }
277 }
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
global $ilDB