ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  {
41  global $DIC;
42  $this->db = $DIC['ilDB'];
44  }
45 
46  public function isParsingActive(): bool
47  {
48  return $this->parsingActive;
49  }
50 
51  public function setParsingActive(bool $parsingActive): void
52  {
53  $this->parsingActive = $parsingActive;
54  }
55 
56  protected function getCharacterDataBuffer(): ?string
57  {
59  }
60 
64  protected function resetCharacterDataBuffer(): void
65  {
66  $this->characterDataBuffer = '';
67  }
68 
69  protected function appendToCharacterDataBuffer(string $characterData): void
70  {
71  $this->characterDataBuffer .= $characterData;
72  }
73 
75  {
77  }
78 
79  public function initSkillLevelThresholdImportList(): void
80  {
81  $this->skillLevelThresholdImportList = new ilTestSkillLevelThresholdImportList();
82  }
83 
84  public function getCurSkillBaseId(): ?int
85  {
86  return $this->curSkillBaseId;
87  }
88 
89  public function setCurSkillBaseId(?int $curSkillBaseId): void
90  {
91  $this->curSkillBaseId = $curSkillBaseId;
92  }
93 
94  public function getCurSkillTrefId(): ?int
95  {
96  return $this->curSkillTrefId;
97  }
98 
99  public function setCurSkillTrefId(?int $curSkillTrefId): void
100  {
101  $this->curSkillTrefId = $curSkillTrefId;
102  }
103 
105  {
107  }
108 
109  public function setCurSkillLevelThreshold(?ilTestSkillLevelThresholdImport $curSkillLevelThreshold): void
110  {
111  $this->curSkillLevelThreshold = $curSkillLevelThreshold;
112  }
113 
114  public function setHandlers($a_xml_parser): void
115  {
116  xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
117  xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
118  }
119 
120  public function handlerBeginTag($xmlParser, $tagName, $tagAttributes): void
121  {
122  if ($tagName != 'SkillsLevelThresholds' && !$this->isParsingActive()) {
123  return;
124  }
125 
126  switch ($tagName) {
127  case 'SkillsLevelThresholds':
128  $this->setParsingActive(true);
130  break;
131 
132  case 'QuestionsAssignedSkill':
133  $this->setCurSkillBaseId($tagAttributes['BaseId']);
134  $this->setCurSkillTrefId($tagAttributes['TrefId']);
135  break;
136 
137  case 'OriginalLevelDescription':
138  case 'OriginalLevelTitle':
139  case 'ThresholdPercentage':
140  case 'OriginalSkillPath':
141  case 'OriginalSkillTitle':
142  $this->resetCharacterDataBuffer();
143  break;
144 
145  case 'SkillLevel':
146  $skillLevelThreshold = new ilTestSkillLevelThresholdImport();
147  $skillLevelThreshold->setImportSkillBaseId($this->getCurSkillBaseId());
148  $skillLevelThreshold->setImportSkillTrefId($this->getCurSkillTrefId());
149  $skillLevelThreshold->setImportLevelId($tagAttributes['Id']);
150  $skillLevelThreshold->setOrderIndex($tagAttributes['Nr']);
151  $this->setCurSkillLevelThreshold($skillLevelThreshold);
152  break;
153  }
154  }
155 
156  public function handlerEndTag($xmlParser, $tagName): void
157  {
158  if (!$this->isParsingActive()) {
159  return;
160  }
161 
162  switch ($tagName) {
163  case 'SkillsLevelThresholds':
164  $this->setParsingActive(false);
165  break;
166 
167  case 'QuestionsAssignedSkill':
168  $this->setCurSkillBaseId(null);
169  $this->setCurSkillTrefId(null);
170  break;
171 
172  case 'OriginalSkillTitle':
173  $this->getSkillLevelThresholdImportList()->addOriginalSkillTitle(
174  $this->getCurSkillBaseId(),
175  $this->getCurSkillTrefId(),
176  $this->getCharacterDataBuffer()
177  );
178  $this->resetCharacterDataBuffer();
179  break;
180 
181  case 'OriginalSkillPath':
182  $this->getSkillLevelThresholdImportList()->addOriginalSkillPath(
183  $this->getCurSkillBaseId(),
184  $this->getCurSkillTrefId(),
185  $this->getCharacterDataBuffer()
186  );
187  $this->resetCharacterDataBuffer();
188  break;
189 
190  case 'SkillLevel':
191  $this->getSkillLevelThresholdImportList()->addSkillLevelThreshold(
193  );
195  break;
196 
197  case 'ThresholdPercentage':
198  $this->getCurSkillLevelThreshold()->setThreshold($this->getCharacterDataBuffer());
199  $this->resetCharacterDataBuffer();
200  break;
201 
202  case 'OriginalLevelTitle':
203  $this->getCurSkillLevelThreshold()->setOriginalLevelTitle($this->getCharacterDataBuffer());
204  $this->resetCharacterDataBuffer();
205  break;
206 
207  case 'OriginalLevelDescription':
208  $this->getCurSkillLevelThreshold()->setOriginalLevelDescription($this->getCharacterDataBuffer());
209  $this->resetCharacterDataBuffer();
210  break;
211  }
212  }
213 
214  public function handlerCharacterData($xmlParser, $charData): void
215  {
216  if (!$this->isParsingActive()) {
217  return;
218  }
219 
220  if ($charData != "\n") {
221  // Replace multiple tabs with one space
222  $charData = preg_replace("/\t+/", " ", $charData);
223 
224  $this->appendToCharacterDataBuffer($charData);
225  }
226  }
227 }
setCurSkillLevelThreshold(?ilTestSkillLevelThresholdImport $curSkillLevelThreshold)
ilTestSkillLevelThresholdImportList $skillLevelThresholdImportList
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
global $DIC
Definition: shib_login.php:22
__construct(Container $dic, ilPlugin $plugin)