ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestSkillLevelThresholdImporter.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Skill/classes/class.ilBasicSkill.php';
5 require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdList.php';
6 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionAssignedSkillList.php';
7 
15 {
19  protected $targetTestId = null;
20 
24  protected $importInstallationId = null;
25 
29  protected $importMappingRegistry = null;
30 
35 
39  protected $importThresholdList = null;
40 
45 
49  public function __construct()
50  {
51  $this->failedThresholdImportSkillList = new ilAssQuestionAssignedSkillList();
52  }
53 
57  public function getTargetTestId()
58  {
59  return $this->targetTestId;
60  }
61 
65  public function setTargetTestId($targetTestId)
66  {
67  $this->targetTestId = $targetTestId;
68  }
69 
73  public function getImportInstallationId()
74  {
76  }
77 
82  {
83  $this->importInstallationId = $importInstallationId;
84  }
85 
89  public function getImportMappingRegistry()
90  {
92  }
93 
98  {
99  $this->importMappingRegistry = $importMappingRegistry;
100  }
101 
106  {
108  }
109 
114  {
115  $this->importedQuestionSkillAssignmentList = $importedQuestionSkillAssignmentList;
116  }
117 
121  public function getImportThresholdList()
122  {
124  }
125 
130  {
131  $this->importThresholdList = $importThresholdList;
132  }
133 
138  {
140  }
141 
146  {
147  $this->failedThresholdImportSkillList = $failedThresholdImportSkillList;
148  }
149 
152  public function import()
153  {
154  global $DIC;
155  $ilDB = $DIC['ilDB'];
156 
157  $importedLevelThresholdList = new ilTestSkillLevelThresholdList($ilDB);
158 
159  foreach ($this->getImportedQuestionSkillAssignmentList()->getUniqueAssignedSkills() as $skillData) {
160  /* @var ilBasicSkill $skill */
161  $skill = $skillData['skill'];
162 
163  $importSkillBaseId = $this->getImportMappingRegistry()->getMapping(
164  'Modules/Test',
165  'skl_base_id_reverse',
166  $skillData['skill_base_id']
167  );
168 
169  $importSkillTrefId = $this->getImportMappingRegistry()->getMapping(
170  'Modules/Test',
171  'skl_tref_id_reverse',
172  $skillData['skill_tref_id']
173  );
174 
175  $levelThresholds = $this->getImportThresholdList()->getThresholdsByImportSkill(
176  $importSkillBaseId,
177  $importSkillTrefId
178  );
179 
180  $existingLevels = $skill->getLevelData();
181 
182  if (count($levelThresholds) != count($existingLevels)) {
183  $this->getFailedThresholdImportSkillList()->addSkill(
184  $skillData['skill_base_id'],
185  $skillData['skill_tref_id']
186  );
187 
188  continue;
189  }
190 
191  for ($i = 0, $max = count($existingLevels); $i < $max; $i++) {
192  $existingLevelData = $existingLevels[$i];
193 
194  /* @var ilTestSkillLevelThresholdImport $importLevelThreshold */
195  $importLevelThreshold = $levelThresholds[$i];
196 
197  if ($importLevelThreshold->getOrderIndex() != $existingLevelData['nr']) {
198  $this->getFailedThresholdImportSkillList()->addSkill(
199  $skillData['skill_base_id'],
200  $skillData['skill_tref_id']
201  );
202 
203  continue(2);
204  }
205 
206  if (!is_numeric($importLevelThreshold->getThreshold())) {
207  continue(2);
208  }
209 
210  $mappedLevelId = $this->getLevelIdMapping($importLevelThreshold->getImportLevelId());
211 
212  $threshold = new ilTestSkillLevelThreshold($ilDB);
213  $threshold->setTestId($this->getTargetTestId());
214  $threshold->setSkillBaseId($skillData['skill_base_id']);
215  $threshold->setSkillTrefId($skillData['skill_tref_id']);
216  $threshold->setSkillLevelId($mappedLevelId);
217  $threshold->setThreshold($importLevelThreshold->getThreshold());
218 
219  $importedLevelThresholdList->addThreshold($threshold);
220  }
221  }
222 
223  $importedLevelThresholdList->saveToDb();
224  }
225 
230  protected function getLevelIdMapping($importLevelId)
231  {
232  /*
233  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
234  $r = ilBasicSkill::getLevelIdForImportId($a_source_inst_id,
235  $a_level_import_id);
236 
237  $results[] = array("level_id" => $rec["id"], "creation_date" =>
238  $rec["creation_date"]);
239  */
240 
242  $mostNewLevelData = current($result);
243  return $mostNewLevelData['level_id'];
244  }
245 }
$result
global $DIC
Definition: saml.php:7
static getLevelIdForImportId($a_source_inst_id, $a_level_import_id)
Get level ids for import IDs (newest first)
__construct()
ilTestSkillLevelThresholdImporter constructor.
setFailedThresholdImportSkillList($failedThresholdImportSkillList)
setImportedQuestionSkillAssignmentList($importedQuestionSkillAssignmentList)
global $ilDB
$i
Definition: disco.tpl.php:19