ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestSkillLevelThresholdImporter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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  {
45  return $this->targetTestId;
46  }
47 
48  public function setTargetTestId(int $targetTestId): void
49  {
50  $this->targetTestId = $targetTestId;
51  }
52 
53  public function getImportInstallationId(): ?int
54  {
56  }
57 
58  public function setImportInstallationId(int $importInstallationId): void
59  {
60  $this->importInstallationId = $importInstallationId;
61  }
62 
64  {
66  }
67 
68  public function setImportMappingRegistry(ilImportMapping $importMappingRegistry): void
69  {
70  $this->importMappingRegistry = $importMappingRegistry;
71  }
72 
74  {
76  }
77 
78  public function setImportedQuestionSkillAssignmentList(ilAssQuestionSkillAssignmentList $importedQuestionSkillAssignmentList): void
79  {
80  $this->importedQuestionSkillAssignmentList = $importedQuestionSkillAssignmentList;
81  }
82 
84  {
86  }
87 
88  public function setImportThresholdList(?ilTestSkillLevelThresholdImportList $importThresholdList): void
89  {
90  $this->importThresholdList = $importThresholdList;
91  }
92 
94  {
96  }
97 
98  public function setFailedThresholdImportSkillList(ilAssQuestionAssignedSkillList $failedThresholdImportSkillList): void
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  $threshold = new ilTestSkillLevelThreshold($this->db);
161  $threshold->setTestId($this->getTargetTestId());
162  $threshold->setSkillBaseId($skillData['skill_base_id']);
163  $threshold->setSkillTrefId($skillData['skill_tref_id']);
164  $threshold->setSkillLevelId($mappedLevelId);
165  $threshold->setThreshold($importLevelThreshold->getThreshold());
166 
167  $importedLevelThresholdList->addThreshold($threshold);
168  }
169  }
170 
171  $importedLevelThresholdList->saveToDb();
172  }
173 
174  protected function getLevelIdMapping(int $importLevelId): int
175  {
176  $result = ilBasicSkill::getLevelIdForImportId($this->getImportInstallationId(), $importLevelId);
177  $mostNewLevelData = current($result);
178  return $mostNewLevelData['level_id'];
179  }
180 }
setImportedQuestionSkillAssignmentList(ilAssQuestionSkillAssignmentList $importedQuestionSkillAssignmentList)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setImportThresholdList(?ilTestSkillLevelThresholdImportList $importThresholdList)
ilTestSkillLevelThresholdImportList $importThresholdList
setFailedThresholdImportSkillList(ilAssQuestionAssignedSkillList $failedThresholdImportSkillList)
setImportMappingRegistry(ilImportMapping $importMappingRegistry)
static getLevelIdForImportId(int $a_source_inst_id, int $a_level_import_id)
ilAssQuestionAssignedSkillList $failedThresholdImportSkillList
ilAssQuestionSkillAssignmentList $importedQuestionSkillAssignmentList