ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilDB;
155 
156  $importedLevelThresholdList = new ilTestSkillLevelThresholdList($ilDB);
157 
158  foreach($this->getImportedQuestionSkillAssignmentList()->getUniqueAssignedSkills() as $skillData)
159  {
160  /* @var ilBasicSkill $skill */
161  $skill = $skillData['skill'];
162 
163  $importSkillBaseId = $this->getImportMappingRegistry()->getMapping(
164  'Modules/Test', 'skl_base_id_reverse', $skillData['skill_base_id']
165  );
166 
167  $importSkillTrefId = $this->getImportMappingRegistry()->getMapping(
168  'Modules/Test', 'skl_tref_id_reverse', $skillData['skill_tref_id']
169  );
170 
171  $levelThresholds = $this->getImportThresholdList()->getThresholdsByImportSkill(
172  $importSkillBaseId, $importSkillTrefId
173  );
174 
175  $existingLevels = $skill->getLevelData();
176 
177  if( count($levelThresholds) != count($existingLevels) )
178  {
179  $this->getFailedThresholdImportSkillList()->addSkill(
180  $skillData['skill_base_id'], $skillData['skill_tref_id']
181  );
182 
183  continue;
184  }
185 
186  for($i = 0, $max = count($existingLevels); $i < $max; $i++)
187  {
188  $existingLevelData = $existingLevels[$i];
189 
190  /* @var ilTestSkillLevelThresholdImport $importLevelThreshold */
191  $importLevelThreshold = $levelThresholds[$i];
192 
193  if( $importLevelThreshold->getOrderIndex() != $existingLevelData['nr'] )
194  {
195  $this->getFailedThresholdImportSkillList()->addSkill(
196  $skillData['skill_base_id'], $skillData['skill_tref_id']
197  );
198 
199  continue(2);
200  }
201 
202  if( !is_numeric($importLevelThreshold->getThreshold()) )
203  {
204  continue(2);
205  }
206 
207  $mappedLevelId = $this->getLevelIdMapping($importLevelThreshold->getImportLevelId());
208 
209  $threshold = new ilTestSkillLevelThreshold($ilDB);
210  $threshold->setTestId($this->getTargetTestId());
211  $threshold->setSkillBaseId($skillData['skill_base_id']);
212  $threshold->setSkillTrefId($skillData['skill_tref_id']);
213  $threshold->setSkillLevelId($mappedLevelId);
214  $threshold->setThreshold($importLevelThreshold->getThreshold());
215 
216  $importedLevelThresholdList->addThreshold($threshold);
217  }
218  }
219 
220  $importedLevelThresholdList->saveToDb();
221  }
222 
227  protected function getLevelIdMapping($importLevelId)
228  {
229  /*
230  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
231  $r = ilBasicSkill::getLevelIdForImportId($a_source_inst_id,
232  $a_level_import_id);
233 
234  $results[] = array("level_id" => $rec["id"], "creation_date" =>
235  $rec["creation_date"]);
236  */
237 
239  $mostNewLevelData = current($result);
240  return $mostNewLevelData['level_id'];
241  }
242 }
$result
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