ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestSkillLevelThresholdImporter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private ?int $targetTestId = null;
30 private ?int $importInstallationId = null;
31
36
37 public function __construct(
38 private ilDBInterface $db
39 ) {
40 $this->failedThresholdImportSkillList = new ilAssQuestionAssignedSkillList();
41 }
42
43 public function getTargetTestId(): ?int
44 {
46 }
47
48 public function setTargetTestId(int $targetTestId): void
49 {
50 $this->targetTestId = $targetTestId;
51 }
52
53 public function getImportInstallationId(): ?int
54 {
56 }
57
59 {
60 $this->importInstallationId = $importInstallationId;
61 }
62
64 {
66 }
67
69 {
70 $this->importMappingRegistry = $importMappingRegistry;
71 }
72
74 {
76 }
77
79 {
80 $this->importedQuestionSkillAssignmentList = $importedQuestionSkillAssignmentList;
81 }
82
84 {
86 }
87
89 {
90 $this->importThresholdList = $importThresholdList;
91 }
92
94 {
96 }
97
99 {
100 $this->failedThresholdImportSkillList = $failedThresholdImportSkillList;
101 }
102
103 public function import(): void
104 {
105 $importedLevelThresholdList = new ilTestSkillLevelThresholdList($this->db);
106
107 foreach ($this->getImportedQuestionSkillAssignmentList()->getUniqueAssignedSkills() as $skillData) {
108 /* @var ilBasicSkill $skill */
109 $skill = $skillData['skill'];
110
111 $importSkillBaseId = $this->getImportMappingRegistry()->getMapping(
112 'components/ILIAS/Test',
113 'skl_base_id_reverse',
114 (string) $skillData['skill_base_id']
115 );
116
117 $importSkillTrefId = $this->getImportMappingRegistry()->getMapping(
118 'components/ILIAS/Test',
119 'skl_tref_id_reverse',
120 (string) $skillData['skill_tref_id']
121 );
122
123 $levelThresholds = $this->getImportThresholdList()->getThresholdsByImportSkill(
124 $importSkillBaseId,
125 $importSkillTrefId
126 );
127
128 $existingLevels = $skill->getLevelData();
129
130 if (count($levelThresholds) != count($existingLevels)) {
131 $this->getFailedThresholdImportSkillList()->addSkill(
132 (int) $skillData['skill_base_id'],
133 (int) $skillData['skill_tref_id']
134 );
135
136 continue;
137 }
138
139 for ($i = 0, $max = count($existingLevels); $i < $max; $i++) {
140 $existingLevelData = $existingLevels[$i];
141
142 /* @var ilTestSkillLevelThresholdImport $importLevelThreshold */
143 $importLevelThreshold = $levelThresholds[$i];
144
145 if ($importLevelThreshold->getOrderIndex() != $existingLevelData['nr']) {
146 $this->getFailedThresholdImportSkillList()->addSkill(
147 (int) $skillData['skill_base_id'],
148 (int) $skillData['skill_tref_id']
149 );
150
151 continue(2);
152 }
153
154 if (!is_numeric($importLevelThreshold->getThreshold())) {
155 continue(2);
156 }
157
158 $mappedLevelId = $this->getLevelIdMapping($importLevelThreshold->getImportLevelId());
159
160 if ($mappedLevelId === null) {
161 continue(2);
162 }
163
164 $threshold = new ilTestSkillLevelThreshold($this->db);
165 $threshold->setTestId($this->getTargetTestId());
166 $threshold->setSkillBaseId($skillData['skill_base_id']);
167 $threshold->setSkillTrefId($skillData['skill_tref_id']);
168 $threshold->setSkillLevelId($mappedLevelId);
169 $threshold->setThreshold($importLevelThreshold->getThreshold());
170
171 $importedLevelThresholdList->addThreshold($threshold);
172 }
173 }
174
175 $importedLevelThresholdList->saveToDb();
176 }
177
178 protected function getLevelIdMapping(int $importLevelId): ?int
179 {
180 $result = ilBasicSkill::getLevelIdForImportId($this->getImportInstallationId(), $importLevelId);
181 $mostNewLevelData = current($result);
182 if (!is_array($mostNewLevelData)) {
183 return null;
184 }
185 return $mostNewLevelData['level_id'];
186 }
187}
static getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id)
setImportThresholdList(?ilTestSkillLevelThresholdImportList $importThresholdList)
setImportedQuestionSkillAssignmentList(ilAssQuestionSkillAssignmentList $importedQuestionSkillAssignmentList)
ilAssQuestionAssignedSkillList $failedThresholdImportSkillList
setFailedThresholdImportSkillList(ilAssQuestionAssignedSkillList $failedThresholdImportSkillList)
setImportMappingRegistry(ilImportMapping $importMappingRegistry)
ilTestSkillLevelThresholdImportList $importThresholdList
ilAssQuestionSkillAssignmentList $importedQuestionSkillAssignmentList
Interface ilDBInterface.