ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestRandomQuestionSetConfigGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
40 {
41  public const CMD_SHOW_GENERAL_CONFIG_FORM = 'showGeneralConfigForm';
42  public const CMD_SAVE_GENERAL_CONFIG_FORM = 'saveGeneralConfigForm';
43  public const CMD_SHOW_SRC_POOL_DEF_LIST = 'showSourcePoolDefinitionList';
44  public const CMD_SAVE_SRC_POOL_DEF_LIST = 'saveSourcePoolDefinitionList';
45  public const CMD_DELETE_SINGLE_SRC_POOL_DEF = 'deleteSingleSourcePoolDefinition';
46  public const CMD_DELETE_MULTI_SRC_POOL_DEFS = 'deleteMultipleSourcePoolDefinitions';
47  public const CMD_SHOW_POOL_SELECTOR_EXPLORER = 'showPoolSelectorExplorer';
48  public const CMD_SHOW_CREATE_SRC_POOL_DEF_FORM = 'showCreateSourcePoolDefinitionForm';
49  public const CMD_SAVE_CREATE_SRC_POOL_DEF_FORM = 'saveCreateSourcePoolDefinitionForm';
50  public const CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM = 'saveCreateAndNewSourcePoolDefinitionForm';
51  public const CMD_SHOW_EDIT_SRC_POOL_DEF_FORM = 'showEditSourcePoolDefinitionForm';
52  public const CMD_SAVE_EDIT_SRC_POOL_DEF_FORM = 'saveEditSourcePoolDefinitionForm';
53  public const CMD_BUILD_QUESTION_STAGE = 'buildQuestionStage';
54  public const CMD_SELECT_DERIVATION_TARGET = 'selectPoolDerivationTarget';
55  public const CMD_DERIVE_NEW_POOLS = 'deriveNewPools';
56  public const CMD_RESET_POOLSYNC = 'resetPoolSync';
57 
58  public const HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD = 'afterRebuildQuestionStageCmd';
59 
65 
66  public function __construct(
67  private ilObjTest $test_obj,
68  private ilCtrl $ctrl,
69  private ilObjUser $user,
70  private ilAccessHandler $access,
71  private UIFactory $ui_factory,
72  private UIRenderer $ui_renderer,
73  private ilTabsGUI $tabs,
74  private ilLanguage $lng,
75  private ilLogger $log,
76  private ilGlobalTemplateInterface $tpl,
77  private ilDBInterface $db,
78  private ilTree $tree,
79  private ilComponentRepository $component_repository,
80  private ilObjectDefinition $obj_definition,
81  private ilObjectDataCache $obj_cache,
82  private ilTestProcessLockerFactory $processLockerFactory,
83  private InternalRequestService $testrequest,
84  private QuestionInfoService $questioninfo
85  ) {
86  $this->question_set_config = new ilTestRandomQuestionSetConfig(
87  $this->tree,
88  $this->db,
89  $this->lng,
90  $this->log,
91  $this->component_repository,
92  $this->test_obj,
93  $this->questioninfo
94  );
95  $this->question_set_config->loadFromDb();
96 
97  $this->source_pool_definition_factory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
98  $this->db,
99  $this->test_obj
100  );
101 
102  $this->source_pool_definition_list = new ilTestRandomQuestionSetSourcePoolDefinitionList(
103  $this->db,
104  $this->test_obj,
105  $this->source_pool_definition_factory
106  );
107 
108  $this->source_pool_definition_list->loadDefinitions();
109 
110  $this->stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder(
111  $this->db,
112  $this->log,
113  $this->test_obj
114  );
115 
116  $this->configStateMessageHandler = new ilTestRandomQuestionSetConfigStateMessageHandler(
117  $this->lng,
118  $this->ui_factory,
119  $this->ui_renderer,
120  $this->ctrl
121  );
122 
123  $this->configStateMessageHandler->setTargetGUI($this);
124  $this->configStateMessageHandler->setQuestionSetConfig($this->question_set_config);
125  $this->configStateMessageHandler->setParticipantDataExists($this->test_obj->participantDataExist());
126  $this->configStateMessageHandler->setLostPools($this->source_pool_definition_list->getLostPools());
127  $this->processLockerFactory = $processLockerFactory;
128  }
129 
130  public function executeCommand(): void
131  {
132  if (!$this->access->checkAccess("write", "", $this->test_obj->getRefId())) {
133  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("cannot_edit_test"), true);
134  $this->ctrl->redirectByClass('ilObjTestGUI', "infoScreen");
135  }
136 
138  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("tst_msg_cannot_modify_random_question_set_conf_due_to_part"), true);
139  $this->ctrl->redirect($this);
140  }
141 
142  $this->handleTabs();
143 
144  $nextClass = $this->ctrl->getNextClass();
145 
146  switch ($nextClass) {
147  case 'iltestrandomquestionsetpooldefinitionformgui':
148  $this->question_set_config->loadFromDb();
149  $poolId = $this->fetchQuestionPoolIdParameter();
150  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
151  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
153  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
154 
155  $this->ctrl->forwardCommand($form);
156  break;
157 
158  default:
159  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM) . 'Cmd';
160  $this->$cmd();
161  }
162  }
163 
164  private function isAvoidManipulationRedirectRequired(): bool
165  {
166  if (!$this->isFrozenConfigRequired()) {
167  return false;
168  }
169 
170  if (!$this->isManipulationCommand()) {
171  return false;
172  }
173 
174  return true;
175  }
176 
177  private function isFrozenConfigRequired(): bool
178  {
179  if ($this->test_obj->participantDataExist()) {
180  return true;
181  }
182 
183  if ($this->source_pool_definition_list->hasLostPool()) {
184  return true;
185  }
186 
187  return false;
188  }
189 
190  private function isManipulationCommand(): bool
191  {
192  switch ($this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM)) {
193  case self::CMD_SAVE_GENERAL_CONFIG_FORM:
194  case self::CMD_SAVE_SRC_POOL_DEF_LIST:
195  case self::CMD_DELETE_SINGLE_SRC_POOL_DEF:
196  case self::CMD_DELETE_MULTI_SRC_POOL_DEFS:
197  case self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM:
198  case self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM:
199  case self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM:
200  case self::CMD_BUILD_QUESTION_STAGE:
201 
202  return true;
203  }
204 
205  return false;
206  }
207 
208  private function handleTabs(): void
209  {
210  $this->tabs->activateTab('assQuestions');
211 
212  $this->tabs->addSubTab(
213  'tstRandQuestSetGeneralConfig',
214  $this->getGeneralConfigTabLabel(),
215  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_GENERAL_CONFIG_FORM)
216  );
217 
218  $this->tabs->addSubTab(
219  'tstRandQuestSetPoolConfig',
220  $this->getPoolConfigTabLabel(),
221  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_SRC_POOL_DEF_LIST)
222  );
223 
224  switch ($this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM)) {
225  case self::CMD_SHOW_GENERAL_CONFIG_FORM:
226  case self::CMD_SAVE_GENERAL_CONFIG_FORM:
227 
228  $this->tabs->activateSubTab('tstRandQuestSetGeneralConfig');
229  break;
230 
231  case self::CMD_SHOW_SRC_POOL_DEF_LIST:
232  case self::CMD_SAVE_SRC_POOL_DEF_LIST:
233  case self::CMD_DELETE_SINGLE_SRC_POOL_DEF:
234  case self::CMD_DELETE_MULTI_SRC_POOL_DEFS:
235  case self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM:
236  case self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM:
237  case self::CMD_SHOW_EDIT_SRC_POOL_DEF_FORM:
238  case self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM:
239 
240  $this->tabs->activateSubTab('tstRandQuestSetPoolConfig');
241  break;
242 
243  default: $this->tabs->activateSubTab('nonTab');
244  }
245  }
246 
247  private function buildQuestionStageCmd(): void
248  {
249  if ($this->source_pool_definition_list->areAllUsedPoolsAvailable()) {
250  $locker = $this->processLockerFactory->retrieveLockerForNamedOperation();
251  $locker->executeNamedOperation(__FUNCTION__, function (): void {
252  $this->stagingPool->rebuild($this->source_pool_definition_list);
253  $this->source_pool_definition_list->saveDefinitions();
254 
255  $this->question_set_config->loadFromDb();
256  $this->question_set_config->setLastQuestionSyncTimestamp(time());
257  $this->question_set_config->saveToDb();
258 
259  $this->test_obj->saveCompleteStatus($this->question_set_config);
260 
261  $this->ctrl->setParameterByClass(self::class, 'modified', 'sync');
262  });
263  }
264 
265  $this->ctrl->redirect($this, $this->fetchAfterRebuildQuestionStageCmdParameter());
266  }
267 
269  {
270  if (!$this->testrequest->isset(self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD)) {
271  return self::CMD_SHOW_GENERAL_CONFIG_FORM;
272  }
273 
274  if (!strlen($this->testrequest->raw(self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD))) {
275  return self::CMD_SHOW_GENERAL_CONFIG_FORM;
276  }
277 
278  return $this->testrequest->raw(self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD);
279  }
280 
282  {
283  $disabled_form = $this->preventFormBecauseOfSync();
284 
285  if ($form === null) {
286  $this->question_set_config->loadFromDb();
287  $form = $this->buildGeneralConfigFormGUI($disabled_form);
288  }
289 
290  $this->tpl->setContent($this->ctrl->getHTML($form));
291 
292  $this->configStateMessageHandler->setContext(
294  );
295 
296  $this->configStateMessageHandler->handle();
297 
298  $message = $this->buildOnScreenMessage();
299  if ($message !== '') {
301  }
302  }
303 
304  private function saveGeneralConfigFormCmd(): void
305  {
306  $form = $this->buildGeneralConfigFormGUI();
307 
308  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
309  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
310 
311  if ($errors) {
312  $this->showGeneralConfigFormCmd($form);
313  return;
314  }
315 
316  $form->save();
317 
318  $this->question_set_config->setLastQuestionSyncTimestamp(0);
319  $this->question_set_config->saveToDb();
320 
321  $this->test_obj->saveCompleteStatus($this->question_set_config);
322 
323  $this->ctrl->setParameter($this, 'modified', 'save');
324  $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
325  }
326 
327 
329  {
331  $this->ctrl,
332  $this->lng,
333  $this->test_obj,
334  $this,
335  $this->question_set_config
336  );
337 
338  //TODO: should frozen config not lead to 'completely disabled' as well?!
339  $form->setEditModeEnabled(!$this->isFrozenConfigRequired());
340 
341  if ($disabled) {
342  $form->setEditModeEnabled(false);
343  }
344 
345  $form->build();
346 
347  if ($disabled) {
348  $form->clearCommandButtons();
349  }
350 
351  return $form;
352  }
353 
354  private function showSourcePoolDefinitionListCmd(): void
355  {
356  $disabled_form = $this->preventFormBecauseOfSync();
357 
358  $this->question_set_config->loadFromDb();
359 
360  $content = '';
361 
362  if (!$this->isFrozenConfigRequired() && !$disabled_form) {
363  $toolbar = $this->buildSourcePoolDefinitionListToolbarGUI();
364  $content .= $this->ctrl->getHTML($toolbar);
365  }
366 
367  $table = $this->buildSourcePoolDefinitionListTableGUI($disabled_form);
368  $table->init($this->source_pool_definition_list);
369  $content .= $this->ctrl->getHTML($table);
370 
371  if (!$this->source_pool_definition_list->areAllUsedPoolsAvailable()) {
372  $table = $this->buildNonAvailablePoolsTableGUI();
373  $table->init($this->source_pool_definition_list);
374  $content .= $this->ctrl->getHTML($table);
375  }
376 
377  $this->tpl->setContent($content);
378 
379  $this->configStateMessageHandler->setContext(
381  );
382 
383  $this->configStateMessageHandler->handle();
384 
385  $message = $this->buildOnScreenMessage();
386  if ($message) {
388  }
389  }
390 
391  private function saveSourcePoolDefinitionListCmd(): void
392  {
393  $this->question_set_config->loadFromDb();
394 
395  $table = $this->buildSourcePoolDefinitionListTableGUI();
396 
397  $table->applySubmit($this->source_pool_definition_list);
398 
399  $this->source_pool_definition_list->reindexPositions();
400  $this->source_pool_definition_list->saveDefinitions();
401 
402  $this->question_set_config->setLastQuestionSyncTimestamp(0);
403  // fau.
404  $this->question_set_config->saveToDb();
405 
406  $this->test_obj->saveCompleteStatus($this->question_set_config);
407 
408  $this->ctrl->setParameter($this, 'modified', 'save');
409  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
410  }
411 
413  {
415  $this->ctrl,
416  $this->lng,
417  $this,
418  $this->question_set_config
419  );
420 
421  $toolbar->build();
422 
423  return $toolbar;
424  }
425 
427  {
429  $this,
430  self::CMD_SHOW_SRC_POOL_DEF_LIST,
431  $this->access,
432  $this->ui_factory,
433  $this->ui_renderer,
434  $this->testrequest->raw('def_order') ?? [],
435  $this->testrequest->raw('quest_amount') ?? []
436  );
437 
438  if (!$this->isFrozenConfigRequired()) {
439  $table->setDefinitionEditModeEnabled(true);
440  }
441 
442  $table->setQuestionAmountColumnEnabled(
443  $this->question_set_config->isQuestionAmountConfigurationModePerPool()
444  );
445 
446  $table->setShowMappedTaxonomyFilter(
447  $this->question_set_config->getLastQuestionSyncTimestamp() != 0
448  );
449 
450  $translater = new ilTestQuestionFilterLabelTranslater($this->db, $this->lng);
451  $translater->loadLabels($this->source_pool_definition_list);
452  $table->setTaxonomyFilterLabelTranslater($translater);
453 
454  if ($disabled) {
455  $table->setDefinitionEditModeEnabled(false);
456  }
457  $table->build();
458 
459  return $table;
460  }
461 
463  {
465  $this->ctrl,
466  $this->lng,
467  $this,
468  self::CMD_SHOW_SRC_POOL_DEF_LIST
469  );
470 
471  $table->build();
472 
473  return $table;
474  }
475 
476  private function deleteSingleSourcePoolDefinitionCmd(): void
477  {
478  $definitionId = $this->fetchSingleSourcePoolDefinitionIdParameter();
479  $this->deleteSourcePoolDefinitions([$definitionId]);
480 
481  $this->ctrl->setParameterByClass(self::class, 'modified', 'remove');
482  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
483  }
484 
485  private function deleteMultipleSourcePoolDefinitionsCmd(): void
486  {
487  $definitionIds = $this->fetchMultiSourcePoolDefinitionIdsParameter();
488  $this->deleteSourcePoolDefinitions($definitionIds);
489 
490  $this->ctrl->setParameterByClass(self::class, 'modified', 'remove');
491  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
492  }
493 
494  private function deleteSourcePoolDefinitions($definitionIds): void
495  {
496  foreach ($definitionIds as $definitionId) {
497  $definition = $this->source_pool_definition_factory->getSourcePoolDefinitionByDefinitionId($definitionId);
498  $definition->deleteFromDb();
499  }
500 
501  $this->source_pool_definition_list->reindexPositions();
502  $this->source_pool_definition_list->saveDefinitions();
503 
504  $this->question_set_config->loadFromDb();
505  $this->question_set_config->setLastQuestionSyncTimestamp(0);
506  $this->question_set_config->saveToDb();
507 
508  $this->test_obj->saveCompleteStatus($this->question_set_config);
509  }
510 
511  // hey: randomPoolSelector - new pool selector explorer command
512  protected function showPoolSelectorExplorerCmd(): void
513  {
514  $this->question_set_config->loadFromDb();
515 
516  $selector = new ilTestQuestionPoolSelectorExplorer(
517  $this,
518  self::CMD_SHOW_POOL_SELECTOR_EXPLORER,
519  self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM,
520  $this->obj_cache
521  );
522 
523  $selector->setAvailableQuestionPools(
524  array_keys($this->question_set_config->getSelectableQuestionPools())
525  );
526 
527  if ($selector->handleCommand()) {
528  return;
529  }
530 
531  $this->tpl->setContent($selector->getHTML());
532  }
533  // hey.
534 
536  {
537  $this->question_set_config->loadFromDb();
538 
539  $poolId = $this->fetchQuestionPoolIdParameter();
540 
541  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
542  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
543 
544  if ($form === null) {
546  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
547  }
548 
549  $this->tpl->setContent($this->ctrl->getHTML($form));
550  }
551 
553  {
555  }
556 
560  private function saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form = false): void
561  {
562  $this->question_set_config->loadFromDb();
563 
564  $poolId = $this->fetchQuestionPoolIdParameter();
565  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
566  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
567 
569  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
570 
571  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
572  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
573 
574  if ($errors) {
576  return;
577  }
578 
579  $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
580 
581  $sourcePoolDefinition->setSequencePosition($this->source_pool_definition_list->getNextPosition());
582  $sourcePoolDefinition->saveToDb();
583  $this->source_pool_definition_list->addDefinition($sourcePoolDefinition);
584 
585  $this->source_pool_definition_list->saveDefinitions();
586 
587  $this->question_set_config->setLastQuestionSyncTimestamp(0);
588  $this->question_set_config->saveToDb();
589 
590  $this->test_obj->saveCompleteStatus($this->question_set_config);
591 
592  if ($redirect_back_to_form) {
593  $this->tpl->setOnScreenMessage('success', $this->lng->txt("tst_msg_random_qsc_modified_add_new_rule"), true);
594  $this->ctrl->setParameter($this, 'src_pool_def_id', $sourcePoolDefinition->getId());
595  $this->ctrl->setParameter($this, 'quest_pool_id', $sourcePoolDefinition->getPoolId());
596  $this->ctrl->redirect($this, self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM);
597  } else {
598  $this->ctrl->setParameterByClass(self::class, 'modified', 'save');
599  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
600  }
601  }
602 
604  {
606  $this->ctrl,
607  $this->lng,
608  $this->test_obj,
609  $this,
610  $this->question_set_config
611  );
612 
613  $form->setSaveCommand(self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM);
614  $form->setSaveAndNewCommand(self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM);
615 
616  return $form;
617  }
618 
620  {
621  $this->question_set_config->loadFromDb();
622 
624  $sourcePoolDefinition = $this->source_pool_definition_factory->getSourcePoolDefinitionByDefinitionId($defId);
625  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
626 
627  if ($form === null) {
628  $form = $this->buildEditSourcePoolDefinitionFormGUI();
629  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
630  }
631 
632  $this->tpl->setContent($this->ctrl->getHTML($form));
633  }
634 
635  private function saveEditSourcePoolDefinitionFormCmd(): void
636  {
637  $this->question_set_config->loadFromDb();
638 
640  $sourcePoolDefinition = $this->source_pool_definition_factory->getSourcePoolDefinitionByDefinitionId($defId);
641  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
642 
643  $form = $this->buildEditSourcePoolDefinitionFormGUI();
644  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
645 
646  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
647  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
648 
649  if ($errors) {
651  return;
652  }
653 
654  $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
655 
656  $sourcePoolDefinition->saveToDb();
657 
658  $this->question_set_config->setLastQuestionSyncTimestamp(0);
659  $this->question_set_config->saveToDb();
660 
661  $this->test_obj->saveCompleteStatus($this->question_set_config);
662 
663  $this->ctrl->setParameterByClass(self::class, 'modified', 'save');
664  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
665  }
666 
668  {
670  $this->ctrl,
671  $this->lng,
672  $this->test_obj,
673  $this,
674  $this->question_set_config
675  );
676 
677  $form->setSaveCommand(self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM);
678 
679  return $form;
680  }
681 
682  private function fetchQuestionPoolIdParameter(): int
683  {
684  if ($this->testrequest->isset('quest_pool_id') && (int) $this->testrequest->raw('quest_pool_id')) {
685  return (int) $this->testrequest->raw('quest_pool_id');
686  }
687 
688  if ($this->testrequest->isset('quest_pool_ref') && (int) $this->testrequest->raw('quest_pool_ref')) {
689  return $this->obj_cache->lookupObjId((int) $this->testrequest->raw('quest_pool_ref'));
690  }
691 
693  }
694 
696  {
697  if ($this->testrequest->isset('src_pool_def_id') && (int) $this->testrequest->raw('src_pool_def_id')) {
698  return (int) $this->testrequest->raw('src_pool_def_id');
699  }
700 
702  }
703 
705  {
706  if (!$this->testrequest->isset('src_pool_def_ids') || !is_array($this->testrequest->raw('src_pool_def_ids'))) {
707  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('tst_please_select_source_pool'), true);
708  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
709  return [];
710  }
711 
712  $definitionIds = [];
713 
714  foreach ($this->testrequest->raw('src_pool_def_ids') as $definitionId) {
715  $definitionId = (int) $definitionId;
716 
717  if (!$definitionId) {
719  }
720 
721  $definitionIds[] = $definitionId;
722  }
723 
724  return $definitionIds;
725  }
726 
728  {
729  $availablePools = $this->test_obj->getAvailableQuestionpools(
730  true,
731  $this->question_set_config->arePoolsWithHomogeneousScoredQuestionsRequired(),
732  false,
733  true,
734  true
735  );
736 
737  if (isset($availablePools[$poolId])) {
738  $originalPoolData = $availablePools[$poolId];
739 
740  $originalPoolData['qpl_path'] = $this->question_set_config->getQuestionPoolPathString($poolId);
741  $originalPoolData['qpl_ref_id'] = $this->question_set_config->getFirstQuestionPoolRefIdByObjId($poolId);
742 
743  return $this->source_pool_definition_factory->getSourcePoolDefinitionByOriginalPoolData($originalPoolData);
744  }
745 
747  }
748 
752  protected function fetchPoolIdsParameter(): array
753  {
754  $pool_ids = [];
755  if ($this->testrequest->isset('derive_pool_ids') && is_array($this->testrequest->raw('derive_pool_ids'))) {
756  $pool_ids = [];
757 
758  foreach ($this->testrequest->raw('derive_pool_ids') as $pool_id) {
759  $pool_ids[] = (int) $pool_id;
760  }
761  } elseif ($this->testrequest->isset('derive_pool_ids') && preg_match('/^\d+(\:\d+)*$/', $this->testrequest->raw('derive_pool_ids'))) {
762  $pool_ids = array_map(
763  fn(int $id) => (int) $id,
764  explode(':', $this->testrequest->raw('derive_pool_ids'))
765  );
766  } elseif ($this->testrequest->isset('derive_pool_id') && (int) $this->testrequest->raw('derive_pool_id')) {
767  $pool_ids = [(int) $this->testrequest->raw('derive_pool_id')];
768  }
769 
770  return $pool_ids;
771  }
772 
773  protected function fetchTargetRefParameter(): ?int
774  {
775  if ($this->testrequest->isset('target_ref') && (int) $this->testrequest->raw('target_ref')) {
776  return (int) $this->testrequest->raw('target_ref');
777  }
778 
779  return null;
780  }
781 
782  private function selectPoolDerivationTargetCmd(): void
783  {
784  $this->ctrl->setParameter($this, 'derive_pool_ids', implode(':', $this->fetchPoolIdsParameter()));
785 
786  $explorer = new ilRepositorySelectorExplorerGUI(
787  $this,
788  self::CMD_SELECT_DERIVATION_TARGET,
789  $this,
790  self::CMD_DERIVE_NEW_POOLS,
791  'target_ref'
792  );
793  $explorer->setClickableTypes($this->obj_definition->getExplorerContainerTypes());
794  $explorer->setSelectableTypes([]);
795 
796  if (!$explorer->handleCommand()) {
797  $this->tpl->setOnScreenMessage('info', $this->lng->txt('tst_please_select_target_for_pool_derives'));
798  $this->tpl->setContent($this->ctrl->getHTML($explorer));
799  }
800  }
801 
802  private function deriveNewPoolsCmd(): void
803  {
804  $pool_ids = $this->fetchPoolIdsParameter();
805  $target_ref = $this->fetchTargetRefParameter();
806  if (!$this->access->checkAccess('write', '', $target_ref)) {
807  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_permission"), true);
808  $this->ctrl->setParameterByClass(ilObjTestGUI::class, 'ref_id', $this->test_obj->getRefId());
809  $this->ctrl->redirectByClass(ilObjTestGUI::class);
810  }
811 
812  if ($pool_ids !== []) {
813  foreach ($pool_ids as $pool_id) {
814  $lost_pool = $this->source_pool_definition_list->getLostPool($pool_id);
815 
816  $deriver = new ilTestRandomQuestionSetPoolDeriver($this->db, $this->component_repository, $this->test_obj);
817  $deriver->setSourcePoolDefinitionList($this->source_pool_definition_list);
818  $deriver->setTargetContainerRef($target_ref);
819  $deriver->setOwnerId($this->user->getId());
820  $new_pool = $deriver->derive($lost_pool);
821 
822  $srcPoolDefinition = $this->source_pool_definition_list->getDefinitionBySourcePoolId($new_pool->getId());
823  $srcPoolDefinition->setPoolTitle($new_pool->getTitle());
824  $srcPoolDefinition->setPoolPath($this->question_set_config->getQuestionPoolPathString($new_pool->getId()));
825  $srcPoolDefinition->setPoolRefId($this->question_set_config->getFirstQuestionPoolRefIdByObjId($new_pool->getId()));
826  $srcPoolDefinition->saveToDb();
827 
829  $this->test_obj->getTestId(),
830  $lost_pool->getId(),
831  $new_pool->getId()
832  );
833  }
834 
835  $this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_non_available_pool_newly_derived'), true);
836  }
837 
838  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
839  }
840 
844  private function getGeneralModificationSuccessMessage(): string
845  {
846  return $this->lng->txt("tst_msg_random_question_set_config_modified");
847  }
848 
852  public function getGeneralConfigTabLabel(): string
853  {
854  return $this->lng->txt('tst_rnd_quest_cfg_tab_general');
855  }
856 
860  public function getPoolConfigTabLabel(): string
861  {
862  return $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
863  }
864 
865 
866  protected function preventFormBecauseOfSync(): bool
867  {
868  $return = false;
869  $last_sync = $this->question_set_config->getLastQuestionSyncTimestamp();
870 
871  if ($last_sync !== null && $last_sync !== 0 &&
872  !$this->isFrozenConfigRequired() && $this->question_set_config->isQuestionSetBuildable()) {
873  return true;
874  }
875  return false;
876  }
877 
878  public function resetPoolSyncCmd(): void
879  {
880  $this->question_set_config->setLastQuestionSyncTimestamp(0);
881  $this->question_set_config->saveToDb();
882  $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
883  }
884 
885  protected function buildOnScreenMessage(): string
886  {
887  $message = $this->buildFormResultMessage();
888  $message .= $this->buildValidationMessage();
889 
890  return $message;
891  }
892 
893  protected function buildFormResultMessage(): string
894  {
895  $message = '';
896 
897  if ($this->testrequest->isset('modified')) {
898  $action = $this->testrequest->raw('modified');
899  if ($action === 'save') {
900  $success_message = $this->ui_factory->messageBox()->success($this->getGeneralModificationSuccessMessage());
901  } elseif ($action === 'remove') {
902  $success_message = $this->ui_factory->messageBox()->success($this->lng->txt("tst_msg_source_pool_definitions_deleted"));
903  } elseif ($action === 'sync') {
904  $success_message = $this->ui_factory->messageBox()->success($this->lng->txt("tst_msg_random_question_set_synced"));
905  }
906  $message .= $this->ui_renderer->render(
907  $success_message
908  );
909  }
910 
911  return $message;
912  }
913 
914  protected function buildValidationMessage(): string
915  {
916  if ($this->configStateMessageHandler->isValidationFailed()) {
917  return $this->ui_renderer->render(
918  $this->ui_factory->messageBox()->failure($this->configStateMessageHandler->getValidationReportHtml())
919  );
920  }
921 
922  if ($this->configStateMessageHandler->hasValidationReports()) {
923  return $this->ui_renderer->render(
924  $this->ui_factory->messageBox()->info($this->configStateMessageHandler->getValidationReportHtml())
925  );
926  }
927 
928  return $this->configStateMessageHandler->getSyncInfoMessage();
929  }
930 
934  protected function populateOnScreenMessage($message)
935  {
936  $this->tpl->setCurrentBlock('mess');
937  $this->tpl->setVariable('MESSAGE', $message);
938  $this->tpl->parseCurrentBlock();
939  }
940 }
Readable part of repository interface to ilComponentDataDB.
Explorer for selecting repository items.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilTestRandomQuestionSetSourcePoolDefinitionFactory $source_pool_definition_factory
__construct(private ilObjTest $test_obj, private ilCtrl $ctrl, private ilObjUser $user, private ilAccessHandler $access, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private ilTabsGUI $tabs, private ilLanguage $lng, private ilLogger $log, private ilGlobalTemplateInterface $tpl, private ilDBInterface $db, private ilTree $tree, private ilComponentRepository $component_repository, private ilObjectDefinition $obj_definition, private ilObjectDataCache $obj_cache, private ilTestProcessLockerFactory $processLockerFactory, private InternalRequestService $testrequest, private QuestionInfoService $questioninfo)
ilTestRandomQuestionSetStagingPoolBuilder $stagingPool
static getUsageOfObject(int $a_obj_id, bool $a_include_titles=false)
ilTestRandomQuestionSetConfigStateMessageHandler $configStateMessageHandler
showEditSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
parses the objects.xml it handles the xml-description of all ilias objects
$lng
$log
Definition: result.php:33
saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form=false)
ilTestRandomQuestionSetSourcePoolDefinitionList $source_pool_definition_list
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$message
Definition: xapiexit.php:32
showGeneralConfigFormCmd(ilTestRandomQuestionSetGeneralConfigFormGUI $form=null)
showCreateSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)