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