ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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']) {
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']) {
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  /* @var ilObjectDataCache $objCache */
758  $objCache = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilObjDataCache'] : $GLOBALS['ilObjDataCache'];
759 
760  return $objCache->lookupObjId((int) $_GET['quest_pool_ref']);
761  }
762 
763  require_once 'Modules/Test/exceptions/class.ilTestMissingQuestionPoolIdParameterException.php';
765  }
766 
768  {
769  if (isset($_POST['src_pool_def_id']) && (int) $_POST['src_pool_def_id']) {
770  return (int) $_POST['src_pool_def_id'];
771  }
772 
773  if (isset($_GET['src_pool_def_id']) && (int) $_GET['src_pool_def_id']) {
774  return (int) $_GET['src_pool_def_id'];
775  }
776 
777  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
779  }
780 
782  {
783  if (!isset($_POST['src_pool_def_ids']) || !is_array($_POST['src_pool_def_ids'])) {
784  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
786  }
787 
788  $definitionIds = array();
789 
790  foreach ($_POST['src_pool_def_ids'] as $definitionId) {
791  $definitionId = (int) $definitionId;
792 
793  if (!$definitionId) {
794  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
796  }
797 
798  $definitionIds[] = $definitionId;
799  }
800 
801  return $definitionIds;
802  }
803 
805  {
806  $availablePools = $this->testOBJ->getAvailableQuestionpools(
807  true,
808  $this->questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired(),
809  false,
810  true,
811  true
812  );
813 
814  if (isset($availablePools[$poolId])) {
815  $originalPoolData = $availablePools[$poolId];
816 
817  $originalPoolData['qpl_path'] = $this->questionSetConfig->getQuestionPoolPathString($poolId);
818 
819  return $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByOriginalPoolData($originalPoolData);
820  }
821 
822  require_once 'Modules/Test/exceptions/class.ilTestQuestionPoolNotAvailableAsSourcePoolException.php';
824  }
825 
826  protected function fetchPoolIdsParameter()
827  {
828  if (isset($_POST['derive_pool_ids']) && is_array($_POST['derive_pool_ids'])) {
829  $poolIds = array();
830 
831  foreach ($_POST['derive_pool_ids'] as $poolId) {
832  $poolIds[] = (int) $poolId;
833  }
834  } elseif (isset($_GET['derive_pool_ids']) && preg_match('/^\d+(\:\d+)*$/', $_GET['derive_pool_ids'])) {
835  $poolIds = explode(':', $_GET['derive_pool_ids']);
836  } elseif (isset($_GET['derive_pool_id']) && (int) $_GET['derive_pool_id']) {
837  $poolIds = array( (int) $_GET['derive_pool_id'] );
838  }
839 
840  return $poolIds;
841  }
842 
843  protected function fetchTargetRefParameter()
844  {
845  if (isset($_GET['target_ref']) && (int) $_GET['target_ref']) {
846  return (int) $_GET['target_ref'];
847  }
848 
849  return null;
850  }
851 
852  private function selectPoolDerivationTargetCmd()
853  {
854  $this->ctrl->setParameter($this, 'derive_pool_ids', implode(':', $this->fetchPoolIdsParameter()));
855 
856  require_once 'Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php';
857  $explorer = new ilRepositorySelectorExplorerGUI(
858  $this,
859  self::CMD_SELECT_DERIVATION_TARGET,
860  $this,
861  self::CMD_DERIVE_NEW_POOLS,
862  'target_ref'
863  );
864  $explorer->setClickableTypes($this->objDefinition->getExplorerContainerTypes());
865  $explorer->setSelectableTypes(array());
866 
867  if (!$explorer->handleCommand()) {
868  ilUtil::sendInfo($this->lng->txt('tst_please_select_target_for_pool_derives'));
869  $this->tpl->setContent($this->ctrl->getHTML($explorer));
870  }
871  }
872 
873  private function deriveNewPoolsCmd()
874  {
875  $poolIds = $this->fetchPoolIdsParameter();
876  $targetRef = $this->fetchTargetRefParameter();
877 
878  if (count($poolIds)) {
879  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetPoolDeriver.php';
880 
881  foreach ($poolIds as $poolId) {
882  $lostPool = $this->sourcePoolDefinitionList->getLostPool($poolId);
883 
884  $deriver = new ilTestRandomQuestionSetPoolDeriver($this->db, $this->pluginAdmin, $this->testOBJ);
885  $deriver->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
886  $deriver->setTargetContainerRef($targetRef);
887  $deriver->setOwnerId($GLOBALS['DIC']['ilUser']->getId());
888  $newPool = $deriver->derive($lostPool);
889 
890  $srcPoolDefinition = $this->sourcePoolDefinitionList->getDefinitionBySourcePoolId($newPool->getId());
891  $srcPoolDefinition->setPoolTitle($newPool->getTitle());
892  $srcPoolDefinition->setPoolPath($this->questionSetConfig->getQuestionPoolPathString($newPool->getId()));
893  $srcPoolDefinition->saveToDb();
894 
896  $this->testOBJ->getTestId(),
897  $lostPool->getId(),
898  $newPool->getId()
899  );
900  }
901 
902  ilUtil::sendSuccess($this->lng->txt('tst_non_available_pool_newly_derived'), true);
903  }
904 
905  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
906  }
907 
912  {
913  return $this->lng->txt("tst_msg_random_question_set_config_modified");
914  }
915 
919  public function getGeneralConfigTabLabel()
920  {
921  return $this->lng->txt('tst_rnd_quest_cfg_tab_general');
922  }
923 
927  public function getPoolConfigTabLabel()
928  {
929  return $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
930  }
931 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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(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...
Create styles array
The data for the language used.
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
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(empty($password)) $table
Definition: pwgen.php:24
showGeneralConfigFormCmd(ilTestRandomQuestionSetGeneralConfigFormGUI $form=null)
showCreateSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
$_POST["username"]