ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
4 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfig.php';
5 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
6 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
7 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetStagingPoolBuilder.php';
8 require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetConfigStateMessageHandler.php';
9 
10 require_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 
45  const HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD = 'afterRebuildQuestionStageCmd';
49  public $ctrl = null;
50 
54  public $access = null;
55 
59  public $tabs = null;
60 
64  public $lng = null;
65 
69  public $tpl = null;
70 
74  public $db = null;
75 
79  public $tree = null;
80 
84  public $pluginAdmin = null;
85 
89  public $objDefinition = null;
90 
94  public $testOBJ = null;
95 
99  protected $questionSetConfig = null;
100 
105 
109  protected $sourcePoolDefinitionList = null;
110 
114  protected $stagingPool = null;
115 
124 
125  public function __construct(
126  ilCtrl $ctrl,
132  ilTree $tree,
136  ) {
137  $this->ctrl = $ctrl;
138  $this->access = $access;
139  $this->tabs = $tabs;
140  $this->lng = $lng;
141  $this->tpl = $tpl;
142  $this->db = $db;
143  $this->tree = $tree;
144  $this->pluginAdmin = $pluginAdmin;
145  $this->objDefinition = $GLOBALS['DIC']['objDefinition'];
146  $this->testOBJ = $testOBJ;
147 
148  $this->questionSetConfig = new ilTestRandomQuestionSetConfig(
149  $this->tree,
150  $this->db,
151  $this->pluginAdmin,
152  $this->testOBJ
153  );
154 
155  $this->sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
156  $this->db,
157  $this->testOBJ
158  );
159 
160  $this->sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
161  $this->db,
162  $this->testOBJ,
163  $this->sourcePoolDefinitionFactory
164  );
165 
166  $this->sourcePoolDefinitionList->loadDefinitions();
167 
168  $this->stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder(
169  $this->db,
170  $this->testOBJ
171  );
172 
173  $this->configStateMessageHandler = new ilTestRandomQuestionSetConfigStateMessageHandler(
174  $this->lng,
175  $this->ctrl
176  );
177 
178  $this->configStateMessageHandler->setTargetGUI($this);
179  $this->configStateMessageHandler->setQuestionSetConfig($this->questionSetConfig);
180  $this->configStateMessageHandler->setParticipantDataExists($this->testOBJ->participantDataExist());
181  $this->configStateMessageHandler->setLostPools($this->sourcePoolDefinitionList->getLostPools());
182  $this->processLockerFactory = $processLockerFactory;
183  }
184 
185  public function executeCommand()
186  {
187  if (!$this->access->checkAccess("write", "", $this->testOBJ->getRefId())) {
188  ilUtil::sendFailure($this->lng->txt("cannot_edit_test"), true);
189  $this->ctrl->redirectByClass('ilObjTestGUI', "infoScreen");
190  }
191 
193  ilUtil::sendFailure($this->lng->txt("tst_msg_cannot_modify_random_question_set_conf_due_to_part"), true);
194  $this->ctrl->redirect($this);
195  }
196 
197  $this->handleTabs();
198 
199  $nextClass = $this->ctrl->getNextClass();
200 
201  switch ($nextClass) {
202  case 'iltestrandomquestionsetpooldefinitionformgui':
203  $this->questionSetConfig->loadFromDb();
204  $poolId = $this->fetchQuestionPoolIdParameter();
205  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
206  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
208  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
209 
210  $this->ctrl->forwardCommand($form);
211  break;
212 
213  default:
214 
215  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM) . 'Cmd';
216 
217  $this->$cmd();
218  }
219  }
220 
222  {
223  if (!$this->isFrozenConfigRequired()) {
224  return false;
225  }
226 
227  if (!$this->isManipulationCommand()) {
228  return false;
229  }
230 
231  return true;
232  }
233 
234  private function isFrozenConfigRequired()
235  {
236  if ($this->testOBJ->participantDataExist()) {
237  return true;
238  }
239 
240  if ($this->sourcePoolDefinitionList->hasLostPool()) {
241  return true;
242  }
243 
244  return false;
245  }
246 
247  private function isManipulationCommand()
248  {
249  switch ($this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM)) {
250  case self::CMD_SAVE_GENERAL_CONFIG_FORM:
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_SAVE_CREATE_SRC_POOL_DEF_FORM:
255  case self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM:
256  case self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM:
257  case self::CMD_BUILD_QUESTION_STAGE:
258 
259  return true;
260  }
261 
262  return false;
263  }
264 
265  private function handleTabs()
266  {
267  $this->tabs->activateTab('assQuestions');
268 
269  $this->tabs->addSubTab(
270  'tstRandQuestSetGeneralConfig',
271  $this->getGeneralConfigTabLabel(),
272  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_GENERAL_CONFIG_FORM)
273  );
274 
275  $this->tabs->addSubTab(
276  'tstRandQuestSetPoolConfig',
277  $this->getPoolConfigTabLabel(),
278  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_SRC_POOL_DEF_LIST)
279  );
280 
281  switch ($this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM)) {
282  case self::CMD_SHOW_GENERAL_CONFIG_FORM:
283  case self::CMD_SAVE_GENERAL_CONFIG_FORM:
284 
285  $this->tabs->activateSubTab('tstRandQuestSetGeneralConfig');
286  break;
287 
288  case self::CMD_SHOW_SRC_POOL_DEF_LIST:
289  case self::CMD_SAVE_SRC_POOL_DEF_LIST:
290  case self::CMD_DELETE_SINGLE_SRC_POOL_DEF:
291  case self::CMD_DELETE_MULTI_SRC_POOL_DEFS:
292  case self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM:
293  case self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM:
294  case self::CMD_SHOW_EDIT_SRC_POOL_DEF_FORM:
295  case self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM:
296 
297  $this->tabs->activateSubTab('tstRandQuestSetPoolConfig');
298  break;
299 
300  default: $this->tabs->activateSubTab('nonTab');
301  }
302  }
303 
304  private function buildQuestionStageCmd() : void
305  {
306  if ($this->sourcePoolDefinitionList->areAllUsedPoolsAvailable()) {
307  $locker = $this->processLockerFactory->retrieveLockerForNamedOperation();
308  $locker->executeNamedOperation(__FUNCTION__, function() : void {
309  $this->stagingPool->rebuild($this->sourcePoolDefinitionList);
310  $this->sourcePoolDefinitionList->saveDefinitions();
311 
312  $this->questionSetConfig->loadFromDb();
313  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
314  $this->questionSetConfig->saveToDb();
315 
316  $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
317 
318  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_synced"), true);
319  });
320  }
321 
322  $this->ctrl->redirect($this, $this->fetchAfterRebuildQuestionStageCmdParameter());
323  }
324 
326  {
327  if (!isset($_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD])) {
328  return self::CMD_SHOW_GENERAL_CONFIG_FORM;
329  }
330 
331  if (!strlen($_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD])) {
332  return self::CMD_SHOW_GENERAL_CONFIG_FORM;
333  }
334 
335  return $_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD];
336  }
337 
339  {
340  if ($form === null) {
341  $this->questionSetConfig->loadFromDb();
342  $form = $this->buildGeneralConfigFormGUI();
343  }
344 
345  $this->tpl->setContent($this->ctrl->getHTML($form));
346 
347  $this->configStateMessageHandler->setContext(
349  );
350 
351  $this->configStateMessageHandler->handle();
352 
353  if ($this->configStateMessageHandler->hasValidationReports()) {
354  if ($this->configStateMessageHandler->isValidationFailed()) {
356  $this->configStateMessageHandler->getValidationReportHtml()
357  );
358  } else {
359  ilUtil::sendInfo($this->configStateMessageHandler->getValidationReportHtml());
360  }
361  }
362 
363  if (isset($_GET['modified']) && (int) $_GET['modified']) {
364  ilUtil::sendSuccess($this->getGeneralModificationSuccessMessage());
365  }
366  }
367 
368  private function saveGeneralConfigFormCmd()
369  {
370  $this->questionSetConfig->loadFromDb();
371 
372  $form = $this->buildGeneralConfigFormGUI();
373 
374  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
375  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
376 
377  if ($errors) {
378  return $this->showGeneralConfigFormCmd($form);
379  }
380 
381  $form->save();
382 
383  $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
384  $this->questionSetConfig->saveToDb();
385 
386  $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
387 
388  $this->ctrl->setParameter($this, 'modified', 1);
389  $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
390  }
391 
392  private function buildGeneralConfigFormGUI()
393  {
394  require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetGeneralConfigFormGUI.php';
395 
397  $this->ctrl,
398  $this->lng,
399  $this->testOBJ,
400  $this,
401  $this->questionSetConfig
402  );
403 
404  $form->setEditModeEnabled(!$this->isFrozenConfigRequired());
405 
406  $form->build();
407 
408  return $form;
409  }
410 
412  {
413  $this->questionSetConfig->loadFromDb();
414 
415  $content = '';
416 
417  if (!$this->isFrozenConfigRequired()) {
418  $toolbar = $this->buildSourcePoolDefinitionListToolbarGUI();
419  $content .= $this->ctrl->getHTML($toolbar);
420  }
421 
422  $table = $this->buildSourcePoolDefinitionListTableGUI();
423  $table->init($this->sourcePoolDefinitionList);
424  $content .= $this->ctrl->getHTML($table);
425 
426  if (!$this->sourcePoolDefinitionList->areAllUsedPoolsAvailable()) {
427  $table = $this->buildNonAvailablePoolsTableGUI();
428  $table->init($this->sourcePoolDefinitionList);
429  $content .= $this->ctrl->getHTML($table);
430  }
431 
432  $this->tpl->setContent($content);
433 
434  $this->configStateMessageHandler->setContext(
436  );
437 
438  $this->configStateMessageHandler->handle();
439 
440  if ($this->configStateMessageHandler->hasValidationReports()) {
441  if ($this->configStateMessageHandler->isValidationFailed()) {
443  $this->configStateMessageHandler->getValidationReportHtml()
444  );
445  } else {
446  ilUtil::sendInfo($this->configStateMessageHandler->getValidationReportHtml());
447  }
448  }
449 
450  if (isset($_GET['modified']) && (int) $_GET['modified']) {
451  ilUtil::sendSuccess($this->getGeneralModificationSuccessMessage());
452  }
453  }
454 
456  {
457  $this->questionSetConfig->loadFromDb();
458 
459  $table = $this->buildSourcePoolDefinitionListTableGUI();
460 
461  $table->applySubmit($this->sourcePoolDefinitionList);
462 
463  $this->sourcePoolDefinitionList->reindexPositions();
464  $this->sourcePoolDefinitionList->saveDefinitions();
465 
466  // fau: delayCopyRandomQuestions - don't rebuild the staging pool, just clear the sycn timestamp
467  #$this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
468  #$this->sourcePoolDefinitionList->saveDefinitions();
469  #$this->questionSetConfig->setLastQuestionSyncTimestamp(time());
470  $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
471  // fau.
472  $this->questionSetConfig->saveToDb();
473 
474  $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
475 
476  $this->ctrl->setParameter($this, 'modified', 1);
477  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
478  }
479 
481  {
482  require_once 'Modules/Test/classes/toolbars/class.ilTestRandomQuestionSetSourcePoolDefinitionListToolbarGUI.php';
483 
485  $this->ctrl,
486  $this->lng,
487  $this,
488  $this->questionSetConfig
489  );
490 
491  $toolbar->build();
492 
493  return $toolbar;
494  }
495 
497  {
498  require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php';
499 
501  $this->ctrl,
502  $this->lng,
503  $this,
504  self::CMD_SHOW_SRC_POOL_DEF_LIST
505  );
506 
507  if (!$this->isFrozenConfigRequired()) {
508  $table->setDefinitionEditModeEnabled(true);
509  }
510 
511  $table->setQuestionAmountColumnEnabled(
512  $this->questionSetConfig->isQuestionAmountConfigurationModePerPool()
513  );
514 
515  // fau: taxFilter/typeFilter - show the mapped taxonomy filters if pools are synced
516  $table->setShowMappedTaxonomyFilter(
517  $this->questionSetConfig->getLastQuestionSyncTimestamp() != 0
518  );
519  // fau.
520 
521  require_once 'Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php';
522  $translater = new ilTestTaxonomyFilterLabelTranslater($this->db);
523  $translater->loadLabels($this->sourcePoolDefinitionList);
524  $table->setTaxonomyFilterLabelTranslater($translater);
525 
526  $table->build();
527 
528  return $table;
529  }
530 
532  {
533  require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetNonAvailablePoolsTableGUI.php';
534 
536  $this->ctrl,
537  $this->lng,
538  $this,
539  self::CMD_SHOW_SRC_POOL_DEF_LIST
540  );
541 
542  $table->build();
543 
544  return $table;
545  }
546 
548  {
549  $definitionId = $this->fetchSingleSourcePoolDefinitionIdParameter();
550  $this->deleteSourcePoolDefinitions(array($definitionId));
551 
552  ilUtil::sendSuccess($this->lng->txt("tst_msg_source_pool_definitions_deleted"), true);
553  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
554  }
555 
557  {
558  $definitionIds = $this->fetchMultiSourcePoolDefinitionIdsParameter();
559  $this->deleteSourcePoolDefinitions($definitionIds);
560 
561  ilUtil::sendSuccess($this->lng->txt("tst_msg_source_pool_definitions_deleted"), true);
562  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
563  }
564 
565  private function deleteSourcePoolDefinitions($definitionIds)
566  {
567  foreach ($definitionIds as $definitionId) {
568  $definition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($definitionId);
569  $definition->deleteFromDb();
570  }
571 
572  $this->sourcePoolDefinitionList->reindexPositions();
573  $this->sourcePoolDefinitionList->saveDefinitions();
574 
575  $this->questionSetConfig->loadFromDb();
576  $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
577  $this->questionSetConfig->saveToDb();
578 
579  $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
580  }
581 
582  // hey: randomPoolSelector - new pool selector explorer command
583  protected function showPoolSelectorExplorerCmd()
584  {
585  $this->questionSetConfig->loadFromDb();
586 
587  require_once 'Services/Repository/classes/class.ilTestQuestionPoolSelectorExplorer.php';
588  $selector = new ilTestQuestionPoolSelectorExplorer(
589  $this,
590  self::CMD_SHOW_POOL_SELECTOR_EXPLORER,
591  self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM
592  );
593 
594  $selector->setAvailableQuestionPools(
595  array_keys($this->questionSetConfig->getSelectableQuestionPools())
596  );
597 
598  if ($selector->handleCommand()) {
599  return;
600  }
601 
602  $this->tpl->setContent($selector->getHTML());
603  }
604  // hey.
605 
607  {
608  $this->questionSetConfig->loadFromDb();
609 
610  $poolId = $this->fetchQuestionPoolIdParameter();
611 
612  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
613  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
614 
615  if ($form === null) {
617  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
618  }
619 
620  $this->tpl->setContent($this->ctrl->getHTML($form));
621  }
622 
624  {
626  }
627 
631  private function saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form = false)
632  {
633  $this->questionSetConfig->loadFromDb();
634 
635  $poolId = $this->fetchQuestionPoolIdParameter();
636  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
637  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
638 
640  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
641 
642  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
643  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
644 
645  if ($errors) {
646  return $this->showCreateSourcePoolDefinitionFormCmd($form);
647  }
648 
649  $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
650 
651  $sourcePoolDefinition->setSequencePosition($this->sourcePoolDefinitionList->getNextPosition());
652  $sourcePoolDefinition->saveToDb();
653  $this->sourcePoolDefinitionList->addDefinition($sourcePoolDefinition);
654 
655  $this->sourcePoolDefinitionList->saveDefinitions();
656 
657  $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
658  $this->questionSetConfig->saveToDb();
659 
660  $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
661 
662  if ($redirect_back_to_form) {
663  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_qsc_modified_add_new_rule"), true);
664  $this->ctrl->setParameter($this, 'src_pool_def_id', $sourcePoolDefinition->getId());
665  $this->ctrl->setParameter($this, 'quest_pool_id', $sourcePoolDefinition->getPoolId());
666  $this->ctrl->redirect($this, self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM);
667  } else {
668  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
669  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
670  }
671  }
672 
674  {
675  require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php';
676 
678  $this->ctrl,
679  $this->lng,
680  $this->testOBJ,
681  $this,
682  $this->questionSetConfig
683  );
684 
685  $form->setSaveCommand(self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM);
686  $form->setSaveAndNewCommand(self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM);
687 
688  return $form;
689  }
690 
692  {
693  $this->questionSetConfig->loadFromDb();
694 
696  $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($defId);
697  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
698 
699  if ($form === null) {
700  $form = $this->buildEditSourcePoolDefinitionFormGUI();
701  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
702  }
703 
704  $this->tpl->setContent($this->ctrl->getHTML($form));
705  }
706 
708  {
709  $this->questionSetConfig->loadFromDb();
710 
712  $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($defId);
713  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
714 
715  $form = $this->buildEditSourcePoolDefinitionFormGUI();
716  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
717 
718  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
719  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
720 
721  if ($errors) {
722  return $this->showSourcePoolDefinitionListCmd($form);
723  }
724 
725  $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
726 
727  $sourcePoolDefinition->saveToDb();
728 
729  $this->questionSetConfig->setLastQuestionSyncTimestamp(0);
730  $this->questionSetConfig->saveToDb();
731 
732  $this->testOBJ->saveCompleteStatus($this->questionSetConfig);
733 
734  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
735  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
736  }
737 
739  {
740  require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php';
741 
743  $this->ctrl,
744  $this->lng,
745  $this->testOBJ,
746  $this,
747  $this->questionSetConfig
748  );
749 
750  $form->setSaveCommand(self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM);
751 
752  return $form;
753  }
754 
755  private function fetchQuestionPoolIdParameter()
756  {
757  if (isset($_POST['quest_pool_id']) && (int) $_POST['quest_pool_id']) {
758  return (int) $_POST['quest_pool_id'];
759  }
760 
761  if (isset($_GET['quest_pool_id']) && (int) $_GET['quest_pool_id']) {
762  return (int) $_GET['quest_pool_id'];
763  }
764 
765  if (isset($_GET['quest_pool_ref']) && (int) $_GET['quest_pool_ref']) {
766  global $DIC; /* @var ILIAS\DI\Container $DIC */
767  /* @var ilObjectDataCache $objCache */
768  $objCache = $DIC['ilObjDataCache'];
769 
770  return $objCache->lookupObjId((int) $_GET['quest_pool_ref']);
771  }
772 
773  require_once 'Modules/Test/exceptions/class.ilTestMissingQuestionPoolIdParameterException.php';
775  }
776 
778  {
779  if (isset($_POST['src_pool_def_id']) && (int) $_POST['src_pool_def_id']) {
780  return (int) $_POST['src_pool_def_id'];
781  }
782 
783  if (isset($_GET['src_pool_def_id']) && (int) $_GET['src_pool_def_id']) {
784  return (int) $_GET['src_pool_def_id'];
785  }
786 
787  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
789  }
790 
792  {
793  if (!isset($_POST['src_pool_def_ids']) || !is_array($_POST['src_pool_def_ids'])) {
794  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
796  }
797 
798  $definitionIds = array();
799 
800  foreach ($_POST['src_pool_def_ids'] as $definitionId) {
801  $definitionId = (int) $definitionId;
802 
803  if (!$definitionId) {
804  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
806  }
807 
808  $definitionIds[] = $definitionId;
809  }
810 
811  return $definitionIds;
812  }
813 
815  {
816  $availablePools = $this->testOBJ->getAvailableQuestionpools(
817  true,
818  $this->questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired(),
819  false,
820  true,
821  true
822  );
823 
824  if (isset($availablePools[$poolId])) {
825  $originalPoolData = $availablePools[$poolId];
826 
827  $originalPoolData['qpl_path'] = $this->questionSetConfig->getQuestionPoolPathString($poolId);
828  $originalPoolData['qpl_ref_id'] = $this->questionSetConfig->getFirstQuestionPoolRefIdByObjId($poolId);
829 
830  return $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByOriginalPoolData($originalPoolData);
831  }
832 
833  require_once 'Modules/Test/exceptions/class.ilTestQuestionPoolNotAvailableAsSourcePoolException.php';
835  }
836 
837  protected function fetchPoolIdsParameter()
838  {
839  if (isset($_POST['derive_pool_ids']) && is_array($_POST['derive_pool_ids'])) {
840  $poolIds = array();
841 
842  foreach ($_POST['derive_pool_ids'] as $poolId) {
843  $poolIds[] = (int) $poolId;
844  }
845  } elseif (isset($_GET['derive_pool_ids']) && preg_match('/^\d+(\:\d+)*$/', $_GET['derive_pool_ids'])) {
846  $poolIds = explode(':', $_GET['derive_pool_ids']);
847  } elseif (isset($_GET['derive_pool_id']) && (int) $_GET['derive_pool_id']) {
848  $poolIds = array( (int) $_GET['derive_pool_id'] );
849  }
850 
851  return $poolIds;
852  }
853 
854  protected function fetchTargetRefParameter()
855  {
856  if (isset($_GET['target_ref']) && (int) $_GET['target_ref']) {
857  return (int) $_GET['target_ref'];
858  }
859 
860  return null;
861  }
862 
863  private function selectPoolDerivationTargetCmd()
864  {
865  $this->ctrl->setParameter($this, 'derive_pool_ids', implode(':', $this->fetchPoolIdsParameter()));
866 
867  require_once 'Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php';
868  $explorer = new ilRepositorySelectorExplorerGUI(
869  $this,
870  self::CMD_SELECT_DERIVATION_TARGET,
871  $this,
872  self::CMD_DERIVE_NEW_POOLS,
873  'target_ref'
874  );
875  $explorer->setClickableTypes($this->objDefinition->getExplorerContainerTypes());
876  $explorer->setSelectableTypes(array());
877 
878  if (!$explorer->handleCommand()) {
879  ilUtil::sendInfo($this->lng->txt('tst_please_select_target_for_pool_derives'));
880  $this->tpl->setContent($this->ctrl->getHTML($explorer));
881  }
882  }
883 
884  private function deriveNewPoolsCmd()
885  {
886  $poolIds = $this->fetchPoolIdsParameter();
887  $targetRef = $this->fetchTargetRefParameter();
888 
889  if (count($poolIds)) {
890  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetPoolDeriver.php';
891 
892  foreach ($poolIds as $poolId) {
893  $lostPool = $this->sourcePoolDefinitionList->getLostPool($poolId);
894 
895  $deriver = new ilTestRandomQuestionSetPoolDeriver($this->db, $this->pluginAdmin, $this->testOBJ);
896  $deriver->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
897  $deriver->setTargetContainerRef($targetRef);
898  $deriver->setOwnerId($GLOBALS['DIC']['ilUser']->getId());
899  $newPool = $deriver->derive($lostPool);
900 
901  $srcPoolDefinition = $this->sourcePoolDefinitionList->getDefinitionBySourcePoolId($newPool->getId());
902  $srcPoolDefinition->setPoolTitle($newPool->getTitle());
903  $srcPoolDefinition->setPoolPath($this->questionSetConfig->getQuestionPoolPathString($newPool->getId()));
904  $srcPoolDefinition->setPoolRefId($this->questionSetConfig->getFirstQuestionPoolRefIdByObjId((int) $newPool->getId()));
905  $srcPoolDefinition->saveToDb();
906 
908  $this->testOBJ->getTestId(),
909  $lostPool->getId(),
910  $newPool->getId()
911  );
912  }
913 
914  ilUtil::sendSuccess($this->lng->txt('tst_non_available_pool_newly_derived'), true);
915  }
916 
917  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
918  }
919 
924  {
925  return $this->lng->txt("tst_msg_random_question_set_config_modified");
926  }
927 
931  public function getGeneralConfigTabLabel()
932  {
933  return $this->lng->txt('tst_rnd_quest_cfg_tab_general');
934  }
935 
939  public function getPoolConfigTabLabel()
940  {
941  return $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
942  }
943 }
$errors
This class provides processing control methods.
Explorer for selecting repository items.
Tabs GUI.
static getUsageOfObject($a_obj_id, $a_include_titles=false)
Get usage of object.
$_GET["client_id"]
Interface ilAccessHandler.
Administration class for plugins.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
showEditSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
Interface ilDBInterface.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form=false)
__construct(ilCtrl $ctrl, ilAccessHandler $access, ilTabsGUI $tabs, ilLanguage $lng, ilGlobalTemplateInterface $tpl, ilDBInterface $db, ilTree $tree, ilPluginAdmin $pluginAdmin, ilObjTest $testOBJ, ilTestProcessLockerFactory $processLockerFactory)
$DIC
Definition: xapitoken.php:46
language handling
showGeneralConfigFormCmd(ilTestRandomQuestionSetGeneralConfigFormGUI $form=null)
showCreateSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
$_POST["username"]