ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestSkillLevelThresholdXmlParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
29  protected bool $parsingActive = false;
30  protected ?string $characterDataBuffer = null;
31  protected ?int $curSkillBaseId = null;
32  protected ?int $curSkillTrefId = null;
33 
34  private ilDBInterface $db;
35 
38 
39  public function __construct(
40  ?string $path_to_file = ''
41  ) {
42  global $DIC;
43  $this->db = $DIC['ilDB'];
44  parent::__construct($path_to_file);
45  }
46 
47  public function isParsingActive(): bool
48  {
49  return $this->parsingActive;
50  }
51 
52  public function setParsingActive(bool $parsingActive): void
53  {
54  $this->parsingActive = $parsingActive;
55  }
56 
57  protected function getCharacterDataBuffer(): ?string
58  {
60  }
61 
65  protected function resetCharacterDataBuffer(): void
66  {
67  $this->characterDataBuffer = '';
68  }
69 
70  protected function appendToCharacterDataBuffer(string $characterData): void
71  {
72  $this->characterDataBuffer .= $characterData;
73  }
74 
76  {
78  }
79 
80  public function initSkillLevelThresholdImportList(): void
81  {
82  $this->skillLevelThresholdImportList = new ilTestSkillLevelThresholdImportList($this->db);
83  }
84 
85  public function getCurSkillBaseId(): ?int
86  {
87  return $this->curSkillBaseId;
88  }
89 
90  public function setCurSkillBaseId(?int $curSkillBaseId): void
91  {
92  $this->curSkillBaseId = $curSkillBaseId;
93  }
94 
95  public function getCurSkillTrefId(): ?int
96  {
97  return $this->curSkillTrefId;
98  }
99 
100  public function setCurSkillTrefId(?int $curSkillTrefId): void
101  {
102  $this->curSkillTrefId = $curSkillTrefId;
103  }
104 
106  {
108  }
109 
110  public function setCurSkillLevelThreshold(?ilTestSkillLevelThresholdImport $curSkillLevelThreshold): void
111  {
112  $this->curSkillLevelThreshold = $curSkillLevelThreshold;
113  }
114 
115  public function setHandlers($a_xml_parser): void
116  {
117  xml_set_object($a_xml_parser, $this);
118  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
119  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
120  }
121 
122  public function handlerBeginTag($xmlParser, $tagName, $tagAttributes): void
123  {
124  if ($tagName != 'SkillsLevelThresholds' && !$this->isParsingActive()) {
125  return;
126  }
127 
128  switch ($tagName) {
129  case 'SkillsLevelThresholds':
130  $this->setParsingActive(true);
132  break;
133 
134  case 'QuestionsAssignedSkill':
135  $this->setCurSkillBaseId((int) $tagAttributes['BaseId']);
136  $this->setCurSkillTrefId((int) $tagAttributes['TrefId']);
137  break;
138 
139  case 'OriginalLevelDescription':
140  case 'OriginalLevelTitle':
141  case 'ThresholdPercentage':
142  case 'OriginalSkillPath':
143  case 'OriginalSkillTitle':
144  $this->resetCharacterDataBuffer();
145  break;
146 
147  case 'SkillLevel':
148  $skillLevelThreshold = new ilTestSkillLevelThresholdImport($this->db);
149  $skillLevelThreshold->setImportSkillBaseId($this->getCurSkillBaseId());
150  $skillLevelThreshold->setImportSkillTrefId($this->getCurSkillTrefId());
151  $skillLevelThreshold->setImportLevelId((int) $tagAttributes['Id']);
152  $skillLevelThreshold->setOrderIndex((int) $tagAttributes['Nr']);
153  $this->setCurSkillLevelThreshold($skillLevelThreshold);
154  break;
155  }
156  }
157 
158  public function handlerEndTag($xmlParser, $tagName): void
159  {
160  if (!$this->isParsingActive()) {
161  return;
162  }
163 
164  switch ($tagName) {
165  case 'SkillsLevelThresholds':
166  $this->setParsingActive(false);
167  break;
168 
169  case 'QuestionsAssignedSkill':
170  $this->setCurSkillBaseId(null);
171  $this->setCurSkillTrefId(null);
172  break;
173 
174  case 'OriginalSkillTitle':
175  $this->getSkillLevelThresholdImportList()->addOriginalSkillTitle(
176  $this->getCurSkillBaseId(),
177  $this->getCurSkillTrefId(),
178  $this->getCharacterDataBuffer()
179  );
180  $this->resetCharacterDataBuffer();
181  break;
182 
183  case 'OriginalSkillPath':
184  $this->getSkillLevelThresholdImportList()->addOriginalSkillPath(
185  $this->getCurSkillBaseId(),
186  $this->getCurSkillTrefId(),
187  $this->getCharacterDataBuffer()
188  );
189  $this->resetCharacterDataBuffer();
190  break;
191 
192  case 'SkillLevel':
193  $this->getSkillLevelThresholdImportList()->addSkillLevelThreshold(
195  );
196  $this->setCurSkillLevelThreshold(null);
197  break;
198 
199  case 'ThresholdPercentage':
200  $this->getCurSkillLevelThreshold()->setThreshold((int) $this->getCharacterDataBuffer());
201  $this->resetCharacterDataBuffer();
202  break;
203 
204  case 'OriginalLevelTitle':
205  $this->getCurSkillLevelThreshold()->setOriginalLevelTitle($this->getCharacterDataBuffer());
206  $this->resetCharacterDataBuffer();
207  break;
208 
209  case 'OriginalLevelDescription':
210  $this->getCurSkillLevelThreshold()->setOriginalLevelDescription($this->getCharacterDataBuffer());
211  $this->resetCharacterDataBuffer();
212  break;
213  }
214  }
215 
216  public function handlerCharacterData($xmlParser, $charData): void
217  {
218  if (!$this->isParsingActive()) {
219  return;
220  }
221 
222  if ($charData != "\n") {
223  // Replace multiple tabs with one space
224  $charData = preg_replace("/\t+/", " ", $charData);
225 
226  $this->appendToCharacterDataBuffer($charData);
227  }
228  }
229 }
setCurSkillLevelThreshold(?ilTestSkillLevelThresholdImport $curSkillLevelThreshold)
ilTestSkillLevelThresholdImportList $skillLevelThresholdImportList
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)