ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilAssQuestionSkillAssignmentImporter.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
29  protected $db;
30 
35 
40 
45 
54 
59 
64 
66 
70  public function __construct()
71  {
72  global $DIC;
73  $ilDB = $DIC['ilDB'];
74  $this->db = $ilDB;
75 
76  $this->targetParentObjId = null;
77  $this->importInstallationId = null;
78  $this->importMappingRegistry = null;
79  $this->importAssignmentList = null;
80  $this->failedImportAssignmentList = new ilAssQuestionSkillAssignmentImportList();
81  $this->successImportAssignmentList = new ilAssQuestionSkillAssignmentList($this->db);
82  $this->skillUsageService = $DIC->skills()->usage();
83  }
84 
89  {
90  $this->targetParentObjId = $targetParentObjId;
91  }
92 
96  public function getTargetParentObjId(): ?int
97  {
99  }
100 
104  public function getImportInstallationId(): ?int
105  {
107  }
108 
113  {
114  $this->importInstallationId = $importInstallationId;
115  }
116 
121  {
123  }
124 
129  {
130  $this->importMappingRegistry = $importMappingRegistry;
131  }
132 
136  public function getImportMappingComponent(): string
137  {
139  }
140 
145  {
146  $this->importMappingComponent = $importMappingComponent;
147  }
148 
153  {
155  }
156 
161  {
162  $this->importAssignmentList = $importAssignmentList;
163  }
164 
169  {
171  }
172 
177  {
179  }
180 
185  {
186  $this->successImportAssignmentList = $successImportAssignmentList;
187  }
188 
189  /*
190  $r = ilBasicSkill::getCommonSkillIdForImportId($a_source_inst_id,
191  $a_skill_import_id, $a_tref_import_id);
192 
193  $results[] = array("skill_id" => $rec["obj_id"], "tref_id" => $t,
194  "creation_date" => $rec["creation_date"]);
195  */
196 
197  public function import(): void
198  {
199  foreach ($this->getImportAssignmentList() as $assignment) {
200  $foundSkillId = $this->getSkillIdMapping(
201  $assignment->getImportSkillBaseId(),
202  $assignment->getImportSkillTrefId()
203  );
204 
205  if (!$this->isValidSkill($foundSkillId)) {
206  $this->getFailedImportAssignmentList()->addAssignment($assignment);
207  continue;
208  }
209 
210  $this->getImportMappingRegistry()->addMapping(
211  'components/ILIAS/Test',
212  'skl_base_id_reverse',
213  $foundSkillId['skill_id'],
214  $assignment->getImportSkillBaseId()
215  );
216 
217  $this->getImportMappingRegistry()->addMapping(
218  'components/ILIAS/Test',
219  'skl_tref_id_reverse',
220  $foundSkillId['tref_id'],
221  $assignment->getImportSkillTrefId()
222  );
223 
224  $importableAssignment = $this->buildImportableAssignment($assignment, $foundSkillId);
225 
226  foreach ($assignment->getImportSolutionComparisonExpressionList() as $solCompExp) {
227  $importableSolCompExp = $this->buildImportableSolutionComparisonExpression($solCompExp);
228  $importableAssignment->getSolutionComparisonExpressionList()->add($importableSolCompExp);
229  }
230 
231  $importableAssignment->saveToDb();
232  $importableAssignment->saveComparisonExpressions();
233 
234  // add skill usage
235  $this->skillUsageService->addUsage($this->getTargetParentObjId(), $foundSkillId['skill_id'], $foundSkillId['tref_id']);
236 
237  $this->getSuccessImportAssignmentList()->addAssignment($importableAssignment);
238  }
239  }
240 
242  {
243  $importableAssignment = new ilAssQuestionSkillAssignment($this->db);
244 
245  $importableAssignment->setEvalMode($assignment->getEvalMode());
246  $importableAssignment->setSkillPoints($assignment->getSkillPoints());
247 
248  $importableAssignment->setSkillBaseId($foundSkillId['skill_id']);
249  $importableAssignment->setSkillTrefId($foundSkillId['tref_id']);
250 
251  $importableAssignment->setParentObjId($this->getTargetParentObjId());
252 
253  $importableAssignment->setQuestionId($this->getImportMappingRegistry()->getMapping(
254  $this->getImportMappingComponent(),
255  'quest',
256  $assignment->getImportQuestionId()
257  ));
258 
259  $importableAssignment->initSolutionComparisonExpressionList();
260 
261  return $importableAssignment;
262  }
263 
265  {
266  $importableSolCompExp = new ilAssQuestionSolutionComparisonExpression($this->db);
267 
268  $importableSolCompExp->setOrderIndex($solCompExp->getOrderIndex());
269  $importableSolCompExp->setExpression($solCompExp->getExpression());
270  $importableSolCompExp->setPoints($solCompExp->getPoints());
271 
272  return $importableSolCompExp;
273  }
274 
275  protected function isValidSkill($foundSkillData): bool
276  {
277  if (!is_array($foundSkillData) || !isset($foundSkillData['skill_id']) || !$foundSkillData['skill_id']) {
278  return false;
279  }
280 
281  return true;
282  }
283 
284  protected function getSkillIdMapping($importSkillBaseId, $importSkillTrefId)
285  {
286  if ($this->getImportInstallationId() == $this->getLocalInstallationId()) {
287  return [ 'skill_id' => $importSkillBaseId, 'tref_id' => $importSkillTrefId ];
288  }
289 
291  $this->getImportInstallationId(),
292  $importSkillBaseId,
293  $importSkillTrefId
294  );
295 
296  return current($foundSkillData);
297  }
298 
299  protected function getLocalInstallationId(): ?string
300  {
301  global $DIC; /* @var ILIAS\DI\Container $DIC */
302 
303  return $DIC->settings()->get('inst_id', 0);
304  }
305 }
buildImportableAssignment(ilAssQuestionSkillAssignmentImport $assignment, $foundSkillId)
static getCommonSkillIdForImportId(int $a_source_inst_id, int $a_skill_import_id, int $a_tref_import_id=0)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
buildImportableSolutionComparisonExpression(ilAssQuestionSolutionComparisonExpressionImport $solCompExp)
__construct()
ilAssQuestionSkillAssignmentImporter constructor.