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