ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestSkillLevelThresholdXmlParser.php
Go to the documentation of this file.
1<?php
2
19declare(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
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 {
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();
83 }
84
85 public function getCurSkillBaseId(): ?int
86 {
88 }
89
90 public function setCurSkillBaseId(?int $curSkillBaseId): void
91 {
92 $this->curSkillBaseId = $curSkillBaseId;
93 }
94
95 public function getCurSkillTrefId(): ?int
96 {
98 }
99
100 public function setCurSkillTrefId(?int $curSkillTrefId): void
101 {
102 $this->curSkillTrefId = $curSkillTrefId;
103 }
104
106 {
108 }
109
111 {
112 $this->curSkillLevelThreshold = $curSkillLevelThreshold;
113 }
114
115 public function setHandlers($a_xml_parser): void
116 {
117 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
118 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
119 }
120
121 public function handlerBeginTag($xmlParser, $tagName, $tagAttributes): void
122 {
123 if ($tagName != 'SkillsLevelThresholds' && !$this->isParsingActive()) {
124 return;
125 }
126
127 switch ($tagName) {
128 case 'SkillsLevelThresholds':
129 $this->setParsingActive(true);
131 break;
132
133 case 'QuestionsAssignedSkill':
134 $this->setCurSkillBaseId((int) $tagAttributes['BaseId']);
135 $this->setCurSkillTrefId((int) $tagAttributes['TrefId']);
136 break;
137
138 case 'OriginalLevelDescription':
139 case 'OriginalLevelTitle':
140 case 'ThresholdPercentage':
141 case 'OriginalSkillPath':
142 case 'OriginalSkillTitle':
144 break;
145
146 case 'SkillLevel':
147 $skillLevelThreshold = new ilTestSkillLevelThresholdImport();
148 $skillLevelThreshold->setImportSkillBaseId($this->getCurSkillBaseId());
149 $skillLevelThreshold->setImportSkillTrefId($this->getCurSkillTrefId());
150 $skillLevelThreshold->setImportLevelId((int) $tagAttributes['Id']);
151 $skillLevelThreshold->setOrderIndex((int) $tagAttributes['Nr']);
152 $this->setCurSkillLevelThreshold($skillLevelThreshold);
153 break;
154 }
155 }
156
157 public function handlerEndTag($xmlParser, $tagName): void
158 {
159 if (!$this->isParsingActive()) {
160 return;
161 }
162
163 switch ($tagName) {
164 case 'SkillsLevelThresholds':
165 $this->setParsingActive(false);
166 break;
167
168 case 'QuestionsAssignedSkill':
169 $this->setCurSkillBaseId(null);
170 $this->setCurSkillTrefId(null);
171 break;
172
173 case 'OriginalSkillTitle':
174 $this->getSkillLevelThresholdImportList()->addOriginalSkillTitle(
175 $this->getCurSkillBaseId(),
176 $this->getCurSkillTrefId(),
178 );
180 break;
181
182 case 'OriginalSkillPath':
183 $this->getSkillLevelThresholdImportList()->addOriginalSkillPath(
184 $this->getCurSkillBaseId(),
185 $this->getCurSkillTrefId(),
187 );
189 break;
190
191 case 'SkillLevel':
192 $this->getSkillLevelThresholdImportList()->addSkillLevelThreshold(
194 );
195 $this->setCurSkillLevelThreshold(null);
196 break;
197
198 case 'ThresholdPercentage':
199 $this->getCurSkillLevelThreshold()->setThreshold((int) $this->getCharacterDataBuffer());
201 break;
202
203 case 'OriginalLevelTitle':
204 $this->getCurSkillLevelThreshold()->setOriginalLevelTitle($this->getCharacterDataBuffer());
206 break;
207
208 case 'OriginalLevelDescription':
209 $this->getCurSkillLevelThreshold()->setOriginalLevelDescription($this->getCharacterDataBuffer());
211 break;
212 }
213 }
214
215 public function handlerCharacterData($xmlParser, $charData): void
216 {
217 if (!$this->isParsingActive()) {
218 return;
219 }
220
221 if ($charData != "\n") {
222 // Replace multiple tabs with one space
223 $charData = preg_replace("/\t+/", " ", $charData);
224
225 $this->appendToCharacterDataBuffer($charData);
226 }
227 }
228}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilTestSkillLevelThresholdImportList $skillLevelThresholdImportList
setCurSkillLevelThreshold(?ilTestSkillLevelThresholdImport $curSkillLevelThreshold)
Interface ilDBInterface.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26