ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilAssQuestionSkillAssignmentsGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Data\Factory as DataFactory;
20use ILIAS\HTTP\Services as HTTP;
21use ILIAS\Refinery\Factory as Refinery;
29use ILIAS\UI\Factory as UIFactory;
30use ILIAS\UI\Renderer as UIRenderer;
32
47{
48 public const CMD_SHOW_SKILL_QUEST_ASSIGNS = 'showSkillQuestionAssignments';
49 public const CMD_EDIT_SKILL_QUEST_ASSIGNS = 'editSkillQuestionAssignment';
50 public const CMD_SHOW_SKILL_SELECT = 'showSkillSelection';
51 public const CMD_UPDATE_SKILL_QUEST_ASSIGNS = 'updateSkillQuestionAssignments';
52 public const CMD_SHOW_SKILL_QUEST_ASSIGN_PROPERTIES_FORM = 'showSkillQuestionAssignmentPropertiesForm';
53 public const CMD_SAVE_SKILL_QUEST_ASSIGN_PROPERTIES_FORM = 'saveSkillQuestionAssignmentPropertiesForm';
54 public const CMD_SAVE_SKILL_POINTS = 'saveSkillPoints';
55 public const CMD_SHOW_SYNC_ORIGINAL_CONFIRMATION = 'showSyncOriginalConfirmation';
56 public const CMD_SYNC_ORIGINAL = 'syncOriginal';
57
58 public const PARAM_SKILL_SELECTION = 'skill_ids';
59
64
66
67 private DataFactory $data_factory;
68
69 public function __construct(
70 private readonly ilCtrl $ctrl,
71 private readonly ilAccessHandler $access,
72 private readonly ilGlobalTemplateInterface $tpl,
73 private readonly ilLanguage $lng,
74 private readonly ilDBInterface $db,
75 private readonly RequestDataCollectorInterface $request_data_collector,
76 private readonly SkillUsageService $skill_usage_service,
77 private readonly UIFactory $ui_factory,
78 private readonly UIRenderer $ui_renderer,
79 private readonly Refinery $refinery,
80 private readonly HTTP $http,
81 private readonly ilToolbarGUI $toolbar,
82 private readonly ilTabsGUI $tabs
83 ) {
84 $this->data_factory = new DataFactory();
85 }
86
87 public function getQuestionOrderSequence(): ?array
88 {
90 }
91
92 public function getAssignmentConfigurationHintMessage(): ?string
93 {
95 }
96
97 public function setAssignmentConfigurationHintMessage(?string $assignmentConfigurationHintMessage): void
98 {
99 $this->assignment_configuration_hint_message = $assignmentConfigurationHintMessage;
100 }
101
106 {
107 $this->questionOrderSequence = $questionOrderSequence;
108 }
109
114 {
116 }
117
121 public function setQuestionList($questionList): void
122 {
123 $this->question_list = $questionList;
124 }
125
129 public function getQuestionContainerId(): int
130 {
132 }
133
137 public function setQuestionContainerId($questionContainerId): void
138 {
139 $this->question_container_id = $questionContainerId;
140 }
141
145 public function isAssignmentEditingEnabled(): bool
146 {
148 }
149
153 public function setAssignmentEditingEnabled($assignmentEditingEnabled): void
154 {
155 $this->assignment_editing_enabled = $assignmentEditingEnabled;
156 }
157
158 public function executeCommand(): void
159 {
160 $nextClass = $this->ctrl->getNextClass();
161
162 $command = $this->ctrl->getCmd(self::CMD_SHOW_SKILL_QUEST_ASSIGNS);
163
164 if ($this->isAvoidManipulationRedirectRequired($command)) {
165 $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_QUEST_ASSIGNS);
166 }
167
169
170 if (in_array($command, [self::CMD_EDIT_SKILL_QUEST_ASSIGNS])) {
171 $this->modifyTabs();
172 }
173
174 switch ($nextClass) {
175 case strtolower(__CLASS__):
176 case '':
177
178 $command .= 'Cmd';
179 $this->$command();
180 break;
181
182 default:
183
184 throw new ilTestQuestionPoolException('unsupported next class in ctrl flow');
185 }
186 }
187
188 private function modifyTabs(): void
189 {
190 $this->tabs->clearTargets();
191 $this->tabs->setBackTarget(
192 $this->lng->txt('back'),
193 $this->ctrl->getLinkTargetByClass(
194 ilAssQuestionSkillAssignmentsGUI::class,
196 )
197 );
198 $this->tabs->addTab(
199 strtolower(ilAssQuestionSkillAssignmentsGUI::class),
200 $this->lng->txt('qpl_skl_sub_tab_quest_assign'),
201 $this->ctrl->getLinkTargetByClass(
202 ilAssQuestionSkillAssignmentsGUI::class,
204 )
205 );
206 $this->tabs->activateTab(strtolower(ilAssQuestionSkillAssignmentsGUI::class));
207 }
208
209 private function isAvoidManipulationRedirectRequired($command): bool
210 {
211 if ($this->isAssignmentEditingEnabled()) {
212 return false;
213 }
214
215 switch ($command) {
218
219 return true;
220 }
221
222 return false;
223 }
224
225 private function saveSkillPointsCmd(): void
226 {
227 $success = true;
228 $skill_points = $this->request_data_collector->raw('skill_points');
229
230 for ($i = 0; $i < 2; $i++) {
231 foreach ($skill_points as $assignment_key => $skill_point) {
232 $assignment_key = explode(':', $assignment_key);
233 $skillBaseId = (int) $assignment_key[0];
234 $skillTrefId = (int) $assignment_key[1];
235 $questionId = (int) $assignment_key[2];
236
237 if ($this->isTestQuestion($questionId)) {
238 $assignment = new ilAssQuestionSkillAssignment($this->db);
239
240 if ($i === 0) {
241 if (!$assignment->isValidSkillPoint($skill_point)) {
242 $success = false;
243 break 2;
244 }
245 continue;
246 }
247
248 $assignment->setParentObjId($this->getQuestionContainerId());
249 $assignment->setQuestionId($questionId);
250 $assignment->setSkillBaseId($skillBaseId);
251 $assignment->setSkillTrefId($skillTrefId);
252
253 if ($assignment->dbRecordExists()) {
254 $assignment->loadFromDb();
255
256 if (!$assignment->hasEvalModeBySolution()) {
257 $assignment->setSkillPoints($skill_point);
258 $assignment->saveToDb();
259
260 // add skill usage
261 $this->skill_usage_service->addUsage($this->getQuestionContainerId(), $skillBaseId, $skillTrefId);
262 }
263 }
264 }
265
266 }
267 }
268
269 if ($success) {
270 $this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_msg_skl_qst_assign_points_saved'), true);
271 $this->ctrl->redirect($this, self::CMD_SHOW_SKILL_QUEST_ASSIGNS);
272 return;
273 }
274
275 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_msg_skl_qst_assign_points_not_saved'));
276 $this->showSkillQuestionAssignmentsCmd(true);
277 }
278
279 private function updateSkillQuestionAssignmentsCmd(): void
280 {
282 $question_id = $this->request_data_collector->getQuestionId();
283
284 if ($this->isTestQuestion($question_id)) {
285 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
286 $assignmentList->setParentObjId($this->getQuestionContainerId());
287 $assignmentList->loadFromDb();
288
289 $handledSkills = [];
290
291 $sgui = $this->buildSkillSelectorExplorerGUI([]);
292 $skillIds = $sgui->getSelectedSkills();
293
294 foreach ($skillIds as $skillId) {
295 $skill = explode(':', $skillId);
296 $skillBaseId = (int) $skill[0];
297 $skillTrefId = (int) $skill[1];
298
299 if ($skillBaseId) {
300 if (!$assignmentList->isAssignedToQuestionId($skillBaseId, $skillTrefId, $question_id)) {
301 $assignment = new ilAssQuestionSkillAssignment($this->db);
302
303 $assignment->setParentObjId($this->getQuestionContainerId());
304 $assignment->setQuestionId($question_id);
305 $assignment->setSkillBaseId($skillBaseId);
306 $assignment->setSkillTrefId($skillTrefId);
307
310 $assignment->saveToDb();
311
312 // add skill usage
313 $this->skill_usage_service->addUsage($this->getQuestionContainerId(), $skillBaseId, $skillTrefId);
314 }
315
316 $handledSkills[$skillId] = $skill;
317 }
318 }
319
320 foreach ($assignmentList->getAssignmentsByQuestionId($question_id) as $assignment) {
321 if (isset($handledSkills["{$assignment->getSkillBaseId()}:{$assignment->getSkillTrefId()}"])) {
322 continue;
323 }
324
325 $assignment->deleteFromDb();
326
327 // remove skill usage
328 if (!$assignment->isSkillUsed()) {
329 $this->skill_usage_service->removeUsage(
330 $assignment->getParentObjId(),
331 $assignment->getSkillBaseId(),
332 $assignment->getSkillTrefId()
333 );
334 }
335 }
336
337 $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_qst_skl_assigns_updated'), true);
338
339 if ($this->isSyncOriginalPossibleAndAllowed($question_id)) {
341 $this->ctrl->redirect($this, self::CMD_SHOW_SYNC_ORIGINAL_CONFIRMATION);
342 }
343 }
344
346 }
347
348 private function showSkillSelectionCmd(): void
349 {
351 $question_id = $this->request_data_collector->getQuestionId();
352
353 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
354 $assignmentList->setParentObjId($this->getQuestionContainerId());
355 $assignmentList->loadFromDb();
356
357 $skillSelectorExplorerGUI = $this->buildSkillSelectorExplorerGUI(
358 $assignmentList->getAssignmentsByQuestionId($question_id)
359 );
360
361 if (!$skillSelectorExplorerGUI->handleCommand()) {
362 $tpl = new ilTemplate('tpl.qpl_qst_skl_assign_selection.html', false, false, 'components/ILIAS/TestQuestionPool');
363
364 $tpl->setVariable('SKILL_SELECTOR_HEADER', $this->getSkillSelectorHeader($question_id));
365
366 $skillSelectorToolbarGUI = $this->buildSkillSelectorToolbarGUI();
367
368 $skillSelectorToolbarGUI->setOpenFormTag(true);
369 $skillSelectorToolbarGUI->setCloseFormTag(false);
370 $skillSelectorToolbarGUI->setLeadingImage(ilUtil::getImagePath("nav/arrow_upright.svg"), " ");
371 $tpl->setVariable('SKILL_SELECTOR_TOOLBAR_TOP', $this->ctrl->getHTML($skillSelectorToolbarGUI));
372
373 $tpl->setVariable('SKILL_SELECTOR_EXPLORER', $this->ctrl->getHTML($skillSelectorExplorerGUI));
374
375 $skillSelectorToolbarGUI->setOpenFormTag(false);
376 $skillSelectorToolbarGUI->setCloseFormTag(true);
377 $skillSelectorToolbarGUI->setLeadingImage(ilUtil::getImagePath("nav/arrow_downright.svg"), " ");
378 $tpl->setVariable('SKILL_SELECTOR_TOOLBAR_BOTTOM', $this->ctrl->getHTML($skillSelectorToolbarGUI));
379
380 $this->tpl->setContent($tpl->get());
381 }
382 }
383
385 ?assQuestionGUI $question_gui = null,
386 ?ilAssQuestionSkillAssignment $assignment = null,
387 ?ilPropertyFormGUI $form = null
388 ): void {
390
392
393 $question_id = $this->request_data_collector->getQuestionId();
394 $question_gui ??= assQuestionGUI::_getQuestionGUI('', $question_id);
395
396 $row_id_parameter = $this->request_data_collector->getRowIdParameter(EditSkillsOfQuestionTableActions::FULL_ROW_ID_PARAMETER);
397 [1 => $skill_base_id, 2 => $skill_tref_id] = explode('_', $row_id_parameter);
398 $assignment ??= $this->buildQuestionSkillAssignment($question_id, (int) $skill_base_id, (int) $skill_tref_id);
399
400 $form ??= $this->buildSkillQuestionAssignmentPropertiesForm($question_gui->getObject(), $assignment);
401
402 $this->tpl->setContent($form->getHTML() . '<br />' . $this->buildQuestionPage($question_gui));
403 }
404
406 {
407 $question_id = $this->request_data_collector->getQuestionId();
408
409 if ($this->isTestQuestion($question_id)) {
410 $question_gui = assQuestionGUI::_getQuestionGUI('', $question_id);
411
412 $row_id_parameter = $this->request_data_collector->getRowIdParameter(EditSkillsOfQuestionTableActions::FULL_ROW_ID_PARAMETER);
413 [1 => $skill_base_id, 2 => $skill_tref_id] = explode('_', $row_id_parameter);
414 $assignment = $this->buildQuestionSkillAssignment($question_id, (int) $skill_base_id, (int) $skill_tref_id);
415
416 $this->keepAssignmentParameters();
417 $form = $this->buildSkillQuestionAssignmentPropertiesForm($question_gui->getObject(), $assignment);
418 if (!$form->checkInput()
419 || !$this->checkPointsAreInt($form)) {
420 $form->setValuesByPost();
421 $this->showSkillQuestionAssignmentPropertiesFormCmd($question_gui, $assignment, $form);
422 return;
423 }
424 $form->setValuesByPost();
425
426 if ($form->getItemByPostVar('eval_mode')) {
427 $assignment->setEvalMode($form->getItemByPostVar('eval_mode')->getValue());
428 } else {
430 }
431
432 if ($assignment->hasEvalModeBySolution()) {
433 $sol_cmp_expr_input = $form->getItemByPostVar('solution_compare_expressions');
434
435 if (!$this->checkSolutionCompareExpressionInput($sol_cmp_expr_input, $question_gui->getObject())) {
436 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
437 $this->showSkillQuestionAssignmentPropertiesFormCmd($question_gui, $assignment, $form);
438 return;
439 }
440
441 $assignment->initSolutionComparisonExpressionList();
442 $assignment->getSolutionComparisonExpressionList()->reset();
443
444 foreach ($sol_cmp_expr_input->getValues() as $expression) {
445 $assignment->getSolutionComparisonExpressionList()->add($expression);
446 }
447 } else {
448 $assignment->setSkillPoints($form->getItemByPostVar('q_res_skill_points')->getValue());
449 }
450
451 $assignment->saveToDb();
452
453 // add skill usage
454 $this->skill_usage_service->addUsage(
455 $this->getQuestionContainerId(),
456 $this->request_data_collector->int('skill_base_id'),
457 $this->request_data_collector->int('skill_tref_id')
458 );
459
460 $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_qst_skl_assign_properties_modified'), true);
461
462 if ($this->isSyncOriginalPossibleAndAllowed($question_id)) {
463 $this->ctrl->redirect($this, self::CMD_SHOW_SYNC_ORIGINAL_CONFIRMATION);
464 }
465 }
466
467 $this->ctrl->redirect($this, self::CMD_EDIT_SKILL_QUEST_ASSIGNS);
468 }
469
471 assQuestion $question,
475 $form->setQuestion($question);
476 $form->setAssignment($assignment);
477 $form->setManipulationEnabled($this->isAssignmentEditingEnabled());
478 $form->build();
479
480 return $form;
481 }
482
483 private function showSkillQuestionAssignmentsCmd(bool $load_skill_points_from_request = false): void
484 {
485 $this->handleAssignmentConfigurationHintMessage();
486
487 $assignment_list = $this->buildSkillQuestionAssignmentList();
488 $assignment_list->loadFromDb();
489 $assignment_list->loadAdditionalSkillData();
490
492 $mode = $this->http->wrapper()->query()->retrieve(
493 SkillsByQuestionOverviewTable::VIEW_CONTROL_QUERY_PARAM,
494 $this->refinery->byTrying([
495 $this->refinery->kindlyTo()->string(),
496 $this->refinery->always(SkillAssignmentViewControlMode::ALL->value),
497 ])
498 );
499
500 $edit_uri = $this->data_factory->uri(
501 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
502 self::class,
503 self::CMD_EDIT_SKILL_QUEST_ASSIGNS
504 )
505 );
506
507 $this->tpl->setContent($this->ui_renderer->render(
509 $this->question_list,
510 $assignment_list,
511 $this->ui_factory,
512 $this->lng,
513 $this->ctrl,
514 ))->getComponents(
515 $edit_uri,
516 SkillAssignmentViewControlMode::tryFrom($mode) ?? SkillAssignmentViewControlMode::ALL
517 )
518 ));
519 }
520
521 private function editSkillQuestionAssignmentCmd(): void
522 {
523 $assignment_list = $this->buildSkillQuestionAssignmentList();
524 $assignment_list->loadFromDb();
525 $assignment_list->loadAdditionalSkillData();
526
527 $this->keepAssignmentParameters();
528
529 $edit_uri = $this->data_factory->uri(
530 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
531 self::class,
532 self::CMD_SHOW_SKILL_QUEST_ASSIGN_PROPERTIES_FORM
533 )
534 );
535
536 $this->ctrl->setParameterByClass(
537 ilAssQuestionSkillAssignmentsGUI::class,
538 'q_id',
539 $this->request_data_collector->getQuestionId()
540 );
541 $this->toolbar->addComponent(
542 $this->ui_factory->button()->standard(
543 $this->lng->txt('tst_manage_competence_select_skills'),
544 $this->ctrl->getLinkTargetByClass(
545 [ilAssQuestionSkillAssignmentsGUI::class],
546 self::CMD_SHOW_SKILL_SELECT
547 )
548 )->withUnavailableAction(!$this->isAssignmentEditingEnabled())
549 );
550 $this->ctrl->setParameterByClass(ilAssQuestionSkillAssignmentsGUI::class, 'q_id', null);
551
553 $this->request_data_collector,
554 $assignment_list,
555 $this->ui_factory,
556 $this->lng,
558 $this->tpl,
559 [
560 EditSkillsOfQuestionTableEditAction::ACTION_ID => new EditSkillsOfQuestionTableEditAction(
561 $this->ui_factory,
562 $this->lng,
563 $this->isAssignmentEditingEnabled()
564 )
565 ]
566 ))
567 ))->getComponents(new URLBuilder($edit_uri));
568
569 $this->tpl->setContent($this->ui_renderer->render($components));
570 }
571
572 private function isSyncOriginalPossibleAndAllowed(int $questionId): bool
573 {
574 $questionData = $this->question_list->getDataArrayForQuestionId($questionId);
575
576 if (!$questionData['original_id']) {
577 return false;
578 }
579
580 $parentObjId = assQuestion::lookupParentObjId($questionData['original_id']);
581
582 if ($parentObjId === null || !$this->doesObjectTypeMatch($parentObjId)) {
583 return false;
584 }
585
586 foreach (ilObject::_getAllReferences($parentObjId) as $parentRefId) {
587 if ($this->access->checkAccess('write', '', $parentRefId)) {
588 return true;
589 }
590 }
591
592 return false;
593 }
594
595 private function showSyncOriginalConfirmationCmd(): void
596 {
597 $confirmation = new ilConfirmationGUI();
598 $confirmation->setHeaderText($this->lng->txt('qpl_sync_quest_skl_assigns_confirmation'));
599
600 $confirmation->setFormAction($this->ctrl->getFormAction($this));
601 $confirmation->addHiddenItem('q_id', $this->request_data_collector->getQuestionId());
602 $confirmation->setConfirm($this->lng->txt('yes'), self::CMD_SYNC_ORIGINAL);
603 $confirmation->setCancel($this->lng->txt('no'), self::CMD_EDIT_SKILL_QUEST_ASSIGNS);
604
605 $this->tpl->setContent($this->ctrl->getHTML($confirmation));
606 }
607
608 private function syncOriginalCmd(): void
609 {
610 $question_id = $this->request_data_collector->getQuestionId();
611 if ($this->isTestQuestion($question_id) && $this->isSyncOriginalPossibleAndAllowed($question_id)) {
612 $question = assQuestion::instantiateQuestion($question_id);
613
614 $question->syncSkillAssignments(
615 $question->getObjId(),
616 $question->getId(),
617 $question->lookupParentObjId($question->getOriginalId()),
618 $question->getOriginalId()
619 );
620
621 $this->tpl->setOnScreenMessage('success', $this->lng->txt('qpl_qst_skl_assign_synced_to_orig'), true);
622 }
623
624 $this->ctrl->redirect($this, self::CMD_EDIT_SKILL_QUEST_ASSIGNS);
625 }
626
628 {
629 $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
630 $assignmentList->setParentObjId($this->getQuestionContainerId());
631
632 return $assignmentList;
633 }
634
638 private function buildSkillSelectorExplorerGUI($assignments): ilSkillSelectorGUI
639 {
640 $skillSelectorExplorerGUI = new ilSkillSelectorGUI(
641 $this,
642 self::CMD_SHOW_SKILL_SELECT,
643 $this,
644 self::CMD_UPDATE_SKILL_QUEST_ASSIGNS,
645 self::PARAM_SKILL_SELECTION
646 );
647
648 $skillSelectorExplorerGUI->setSelectMode(self::PARAM_SKILL_SELECTION, true);
649 //$skillSelectorExplorerGUI->setNodeOnclickEnabled(false);
650
651 // parameter name for skill selection is actually taken from value passed to constructor,
652 // but passing a non empty name to setSelectMode is neccessary to keep input fields enabled
653
654 foreach ($assignments as $assignment) {
655 $id = "{$assignment->getSkillBaseId()}:{$assignment->getSkillTrefId()}";
656 //$skillSelectorExplorerGUI->setNodeSelected($id);
657 $skillSelectorExplorerGUI->setSkillSelected($id);
658 }
659
660 return $skillSelectorExplorerGUI;
661 }
662
667 {
668 $skillSelectorToolbarGUI = new ilToolbarGUI();
669
670 $skillSelectorToolbarGUI->setFormAction($this->ctrl->getFormAction($this));
671 $skillSelectorToolbarGUI->addFormButton($this->lng->txt('qpl_save_skill_assigns_update'), self::CMD_UPDATE_SKILL_QUEST_ASSIGNS);
672 $skillSelectorToolbarGUI->addFormButton($this->lng->txt('qpl_cancel_skill_assigns_update'), self::CMD_EDIT_SKILL_QUEST_ASSIGNS);
673
674 return $skillSelectorToolbarGUI;
675 }
676
677 private function buildQuestionPage(assQuestionGUI $question_gui)
678 {
679 $this->tpl->addCss('./assets/css/content.css');
680
681 $page_gui = new ilAssQuestionPageGUI($question_gui->getObject()->getId());
682 $page_gui->setFileDownloadLink($question_gui->buildFileDownloadLink());
683 $page_gui->setOutputMode("presentation");
684 $page_gui->setRenderPageContainer(true);
685
686 $page_gui->setPresentationTitle($question_gui->getObject()->getTitleForHTMLOutput());
687
688 $question = $question_gui->getObject();
689 $question->setShuffle(false); // dirty, but works ^^
690 $question_gui->setObject($question);
691 $page_gui->setQuestionHTML([
692 $question_gui->getObject()->getId() => $question_gui->getSolutionOutput(0, 0, false, false, true, false, true, false, true)
693 ]);
694
695 return preg_replace("/src=\"\\.\\//ims", "src=\"" . ILIAS_HTTP_PATH . "/", $page_gui->presentation());
696
697 }
698
703 int $question_id,
704 int $skill_base_id,
705 int $skill_tref_id
707 $assignment = new ilAssQuestionSkillAssignment($this->db);
708
709 $assignment->setParentObjId($this->getQuestionContainerId());
710 $assignment->setQuestionId($question_id);
711 $assignment->setSkillBaseId($skill_base_id);
712 $assignment->setSkillTrefId($skill_tref_id);
713
714 $assignment->loadFromDb();
715 $assignment->loadAdditionalSkillData();
716
717 return $assignment;
718 }
719
720 private function isTestQuestion($questionId): bool
721 {
722 return $this->question_list->isInList($questionId);
723 }
724
725 private function checkSolutionCompareExpressionInput($input, assQuestion $question): bool
726 {
727 $errors = [];
728
729 foreach ($input->getValues() as $expression) {
730 $result = $this->validateSolutionCompareExpression($expression, $question);
731
732 if ($result !== true) {
733 $errors[] = "{$this->lng->txt('ass_lac_expression')} {$expression->getOrderIndex()}: {$result}";
734 }
735 }
736
737 if (count($errors)) {
738 $alert = $this->lng->txt('ass_lac_validation_error');
739 $alert .= '<br />' . implode('<br />', $errors);
740 $input->setAlert($alert);
741 return false;
742 }
743
744 return true;
745 }
746
747 private function checkPointsAreInt(ilPropertyFormGUI $form): bool
748 {
749 $points_result = $form->getInput('q_res_skill_points');
750 $invalid_values_solution = array_filter(
751 $form->getInput('solution_compare_expressions')['points'],
752 fn(string $v): bool => $v != (int) $v
753 );
754 if ($points_result == (int) $points_result
755 && $invalid_values_solution === []) {
756 return true;
757 }
758 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('numeric_only'));
759 return false;
760 }
761
763 {
764 try {
765 $question_provider = new ilAssLacQuestionProvider();
766 $question_provider->setQuestion($question);
767 (new ilAssLacCompositeValidator($question_provider))->validate(
768 (new ilAssLacConditionParser())->parse($expression->getExpression())
769 );
770 } catch (ilAssLacException $e) {
771 if ($e instanceof ilAssLacFormAlertProvider) {
772 return $e->getFormAlert($this->lng);
773 }
774
775 throw $e;
776 }
777
778 return true;
779 }
780
781 private function keepAssignmentParameters(): void
782 {
783 $this->ctrl->saveParameter($this, 'q_id');
784 $this->ctrl->saveParameter($this, 'skill_base_id');
785 $this->ctrl->saveParameter($this, 'skill_tref_id');
786 }
787
789 {
790 if ($this->getAssignmentConfigurationHintMessage()) {
791 $this->tpl->setOnScreenMessage('info', $this->getAssignmentConfigurationHintMessage());
792 }
793 }
794
795 private function getSkillSelectorHeader(int $questionId): string
796 {
797 return sprintf(
798 $this->lng->txt('qpl_qst_skl_selection_for_question_header'),
799 $this->question_list->getDataArrayForQuestionId($questionId)['title']
800 );
801 }
802
803 private function sortAlphabetically($array)
804 {
805 $flags = SORT_REGULAR;
806
807 if (defined('SORT_NATURAL')) {
808 $flags = SORT_NATURAL;
809 } elseif (defined('SORT_STRING')) {
810 $flags = SORT_STRING;
811 }
812
813 if (defined('SORT_FLAG_CASE')) {
814 $flags = $flags | SORT_FLAG_CASE;
815 }
816
817 asort($array, $flags);
818
819 return $array;
820 }
821
822 protected function doesObjectTypeMatch($objectId): bool
823 {
824 return ilObject::_lookupType($objectId) == 'qpl';
825 }
826}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$components
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
static _getQuestionGUI(string $question_type='', int $question_id=-1)
Creates a question gui representation and returns the alias to the question gui.
setObject(assQuestion $question)
getSolutionOutput(int $active_id, ?int $pass=null, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_inline_feedback=true)
static lookupParentObjId(int $question_id)
syncSkillAssignments(int $srcParentId, int $srcQuestionId, int $trgParentId, int $trgQuestionId)
setShuffle(?bool $shuffle=true)
static instantiateQuestion(int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Question page GUI class.
__construct(private readonly ilCtrl $ctrl, private readonly ilAccessHandler $access, private readonly ilGlobalTemplateInterface $tpl, private readonly ilLanguage $lng, private readonly ilDBInterface $db, private readonly RequestDataCollectorInterface $request_data_collector, private readonly SkillUsageService $skill_usage_service, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly Refinery $refinery, private readonly HTTP $http, private readonly ilToolbarGUI $toolbar, private readonly ilTabsGUI $tabs)
checkSolutionCompareExpressionInput($input, assQuestion $question)
setAssignmentConfigurationHintMessage(?string $assignmentConfigurationHintMessage)
showSkillQuestionAssignmentPropertiesFormCmd(?assQuestionGUI $question_gui=null, ?ilAssQuestionSkillAssignment $assignment=null, ?ilPropertyFormGUI $form=null)
buildQuestionSkillAssignment(int $question_id, int $skill_base_id, int $skill_tref_id)
validateSolutionCompareExpression(ilAssQuestionSolutionComparisonExpression $expression, $question)
buildSkillQuestionAssignmentPropertiesForm(assQuestion $question, ilAssQuestionSkillAssignment $assignment)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
Explorer class that works on tree objects (Services/Tree)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$http
Definition: deliver.php:30
@ ALL
event string being used if
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface ilDBInterface.
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:31