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