ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestRandomQuestionSetConfigGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfig.php';
5require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
6require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
7require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
8require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfigStateMessageHandler.php';
9
10require_once 'Services/Taxonomy/classes/class.ilObjTaxonomy.php';
11
28{
29 const CMD_SHOW_GENERAL_CONFIG_FORM = 'showGeneralConfigForm';
30 const CMD_SAVE_GENERAL_CONFIG_FORM = 'saveGeneralConfigForm';
31 const CMD_SHOW_SRC_POOL_DEF_LIST = 'showSourcePoolDefinitionList';
32 const CMD_SAVE_SRC_POOL_DEF_LIST = 'saveSourcePoolDefinitionList';
33 const CMD_DELETE_SINGLE_SRC_POOL_DEF = 'deleteSingleSourcePoolDefinition';
34 const CMD_DELETE_MULTI_SRC_POOL_DEFS = 'deleteMultipleSourcePoolDefinitions';
35 const CMD_SHOW_POOL_SELECTOR_EXPLORER = 'showPoolSelectorExplorer';
36 const CMD_SHOW_CREATE_SRC_POOL_DEF_FORM = 'showCreateSourcePoolDefinitionForm';
37 const CMD_SAVE_CREATE_SRC_POOL_DEF_FORM = 'saveCreateSourcePoolDefinitionForm';
38 const CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM = 'saveCreateAndNewSourcePoolDefinitionForm';
39 const CMD_SHOW_EDIT_SRC_POOL_DEF_FORM = 'showEditSourcePoolDefinitionForm';
40 const CMD_SAVE_EDIT_SRC_POOL_DEF_FORM = 'saveEditSourcePoolDefinitionForm';
41 const CMD_BUILD_QUESTION_STAGE = 'buildQuestionStage';
42 const CMD_SELECT_DERIVATION_TARGET = 'selectPoolDerivationTarget';
43 const CMD_DERIVE_NEW_POOLS = 'deriveNewPools';
44 const CMD_RESET_POOLSYNC = 'resetPoolSync';
45
46 const HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD = 'afterRebuildQuestionStageCmd';
50 public $ctrl = null;
51
55 public $access = null;
56
60 public $tabs = null;
61
65 public $lng = null;
66
70 public $tpl = null;
71
75 public $db = null;
76
80 public $tree = null;
81
85 public $pluginAdmin = null;
86
90 public $objDefinition = null;
91
95 public $testOBJ = null;
96
100 protected $questionSetConfig = null;
101
106
111
115 protected $stagingPool = null;
116
125
129 protected $dic;
130
131 public function __construct(
142 ) {
143 $this->ctrl = $ctrl;
144 $this->access = $access;
145 $this->tabs = $tabs;
146 $this->lng = $lng;
147 $this->tpl = $tpl;
148 $this->db = $db;
149 $this->tree = $tree;
150 $this->pluginAdmin = $pluginAdmin;
151 $this->testOBJ = $testOBJ;
152
153 global $DIC;
154 $this->dic = $DIC;
155 $this->objDefinition = $this->dic['objDefinition'];
156
157 $this->questionSetConfig = new ilTestRandomQuestionSetConfig(
158 $this->tree,
159 $this->db,
160 $this->pluginAdmin,
161 $this->testOBJ
162 );
163 $this->questionSetConfig->loadFromDb();
164
165 $this->sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
166 $this->db,
167 $this->testOBJ
168 );
169
170 $this->sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
171 $this->db,
172 $this->testOBJ,
173 $this->sourcePoolDefinitionFactory
174 );
175
176 $this->sourcePoolDefinitionList->loadDefinitions();
177
178 $this->stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder(
179 $this->db,
180 $this->testOBJ
181 );
182
183 $this->configStateMessageHandler = new ilTestRandomQuestionSetConfigStateMessageHandler(
184 $this->lng,
185 $this->ctrl
186 );
187
188 $this->configStateMessageHandler->setTargetGUI($this);
189 $this->configStateMessageHandler->setQuestionSetConfig($this->questionSetConfig);
190 $this->configStateMessageHandler->setParticipantDataExists($this->testOBJ->participantDataExist());
191 $this->configStateMessageHandler->setLostPools($this->sourcePoolDefinitionList->getLostPools());
192 $this->processLockerFactory = $processLockerFactory;
193 }
194
195 public function executeCommand()
196 {
197 if (!$this->access->checkAccess("write", "", $this->testOBJ->getRefId())) {
198 ilUtil::sendFailure($this->lng->txt("cannot_edit_test"), true);
199 $this->ctrl->redirectByClass('ilObjTestGUI', "infoScreen");
200 }
201
203 ilUtil::sendFailure($this->lng->txt("tst_msg_cannot_modify_random_question_set_conf_due_to_part"), true);
204 $this->ctrl->redirect($this);
205 }
206
207 $this->handleTabs();
208
209 $nextClass = $this->ctrl->getNextClass();
210
211 switch ($nextClass) {
212 case 'iltestrandomquestionsetpooldefinitionformgui':
213 $this->questionSetConfig->loadFromDb();
214 $poolId = $this->fetchQuestionPoolIdParameter();
215 $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
216 $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
218 $form->build($sourcePoolDefinition, $availableTaxonomyIds);
219
220 $this->ctrl->forwardCommand($form);
221 break;
222
223 default:
224
225 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM) . 'Cmd';
226
227 $this->$cmd();
228 }
229 }
230
232 {
233 if (!$this->isFrozenConfigRequired()) {
234 return false;
235 }
236
237 if (!$this->isManipulationCommand()) {
238 return false;
239 }
240
241 return true;
242 }
243
244 private function isFrozenConfigRequired()
245 {
246 if ($this->testOBJ->participantDataExist()) {
247 return true;
248 }
249
250 if ($this->sourcePoolDefinitionList->hasLostPool()) {
251 return true;
252 }
253
254 return false;
255 }
256
257 private function isManipulationCommand()
258 {
259 switch ($this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM)) {
268
269 return true;
270 }
271
272 return false;
273 }
274
275 private function handleTabs()
276 {
277 $this->tabs->activateTab('assQuestions');
278
279 $this->tabs->addSubTab(
280 'tstRandQuestSetGeneralConfig',
282 $this->ctrl->getLinkTarget($this, self::CMD_SHOW_GENERAL_CONFIG_FORM)
283 );
284
285 $this->tabs->addSubTab(
286 'tstRandQuestSetPoolConfig',
287 $this->getPoolConfigTabLabel(),
288 $this->ctrl->getLinkTarget($this, self::CMD_SHOW_SRC_POOL_DEF_LIST)
289 );
290
291 switch ($this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM)) {
294
295 $this->tabs->activateSubTab('tstRandQuestSetGeneralConfig');
296 break;
297
306
307 $this->tabs->activateSubTab('tstRandQuestSetPoolConfig');
308 break;
309
310 default: $this->tabs->activateSubTab('nonTab');
311 }
312 }
313
314 private function buildQuestionStageCmd() : void
315 {
316 if ($this->sourcePoolDefinitionList->areAllUsedPoolsAvailable()) {
317 $locker = $this->processLockerFactory->retrieveLockerForNamedOperation();
318 $locker->executeNamedOperation(__FUNCTION__, function () : void {
319 $this->stagingPool->rebuild($this->sourcePoolDefinitionList);
320 $this->sourcePoolDefinitionList->saveDefinitions();
321
322 $this->questionSetConfig->loadFromDb();
323 $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
324 $this->questionSetConfig->saveToDb();
325
326 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
327
328 ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_synced"), true);
329 });
330 }
331
332 $this->ctrl->redirect($this, $this->fetchAfterRebuildQuestionStageCmdParameter());
333 }
334
336 {
337 if (!isset($_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD])) {
339 }
340
341 if (!strlen($_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD])) {
343 }
344
346 }
347
349 {
350 $disabled_form = $this->preventFormBecauseOfSync();
351
352 if ($form === null) {
353 $this->questionSetConfig->loadFromDb();
354 $form = $this->buildGeneralConfigFormGUI($disabled_form);
355 }
356
357 $this->tpl->setContent($this->ctrl->getHTML($form));
358
359 if (!$disabled_form) {
360 $this->configStateMessageHandler->setContext(
362 );
363
364 $this->configStateMessageHandler->handle();
365
366 if ($this->configStateMessageHandler->hasValidationReports()) {
367 if ($this->configStateMessageHandler->isValidationFailed()) {
369 $this->configStateMessageHandler->getValidationReportHtml()
370 );
371 } else {
372 ilUtil::sendInfo($this->configStateMessageHandler->getValidationReportHtml());
373 }
374 }
375
376 if (isset($_GET['modified']) && (int) $_GET['modified']) {
377 ilUtil::sendSuccess($this->getGeneralModificationSuccessMessage());
378 }
379 }
380 }
381
382 private function saveGeneralConfigFormCmd()
383 {
384 $form = $this->buildGeneralConfigFormGUI();
385
386 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
387 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
388
389 if ($errors) {
390 return $this->showGeneralConfigFormCmd($form);
391 }
392
393 $form->save();
394
395 $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
396 $this->questionSetConfig->saveToDb();
397
398 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
399
400 $this->ctrl->setParameter($this, 'modified', 1);
401 $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
402 }
403
405 {
406 require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetGeneralConfigFormGUI.php';
407
409 $this->ctrl,
410 $this->lng,
411 $this->testOBJ,
412 $this,
413 $this->questionSetConfig
414 );
415
416 //TODO: should frozen config not lead to 'completely disabled' as well?!
417 $form->setEditModeEnabled(!$this->isFrozenConfigRequired());
418
419 if ($disabled) {
420 $form->setEditModeEnabled(false);
421 }
422
423 $form->build();
424
425 if ($disabled) {
426 $form->clearCommandButtons();
427 }
428
429 return $form;
430 }
431
433 {
434 $this->questionSetConfig->loadFromDb();
435
436 $disabled_form = $this->preventFormBecauseOfSync();
437
438 $content = '';
439
440 if (!$this->isFrozenConfigRequired() && !$disabled_form) {
441 $toolbar = $this->buildSourcePoolDefinitionListToolbarGUI();
442 $content .= $this->ctrl->getHTML($toolbar);
443 }
444
445 $table = $this->buildSourcePoolDefinitionListTableGUI($disabled_form);
446 $table->init($this->sourcePoolDefinitionList);
447 $content .= $this->ctrl->getHTML($table);
448
449 if (!$this->sourcePoolDefinitionList->areAllUsedPoolsAvailable()) {
450 $table = $this->buildNonAvailablePoolsTableGUI();
451 $table->init($this->sourcePoolDefinitionList);
452 $content .= $this->ctrl->getHTML($table);
453 }
454
455 $this->tpl->setContent($content);
456
457 if ($disabled_form) {
458 return;
459 }
460
461 $this->configStateMessageHandler->setContext(
463 );
464
465 $this->configStateMessageHandler->handle();
466
467 if ($this->configStateMessageHandler->hasValidationReports()) {
468 if ($this->configStateMessageHandler->isValidationFailed()) {
470 $this->configStateMessageHandler->getValidationReportHtml()
471 );
472 } else {
473 ilUtil::sendInfo($this->configStateMessageHandler->getValidationReportHtml());
474 }
475 }
476
477 if (isset($_GET['modified']) && (int) $_GET['modified']) {
478 ilUtil::sendSuccess($this->getGeneralModificationSuccessMessage());
479 }
480 }
481
483 {
484 $this->questionSetConfig->loadFromDb();
485
487
488 $table->applySubmit($this->sourcePoolDefinitionList);
489
490 $this->sourcePoolDefinitionList->reindexPositions();
491 $this->sourcePoolDefinitionList->saveDefinitions();
492
493 // fau: delayCopyRandomQuestions - don't rebuild the staging pool, just clear the sycn timestamp
494 #$this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
495 #$this->sourcePoolDefinitionList->saveDefinitions();
496 #$this->questionSetConfig->setLastQuestionSyncTimestamp(time());
497 $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
498 // fau.
499 $this->questionSetConfig->saveToDb();
500
501 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
502
503 $this->ctrl->setParameter($this, 'modified', 1);
504 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
505 }
506
508 {
509 require_once 'Modules/Test/classes/toolbars/class.ilTestRandomQuestionSetSourcePoolDefinitionListToolbarGUI.php';
510
512 $this->ctrl,
513 $this->lng,
514 $this,
515 $this->questionSetConfig
516 );
517
518 $toolbar->build();
519
520 return $toolbar;
521 }
522
524 {
525 require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php';
526
528 $this->ctrl,
529 $this->lng,
530 $this,
531 self::CMD_SHOW_SRC_POOL_DEF_LIST
532 );
533
534 if (!$this->isFrozenConfigRequired()) {
535 $table->setDefinitionEditModeEnabled(true);
536 }
537
538 $table->setQuestionAmountColumnEnabled(
539 $this->questionSetConfig->isQuestionAmountConfigurationModePerPool()
540 );
541
542 // fau: taxFilter/typeFilter - show the mapped taxonomy filters if pools are synced
543 $table->setShowMappedTaxonomyFilter(
544 $this->questionSetConfig->getLastQuestionSyncTimestamp() != 0
545 );
546 // fau.
547
548 require_once 'Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php';
549 $translater = new ilTestTaxonomyFilterLabelTranslater($this->db);
550 $translater->loadLabels($this->sourcePoolDefinitionList);
551 $table->setTaxonomyFilterLabelTranslater($translater);
552
553 if ($disabled) {
554 $table->setDefinitionEditModeEnabled(false);
555 }
556 $table->build();
557
558 return $table;
559 }
560
562 {
563 require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetNonAvailablePoolsTableGUI.php';
564
566 $this->ctrl,
567 $this->lng,
568 $this,
569 self::CMD_SHOW_SRC_POOL_DEF_LIST
570 );
571
572 $table->build();
573
574 return $table;
575 }
576
578 {
579 $definitionId = $this->fetchSingleSourcePoolDefinitionIdParameter();
580 $this->deleteSourcePoolDefinitions(array($definitionId));
581
582 ilUtil::sendSuccess($this->lng->txt("tst_msg_source_pool_definitions_deleted"), true);
583 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
584 }
585
587 {
588 $definitionIds = $this->fetchMultiSourcePoolDefinitionIdsParameter();
589 $this->deleteSourcePoolDefinitions($definitionIds);
590
591 ilUtil::sendSuccess($this->lng->txt("tst_msg_source_pool_definitions_deleted"), true);
592 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
593 }
594
595 private function deleteSourcePoolDefinitions($definitionIds)
596 {
597 foreach ($definitionIds as $definitionId) {
598 $definition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($definitionId);
599 $definition->deleteFromDb();
600 }
601
602 $this->sourcePoolDefinitionList->reindexPositions();
603 $this->sourcePoolDefinitionList->saveDefinitions();
604
605 $this->questionSetConfig->loadFromDb();
606 $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
607 $this->questionSetConfig->saveToDb();
608
609 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
610 }
611
612 // hey: randomPoolSelector - new pool selector explorer command
613 protected function showPoolSelectorExplorerCmd()
614 {
615 $this->questionSetConfig->loadFromDb();
616
617 require_once 'Services/Repository/classes/class.ilTestQuestionPoolSelectorExplorer.php';
619 $this,
620 self::CMD_SHOW_POOL_SELECTOR_EXPLORER,
621 self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM
622 );
623
624 $selector->setAvailableQuestionPools(
625 array_keys($this->questionSetConfig->getSelectableQuestionPools())
626 );
627
628 if ($selector->handleCommand()) {
629 return;
630 }
631
632 $this->tpl->setContent($selector->getHTML());
633 }
634 // hey.
635
637 {
638 $this->questionSetConfig->loadFromDb();
639
640 $poolId = $this->fetchQuestionPoolIdParameter();
641
642 $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
643 $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
644
645 if ($form === null) {
647 $form->build($sourcePoolDefinition, $availableTaxonomyIds);
648 }
649
650 $this->tpl->setContent($this->ctrl->getHTML($form));
651 }
652
654 {
656 }
657
661 private function saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form = false)
662 {
663 $this->questionSetConfig->loadFromDb();
664
665 $poolId = $this->fetchQuestionPoolIdParameter();
666 $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
667 $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
668
670 $form->build($sourcePoolDefinition, $availableTaxonomyIds);
671
672 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
673 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
674
675 if ($errors) {
676 return $this->showCreateSourcePoolDefinitionFormCmd($form);
677 }
678
679 $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
680
681 $sourcePoolDefinition->setSequencePosition($this->sourcePoolDefinitionList->getNextPosition());
682 $sourcePoolDefinition->saveToDb();
683 $this->sourcePoolDefinitionList->addDefinition($sourcePoolDefinition);
684
685 $this->sourcePoolDefinitionList->saveDefinitions();
686
687 $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
688 $this->questionSetConfig->saveToDb();
689
690 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
691
692 if ($redirect_back_to_form) {
693 ilUtil::sendSuccess($this->lng->txt("tst_msg_random_qsc_modified_add_new_rule"), true);
694 $this->ctrl->setParameter($this, 'src_pool_def_id', $sourcePoolDefinition->getId());
695 $this->ctrl->setParameter($this, 'quest_pool_id', $sourcePoolDefinition->getPoolId());
696 $this->ctrl->redirect($this, self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM);
697 } else {
698 ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
699 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
700 }
701 }
702
704 {
705 require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php';
706
708 $this->ctrl,
709 $this->lng,
710 $this->testOBJ,
711 $this,
712 $this->questionSetConfig
713 );
714
715 $form->setSaveCommand(self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM);
716 $form->setSaveAndNewCommand(self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM);
717
718 return $form;
719 }
720
722 {
723 $this->questionSetConfig->loadFromDb();
724
726 $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($defId);
727 $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
728
729 if ($form === null) {
731 $form->build($sourcePoolDefinition, $availableTaxonomyIds);
732 }
733
734 $this->tpl->setContent($this->ctrl->getHTML($form));
735 }
736
738 {
739 $this->questionSetConfig->loadFromDb();
740
742 $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($defId);
743 $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
744
746 $form->build($sourcePoolDefinition, $availableTaxonomyIds);
747
748 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
749 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
750
751 if ($errors) {
752 return $this->showSourcePoolDefinitionListCmd($form);
753 }
754
755 $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
756
757 $sourcePoolDefinition->saveToDb();
758
759 $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
760 $this->questionSetConfig->saveToDb();
761
762 $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
763
764 ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
765 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
766 }
767
769 {
770 require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php';
771
773 $this->ctrl,
774 $this->lng,
775 $this->testOBJ,
776 $this,
777 $this->questionSetConfig
778 );
779
780 $form->setSaveCommand(self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM);
781
782 return $form;
783 }
784
786 {
787 if (isset($_POST['quest_pool_id']) && (int) $_POST['quest_pool_id']) {
788 return (int) $_POST['quest_pool_id'];
789 }
790
791 if (isset($_GET['quest_pool_id']) && (int) $_GET['quest_pool_id']) {
792 return (int) $_GET['quest_pool_id'];
793 }
794
795 if (isset($_GET['quest_pool_ref']) && (int) $_GET['quest_pool_ref']) {
796 $objCache = $this->dic['ilObjDataCache'];
797 return $objCache->lookupObjId((int) $_GET['quest_pool_ref']);
798 }
799
800 require_once 'Modules/Test/exceptions/class.ilTestMissingQuestionPoolIdParameterException.php';
802 }
803
805 {
806 if (isset($_POST['src_pool_def_id']) && (int) $_POST['src_pool_def_id']) {
807 return (int) $_POST['src_pool_def_id'];
808 }
809
810 if (isset($_GET['src_pool_def_id']) && (int) $_GET['src_pool_def_id']) {
811 return (int) $_GET['src_pool_def_id'];
812 }
813
814 require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
816 }
817
819 {
820 if (!isset($_POST['src_pool_def_ids']) || !is_array($_POST['src_pool_def_ids'])) {
821 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_please_select_source_pool'), true);
822 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
823 return [];
824 }
825
826 $definitionIds = array();
827
828 foreach ($_POST['src_pool_def_ids'] as $definitionId) {
829 $definitionId = (int) $definitionId;
830
831 if (!$definitionId) {
832 require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
834 }
835
836 $definitionIds[] = $definitionId;
837 }
838
839 return $definitionIds;
840 }
841
843 {
844 $availablePools = $this->testOBJ->getAvailableQuestionpools(
845 true,
846 $this->questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired(),
847 false,
848 true,
849 true
850 );
851
852 if (isset($availablePools[$poolId])) {
853 $originalPoolData = $availablePools[$poolId];
854
855 $originalPoolData['qpl_path'] = $this->questionSetConfig->getQuestionPoolPathString($poolId);
856 $originalPoolData['qpl_ref_id'] = $this->questionSetConfig->getFirstQuestionPoolRefIdByObjId($poolId);
857
858 return $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByOriginalPoolData($originalPoolData);
859 }
860
861 require_once 'Modules/Test/exceptions/class.ilTestQuestionPoolNotAvailableAsSourcePoolException.php';
863 }
864
865 protected function fetchPoolIdsParameter()
866 {
867 if (isset($_POST['derive_pool_ids']) && is_array($_POST['derive_pool_ids'])) {
868 $poolIds = array();
869
870 foreach ($_POST['derive_pool_ids'] as $poolId) {
871 $poolIds[] = (int) $poolId;
872 }
873 } elseif (isset($_GET['derive_pool_ids']) && preg_match('/^\d+(\:\d+)*$/', $_GET['derive_pool_ids'])) {
874 $poolIds = explode(':', $_GET['derive_pool_ids']);
875 } elseif (isset($_GET['derive_pool_id']) && (int) $_GET['derive_pool_id']) {
876 $poolIds = array( (int) $_GET['derive_pool_id'] );
877 }
878
879 return $poolIds;
880 }
881
882 protected function fetchTargetRefParameter()
883 {
884 if (isset($_GET['target_ref']) && (int) $_GET['target_ref']) {
885 return (int) $_GET['target_ref'];
886 }
887
888 return null;
889 }
890
892 {
893 $this->ctrl->setParameter($this, 'derive_pool_ids', implode(':', $this->fetchPoolIdsParameter()));
894
895 require_once 'Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php';
896 $explorer = new ilRepositorySelectorExplorerGUI(
897 $this,
898 self::CMD_SELECT_DERIVATION_TARGET,
899 $this,
900 self::CMD_DERIVE_NEW_POOLS,
901 'target_ref'
902 );
903 $explorer->setClickableTypes($this->objDefinition->getExplorerContainerTypes());
904 $explorer->setSelectableTypes(array());
905
906 if (!$explorer->handleCommand()) {
907 ilUtil::sendInfo($this->lng->txt('tst_please_select_target_for_pool_derives'));
908 $this->tpl->setContent($this->ctrl->getHTML($explorer));
909 }
910 }
911
912 private function deriveNewPoolsCmd()
913 {
914 $poolIds = $this->fetchPoolIdsParameter();
915 $targetRef = $this->fetchTargetRefParameter();
916
917 if (!$this->access->checkAccess('write', '', $targetRef)) {
918 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_permission"), true);
919 $this->ctrl->setParameterByClass(ilObjTestGUI::class, 'ref_id', $this->testOBJ->getRefId());
920 $this->ctrl->redirectByClass(ilObjTestGUI::class);
921 }
922
923 if (count($poolIds)) {
924 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetPoolDeriver.php';
925
926 foreach ($poolIds as $poolId) {
927 $lostPool = $this->sourcePoolDefinitionList->getLostPool($poolId);
928
929 $deriver = new ilTestRandomQuestionSetPoolDeriver($this->db, $this->pluginAdmin, $this->testOBJ);
930 $deriver->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
931 $deriver->setTargetContainerRef($targetRef);
932 $deriver->setOwnerId($this->dic['ilUser']->getId());
933 $newPool = $deriver->derive($lostPool);
934
935 $srcPoolDefinition = $this->sourcePoolDefinitionList->getDefinitionBySourcePoolId($newPool->getId());
936 $srcPoolDefinition->setPoolTitle($newPool->getTitle());
937 $srcPoolDefinition->setPoolPath($this->questionSetConfig->getQuestionPoolPathString($newPool->getId()));
938 $srcPoolDefinition->setPoolRefId($this->questionSetConfig->getFirstQuestionPoolRefIdByObjId((int) $newPool->getId()));
939 $srcPoolDefinition->saveToDb();
940
942 $this->testOBJ->getTestId(),
943 $lostPool->getId(),
944 $newPool->getId()
945 );
946 }
947
948 ilUtil::sendSuccess($this->lng->txt('tst_non_available_pool_newly_derived'), true);
949 }
950
951 $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
952 }
953
958 {
959 return $this->lng->txt("tst_msg_random_question_set_config_modified");
960 }
961
965 public function getGeneralConfigTabLabel()
966 {
967 return $this->lng->txt('tst_rnd_quest_cfg_tab_general');
968 }
969
973 public function getPoolConfigTabLabel()
974 {
975 return $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
976 }
977
978
979 protected function preventFormBecauseOfSync() : bool
980 {
981 $return = false;
982 $last_sync = (int) $this->questionSetConfig->getLastQuestionSyncTimestamp();
983
984 if ($last_sync !== null && $last_sync !== 0 &&
985 !$this->isFrozenConfigRequired() && $this->questionSetConfig->isQuestionSetBuildable()) {
986 $return = true;
987
988 $sync_date = new ilDateTime($last_sync, IL_CAL_UNIX);
989 $msg = sprintf(
990 $this->lng->txt('tst_msg_rand_quest_set_stage_pool_last_sync'),
992 );
993
994 $href = $this->ctrl->getLinkTarget($this, self::CMD_RESET_POOLSYNC);
995 $label = $this->lng->txt('tst_btn_reset_pool_sync');
996
997 $buttons = [
998 $this->dic->ui()->factory()->button()->standard($label, $href)
999 ];
1000
1001 $msgbox = $this->dic->ui()->factory()->messageBox()
1002 ->info($msg)
1003 ->withButtons($buttons);
1004 $message = $this->dic->ui()->renderer()->render($msgbox);
1005 $this->dic->ui()->mainTemplate()->setCurrentBlock('mess');
1006 $this->dic->ui()->mainTemplate()->setVariable('MESSAGE', $message);
1007 $this->dic->ui()->mainTemplate()->parseCurrentBlock();
1008 }
1009 return $return;
1010 }
1011
1012 public function resetPoolSyncCmd() : void
1013 {
1014 $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
1015 $this->questionSetConfig->saveToDb();
1016 $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
1017 }
1018}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
This class provides processing control methods.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
language handling
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
Administration class for plugins.
Explorer for selecting repository items.
Tabs GUI.
showGeneralConfigFormCmd(ilTestRandomQuestionSetGeneralConfigFormGUI $form=null)
saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form=false)
showEditSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
__construct(ilCtrl $ctrl, ilAccessHandler $access, ilTabsGUI $tabs, ilLanguage $lng, ilGlobalTemplateInterface $tpl, ilDBInterface $db, ilTree $tree, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ, ilTestProcessLockerFactory $processLockerFactory)
showCreateSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
$errors
Definition: imgupload.php:49
Interface ilAccessHandler.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:14