ILIAS  release_8 Revision v8.24
class.ilTestSkillLevelThresholdImporter.php
Go to the documentation of this file.
1<?php
2
26{
30 protected $targetTestId = null;
31
35 protected $importInstallationId = null;
36
40 protected $importMappingRegistry = null;
41
46
50 protected $importThresholdList = null;
51
56
60 public function __construct()
61 {
62 $this->failedThresholdImportSkillList = new ilAssQuestionAssignedSkillList();
63 }
64
68 public function getTargetTestId(): ?int
69 {
71 }
72
77 {
78 $this->targetTestId = $targetTestId;
79 }
80
84 public function getImportInstallationId(): ?int
85 {
87 }
88
93 {
94 $this->importInstallationId = $importInstallationId;
95 }
96
101 {
103 }
104
109 {
110 $this->importMappingRegistry = $importMappingRegistry;
111 }
112
117 {
119 }
120
125 {
126 $this->importedQuestionSkillAssignmentList = $importedQuestionSkillAssignmentList;
127 }
128
133 {
135 }
136
141 {
142 $this->importThresholdList = $importThresholdList;
143 }
144
149 {
151 }
152
157 {
158 $this->failedThresholdImportSkillList = $failedThresholdImportSkillList;
159 }
160
163 public function import()
164 {
165 global $DIC;
166 $ilDB = $DIC['ilDB'];
167
168 $importedLevelThresholdList = new ilTestSkillLevelThresholdList($ilDB);
169
170 foreach ($this->getImportedQuestionSkillAssignmentList()->getUniqueAssignedSkills() as $skillData) {
171 /* @var ilBasicSkill $skill */
172 $skill = $skillData['skill'];
173
174 $importSkillBaseId = $this->getImportMappingRegistry()->getMapping(
175 'Modules/Test',
176 'skl_base_id_reverse',
177 $skillData['skill_base_id']
178 );
179
180 $importSkillTrefId = $this->getImportMappingRegistry()->getMapping(
181 'Modules/Test',
182 'skl_tref_id_reverse',
183 $skillData['skill_tref_id']
184 );
185
186 $levelThresholds = $this->getImportThresholdList()->getThresholdsByImportSkill(
187 $importSkillBaseId,
188 $importSkillTrefId
189 );
190
191 $existingLevels = $skill->getLevelData();
192
193 if (count($levelThresholds) != count($existingLevels)) {
194 $this->getFailedThresholdImportSkillList()->addSkill(
195 $skillData['skill_base_id'],
196 $skillData['skill_tref_id']
197 );
198
199 continue;
200 }
201
202 for ($i = 0, $max = count($existingLevels); $i < $max; $i++) {
203 $existingLevelData = $existingLevels[$i];
204
205 /* @var ilTestSkillLevelThresholdImport $importLevelThreshold */
206 $importLevelThreshold = $levelThresholds[$i];
207
208 if ($importLevelThreshold->getOrderIndex() != $existingLevelData['nr']) {
209 $this->getFailedThresholdImportSkillList()->addSkill(
210 $skillData['skill_base_id'],
211 $skillData['skill_tref_id']
212 );
213
214 continue(2);
215 }
216
217 if (!is_numeric($importLevelThreshold->getThreshold())) {
218 continue(2);
219 }
220
221 $mappedLevelId = $this->getLevelIdMapping($importLevelThreshold->getImportLevelId());
222
223 $threshold = new ilTestSkillLevelThreshold($ilDB);
224 $threshold->setTestId($this->getTargetTestId());
225 $threshold->setSkillBaseId($skillData['skill_base_id']);
226 $threshold->setSkillTrefId($skillData['skill_tref_id']);
227 $threshold->setSkillLevelId($mappedLevelId);
228 $threshold->setThreshold($importLevelThreshold->getThreshold());
229
230 $importedLevelThresholdList->addThreshold($threshold);
231 }
232 }
233
234 $importedLevelThresholdList->saveToDb();
235 }
236
241 protected function getLevelIdMapping($importLevelId): int
242 {
243 /*
244 $r = ilBasicSkill::getLevelIdForImportId($a_source_inst_id,
245 $a_level_import_id);
246
247 $results[] = array("level_id" => $rec["id"], "creation_date" =>
248 $rec["creation_date"]);
249 */
250
251 $result = ilBasicSkill::getLevelIdForImportId($this->getImportInstallationId(), $importLevelId);
252 $mostNewLevelData = current($result);
253 return $mostNewLevelData['level_id'];
254 }
255}
static getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFailedThresholdImportSkillList($failedThresholdImportSkillList)
__construct()
ilTestSkillLevelThresholdImporter constructor.
setImportedQuestionSkillAssignmentList($importedQuestionSkillAssignmentList)
global $DIC
Definition: feed.php:28
$i
Definition: metadata.php:41