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