ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssQuestionSkillAssignmentImporter.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/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
6 
14 {
15  protected $db;
16 
21 
26 
31 
40 
45 
50 
54  public function __construct()
55  {
56  global $ilDB;
57  $this->db = $ilDB;
58 
59  $this->targetParentObjId = null;
60  $this->importInstallationId = null;
61  $this->importMappingRegistry = null;
62  $this->importAssignmentList = null;
63  $this->failedImportAssignmentList = new ilAssQuestionSkillAssignmentImportList();
64  $this->successImportAssignmentList = new ilAssQuestionSkillAssignmentList($this->db);
65  }
66 
71  {
72  $this->targetParentObjId = $targetParentObjId;
73  }
74 
78  public function getTargetParentObjId()
79  {
81  }
82 
86  public function getImportInstallationId()
87  {
89  }
90 
95  {
96  $this->importInstallationId = $importInstallationId;
97  }
98 
102  public function getImportMappingRegistry()
103  {
105  }
106 
111  {
112  $this->importMappingRegistry = $importMappingRegistry;
113  }
114 
118  public function getImportMappingComponent()
119  {
121  }
122 
127  {
128  $this->importMappingComponent = $importMappingComponent;
129  }
130 
134  public function getImportAssignmentList()
135  {
137  }
138 
143  {
144  $this->importAssignmentList = $importAssignmentList;
145  }
146 
151  {
153  }
154 
159  {
161  }
162 
167  {
168  $this->successImportAssignmentList = $successImportAssignmentList;
169  }
170 
171  /*
172  $r = ilBasicSkill::getCommonSkillIdForImportId($a_source_inst_id,
173  $a_skill_import_id, $a_tref_import_id);
174 
175  $results[] = array("skill_id" => $rec["obj_id"], "tref_id" => $t,
176  "creation_date" => $rec["creation_date"]);
177  */
178 
182  public function import()
183  {
184  foreach($this->getImportAssignmentList() as $assignment)
185  {
186  $foundSkillId = $this->getSkillIdMapping(
187  $assignment->getImportSkillBaseId(), $assignment->getImportSkillTrefId()
188  );
189 
190  if( !$this->isValidSkill($foundSkillId) )
191  {
192  $this->getFailedImportAssignmentList()->addAssignment($assignment);
193  continue;
194  }
195 
196  $this->getImportMappingRegistry()->addMapping(
197  'Modules/Test', 'skl_base_id_reverse', $foundSkillId['skill_id'], $assignment->getImportSkillBaseId()
198  );
199 
200  $this->getImportMappingRegistry()->addMapping(
201  'Modules/Test', 'skl_tref_id_reverse', $foundSkillId['tref_id'], $assignment->getImportSkillTrefId()
202  );
203 
204  $importableAssignment = $this->buildImportableAssignment($assignment, $foundSkillId);
205 
206  foreach($assignment->getImportSolutionComparisonExpressionList() as $solCompExp)
207  {
208  $importableSolCompExp = $this->buildImportableSolutionComparisonExpression($solCompExp);
209  $importableAssignment->getSolutionComparisonExpressionList()->add($importableSolCompExp);
210  }
211 
212  $importableAssignment->saveToDb();
213  $importableAssignment->saveComparisonExpressions();
214 
215  $this->getSuccessImportAssignmentList()->addAssignment($importableAssignment);
216  }
217  }
218 
219  protected function buildImportableAssignment(ilAssQuestionSkillAssignmentImport $assignment, $foundSkillId)
220  {
221  $importableAssignment = new ilAssQuestionSkillAssignment($this->db);
222 
223  $importableAssignment->setEvalMode($assignment->getEvalMode());
224  $importableAssignment->setSkillPoints($assignment->getSkillPoints());
225 
226  $importableAssignment->setSkillBaseId($foundSkillId['skill_id']);
227  $importableAssignment->setSkillTrefId($foundSkillId['tref_id']);
228 
229  $importableAssignment->setParentObjId($this->getTargetParentObjId());
230 
231  $importableAssignment->setQuestionId($this->getImportMappingRegistry()->getMapping(
232  $this->getImportMappingComponent(), 'quest', $assignment->getImportQuestionId()
233  ));
234 
235  $importableAssignment->initSolutionComparisonExpressionList();
236 
237  return $importableAssignment;
238  }
239 
241  {
242  $importableSolCompExp = new ilAssQuestionSolutionComparisonExpression($this->db);
243 
244  $importableSolCompExp->setOrderIndex($solCompExp->getOrderIndex());
245  $importableSolCompExp->setExpression($solCompExp->getExpression());
246  $importableSolCompExp->setPoints($solCompExp->getPoints());
247 
248  return $importableSolCompExp;
249  }
250 
251  protected function isValidSkill($foundSkillData)
252  {
253  if( !is_array($foundSkillData) || !isset($foundSkillData['skill_id']) || !$foundSkillData['skill_id'] )
254  {
255  return false;
256  }
257 
258  return true;
259  }
260 
261  protected function getSkillIdMapping($importSkillBaseId, $importSkillTrefId)
262  {
263  if( $this->getImportInstallationId() == $this->getLocalInstallationId() )
264  {
265  return array( 'skill_id' => $importSkillBaseId, 'tref_id' => $importSkillTrefId );
266  }
267 
269  $this->getImportInstallationId(), $importSkillBaseId, $importSkillTrefId
270  );
271 
272  return current($foundSkillData);
273  }
274 
275  protected function getLocalInstallationId()
276  {
277  global $DIC; /* @var ILIAS\DI\Container $DIC */
278 
279  return $DIC->settings()->get('inst_id', 0);
280  }
281 }
buildImportableAssignment(ilAssQuestionSkillAssignmentImport $assignment, $foundSkillId)
Create styles array
The data for the language used.
global $ilDB
buildImportableSolutionComparisonExpression(ilAssQuestionSolutionComparisonExpressionImport $solCompExp)
global $DIC
static getCommonSkillIdForImportId($a_source_inst_id, $a_skill_import_id, $a_tref_import_id=0)
Get common skill ids for import IDs (newest first)
__construct()
ilAssQuestionSkillAssignmentImporter constructor.