ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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_CREATE_SRC_POOL_DEF_FORM = 'showCreateSourcePoolDefinitionForm';
36  const CMD_SAVE_CREATE_SRC_POOL_DEF_FORM = 'saveCreateSourcePoolDefinitionForm';
37  const CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM = 'saveCreateAndNewSourcePoolDefinitionForm';
38  const CMD_SHOW_EDIT_SRC_POOL_DEF_FORM = 'showEditSourcePoolDefinitionForm';
39  const CMD_SAVE_EDIT_SRC_POOL_DEF_FORM = 'saveEditSourcePoolDefinitionForm';
40  const CMD_BUILD_QUESTION_STAGE = 'buildQuestionStage';
41  const CMD_SELECT_DERIVATION_TARGET = 'selectPoolDerivationTarget';
42  const CMD_DERIVE_NEW_POOLS = 'deriveNewPools';
43 
44  const HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD = 'afterRebuildQuestionStageCmd';
48  public $ctrl = null;
49 
53  public $access = null;
54 
58  public $tabs = null;
59 
63  public $lng = null;
64 
68  public $tpl = null;
69 
73  public $db = null;
74 
78  public $tree = null;
79 
83  public $pluginAdmin = null;
84 
88  public $objDefinition = null;
89 
93  public $testOBJ = null;
94 
98  protected $questionSetConfig = null;
99 
104 
108  protected $sourcePoolDefinitionList= null;
109 
113  protected $stagingPool = null;
114 
119 
120  public function __construct(
123  )
124  {
125  $this->ctrl = $ctrl;
126  $this->access = $access;
127  $this->tabs = $tabs;
128  $this->lng = $lng;
129  $this->tpl = $tpl;
130  $this->db = $db;
131  $this->tree = $tree;
132  $this->pluginAdmin = $pluginAdmin;
133  $this->objDefinition = $GLOBALS['DIC']['objDefinition'];
134  $this->testOBJ = $testOBJ;
135 
136  $this->questionSetConfig = new ilTestRandomQuestionSetConfig(
137  $this->tree, $this->db, $this->pluginAdmin, $this->testOBJ
138  );
139 
140  $this->sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
141  $this->db, $this->testOBJ
142  );
143 
144  $this->sourcePoolDefinitionList = new ilTestRandomQuestionSetSourcePoolDefinitionList(
145  $this->db, $this->testOBJ, $this->sourcePoolDefinitionFactory
146  );
147 
148  $this->stagingPool = new ilTestRandomQuestionSetStagingPoolBuilder(
149  $this->db, $this->testOBJ
150  );
151 
152  $this->configStateMessageHandler = new ilTestRandomQuestionSetConfigStateMessageHandler(
153  $this->lng, $this->ctrl
154  );
155 
156  $this->configStateMessageHandler->setTargetGUI($this);
157  $this->configStateMessageHandler->setQuestionSetConfig($this->questionSetConfig);
158  $this->configStateMessageHandler->setParticipantDataExists($this->testOBJ->participantDataExist());
159  }
160 
161  public function executeCommand()
162  {
163  if (!$this->access->checkAccess("write", "", $this->testOBJ->getRefId()))
164  {
165  ilUtil::sendFailure($this->lng->txt("cannot_edit_test"), true);
166  $this->ctrl->redirectByClass('ilObjTestGUI', "infoScreen");
167  }
168 
170  {
171  ilUtil::sendFailure($this->lng->txt("tst_msg_cannot_modify_random_question_set_conf_due_to_part"), true);
172  $this->ctrl->redirect($this);
173  }
174 
175  $this->handleTabs();
176 
177  $nextClass = $this->ctrl->getNextClass();
178 
179  switch($nextClass)
180  {
181  case 'iltestrandomquestionsetpooldefinitionformgui':
182  $this->questionSetConfig->loadFromDb();
183  $poolId = $this->fetchQuestionPoolIdParameter();
184  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
185  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
187  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
188 
189  $this->ctrl->forwardCommand($form);
190  break;
191 
192  default:
193 
194  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM).'Cmd';
195 
196  $this->$cmd();
197  }
198  }
199 
201  {
202  if( !$this->isFrozenConfigRequired() )
203  {
204  return false;
205  }
206 
207  if( !$this->isManipulationCommand() )
208  {
209  return false;
210  }
211 
212  return true;
213  }
214 
215  private function isFrozenConfigRequired()
216  {
217  if( $this->testOBJ->participantDataExist() )
218  {
219  return true;
220  }
221 
222  $this->sourcePoolDefinitionList->loadDefinitions();
223 
224  if( $this->sourcePoolDefinitionList->hasLostPool() )
225  {
226  return true;
227  }
228 
229  return false;
230  }
231 
232  private function isManipulationCommand()
233  {
234  switch( $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM) )
235  {
236  case self::CMD_SAVE_GENERAL_CONFIG_FORM:
237  case self::CMD_SAVE_SRC_POOL_DEF_LIST:
238  case self::CMD_DELETE_SINGLE_SRC_POOL_DEF:
239  case self::CMD_DELETE_MULTI_SRC_POOL_DEFS:
240  case self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM:
241  case self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM:
242  case self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM:
243  case self::CMD_BUILD_QUESTION_STAGE:
244 
245  return true;
246  }
247 
248  return false;
249  }
250 
251  private function handleTabs()
252  {
253  $this->tabs->activateTab('assQuestions');
254 
255  $this->tabs->addSubTab(
256  'tstRandQuestSetGeneralConfig',
257  $this->lng->txt('tst_rnd_quest_cfg_tab_general'),
258  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_GENERAL_CONFIG_FORM)
259  );
260 
261  $this->tabs->addSubTab(
262  'tstRandQuestSetPoolConfig',
263  $this->lng->txt('tst_rnd_quest_cfg_tab_pool'),
264  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_SRC_POOL_DEF_LIST)
265  );
266 
267  switch( $this->ctrl->getCmd(self::CMD_SHOW_GENERAL_CONFIG_FORM) )
268  {
269  case self::CMD_SHOW_GENERAL_CONFIG_FORM:
270  case self::CMD_SAVE_GENERAL_CONFIG_FORM:
271 
272  $this->tabs->activateSubTab('tstRandQuestSetGeneralConfig');
273  break;
274 
275  case self::CMD_SHOW_SRC_POOL_DEF_LIST:
276  case self::CMD_SAVE_SRC_POOL_DEF_LIST:
277  case self::CMD_DELETE_SINGLE_SRC_POOL_DEF:
278  case self::CMD_DELETE_MULTI_SRC_POOL_DEFS:
279  case self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM:
280  case self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM:
281  case self::CMD_SHOW_EDIT_SRC_POOL_DEF_FORM:
282  case self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM:
283 
284  $this->tabs->activateSubTab('tstRandQuestSetPoolConfig');
285  break;
286 
287  default: $this->tabs->activateSubTab('nonTab');
288  }
289  }
290 
291  private function buildQuestionStageCmd()
292  {
293  $this->sourcePoolDefinitionList->loadDefinitions();
294  $this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
295  $this->sourcePoolDefinitionList->saveDefinitions();
296 
297  $this->questionSetConfig->loadFromDb();
298  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
299  $this->questionSetConfig->saveToDb();
300 
301  $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
302 
303  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_synced"), true);
304  $this->ctrl->redirect($this, $this->fetchAfterRebuildQuestionStageCmdParameter());
305  }
306 
308  {
309  if( !isset($_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD]) )
310  {
311  return self::CMD_SHOW_GENERAL_CONFIG_FORM;
312  }
313 
314  if( !strlen($_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD]) )
315  {
316  return self::CMD_SHOW_GENERAL_CONFIG_FORM;
317  }
318 
319  return $_GET[self::HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD];
320  }
321 
323  {
324  if($form === null)
325  {
326  $this->questionSetConfig->loadFromDb();
327  $form = $this->buildGeneralConfigFormGUI();
328  }
329 
330  $this->tpl->setContent( $this->ctrl->getHTML($form) );
331 
332  $this->configStateMessageHandler->setContext(
334  );
335 
336  $this->configStateMessageHandler->setLostPools(
337  $this->sourcePoolDefinitionList->getLostPools()
338  );
339 
340  $this->configStateMessageHandler->handle();
341  }
342 
343  private function saveGeneralConfigFormCmd()
344  {
345  $this->questionSetConfig->loadFromDb();
346 
347  $form = $this->buildGeneralConfigFormGUI();
348 
349  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
350  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
351 
352  if($errors)
353  {
354  return $this->showGeneralConfigFormCmd($form);
355  }
356 
357  $form->save();
358 
359  $this->sourcePoolDefinitionList->loadDefinitions();
360  $this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
361  $this->sourcePoolDefinitionList->saveDefinitions();
362 
363  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
364  $this->questionSetConfig->saveToDb();
365 
366  $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
367 
368  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
369  $this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
370  }
371 
372  private function buildGeneralConfigFormGUI()
373  {
374  require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetGeneralConfigFormGUI.php';
375 
377  $this->ctrl, $this->lng, $this->testOBJ, $this, $this->questionSetConfig
378  );
379 
380  $form->setEditModeEnabled(!$this->isFrozenConfigRequired());
381 
382  $form->build();
383 
384  return $form;
385  }
386 
388  {
389  $this->questionSetConfig->loadFromDb();
390  $this->sourcePoolDefinitionList->loadDefinitions();
391 
392  $content = '';
393 
394  if( !$this->isFrozenConfigRequired() )
395  {
396  $toolbar = $this->buildSourcePoolDefinitionListToolbarGUI();
397  $content .= $this->ctrl->getHTML($toolbar);
398  }
399 
400  $table = $this->buildSourcePoolDefinitionListTableGUI();
401  $table->init( $this->sourcePoolDefinitionList);
402  $content .= $this->ctrl->getHTML($table);
403 
404  if( !$this->sourcePoolDefinitionList->areAllUsedPoolsAvailable() )
405  {
406  $table = $this->buildNonAvailablePoolsTableGUI();
407  $table->init($this->sourcePoolDefinitionList);
408  $content .= $this->ctrl->getHTML($table);
409  }
410 
411  $this->tpl->setContent($content);
412 
413  $this->configStateMessageHandler->setContext(
415  );
416 
417  $this->configStateMessageHandler->setLostPools(
418  $this->sourcePoolDefinitionList->getLostPools()
419  );
420 
421  $this->configStateMessageHandler->handle();
422  }
423 
425  {
426  $this->questionSetConfig->loadFromDb();
427 
428  $table = $this->buildSourcePoolDefinitionListTableGUI();
429 
430  $this->sourcePoolDefinitionList->loadDefinitions();
431 
432  $table->applySubmit($this->sourcePoolDefinitionList);
433 
434  $this->sourcePoolDefinitionList->reindexPositions();
435  $this->sourcePoolDefinitionList->saveDefinitions();
436 
437  $this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
438  $this->sourcePoolDefinitionList->saveDefinitions();
439 
440  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
441  $this->questionSetConfig->saveToDb();
442 
443  $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
444 
445  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
446  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
447  }
448 
450  {
451  require_once 'Modules/Test/classes/toolbars/class.ilTestRandomQuestionSetSourcePoolDefinitionListToolbarGUI.php';
452 
454  $this->ctrl, $this->lng, $this, $this->questionSetConfig
455  );
456 
457  $toolbar->build();
458 
459  return $toolbar;
460  }
461 
463  {
464  require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php';
465 
467  $this->ctrl, $this->lng, $this, self::CMD_SHOW_SRC_POOL_DEF_LIST
468  );
469 
470  if( !$this->isFrozenConfigRequired() )
471  {
472  $table->setDefinitionEditModeEnabled(true);
473  }
474 
475  $table->setQuestionAmountColumnEnabled(
476  $this->questionSetConfig->isQuestionAmountConfigurationModePerPool()
477  );
478 
479  require_once 'Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php';
480  $translater = new ilTestTaxonomyFilterLabelTranslater($this->db);
481  $translater->loadLabels($this->sourcePoolDefinitionList);
482  $table->setTaxonomyFilterLabelTranslater($translater);
483 
484  $table->build();
485 
486  return $table;
487  }
488 
490  {
491  require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetNonAvailablePoolsTableGUI.php';
492 
494  $this->ctrl, $this->lng, $this, self::CMD_SHOW_SRC_POOL_DEF_LIST
495  );
496 
497  $table->build();
498 
499  return $table;
500  }
501 
503  {
504  $definitionId = $this->fetchSingleSourcePoolDefinitionIdParameter();
505  $this->deleteSourcePoolDefinitions( array($definitionId) );
506 
507  ilUtil::sendSuccess($this->lng->txt("tst_msg_source_pool_definitions_deleted"), true);
508  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
509  }
510 
512  {
513  $definitionIds = $this->fetchMultiSourcePoolDefinitionIdsParameter();
514  $this->deleteSourcePoolDefinitions( $definitionIds );
515 
516  ilUtil::sendSuccess($this->lng->txt("tst_msg_source_pool_definitions_deleted"), true);
517  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
518  }
519 
520  private function deleteSourcePoolDefinitions($definitionIds)
521  {
522  foreach($definitionIds as $definitionId)
523  {
524  $definition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($definitionId);
525  $definition->deleteFromDb();
526  }
527 
528  $this->sourcePoolDefinitionList->loadDefinitions();
529  $this->sourcePoolDefinitionList->reindexPositions();
530  $this->sourcePoolDefinitionList->saveDefinitions();
531 
532  $this->sourcePoolDefinitionList->loadDefinitions();
533  $this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
534  $this->sourcePoolDefinitionList->saveDefinitions();
535 
536  // Bugfix for mantis: 0015082
537  $this->questionSetConfig->loadFromDb();
538  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
539  $this->questionSetConfig->saveToDb();
540 
541  $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
542  }
543 
545  {
546  $this->questionSetConfig->loadFromDb();
547 
548  $poolId = $this->fetchQuestionPoolIdParameter();
549 
550  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
551  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
552 
553  if($form === null)
554  {
556  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
557  }
558 
559  $this->tpl->setContent( $this->ctrl->getHTML($form) );
560  }
561 
563  {
565  }
566 
570  private function saveCreateSourcePoolDefinitionFormCmd($redirect_back_to_form = false)
571  {
572  $this->questionSetConfig->loadFromDb();
573 
574  $poolId = $this->fetchQuestionPoolIdParameter();
575  $sourcePoolDefinition = $this->getSourcePoolDefinitionByAvailableQuestionPoolId($poolId);
576  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
577 
579  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
580 
581  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
582  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
583 
584  if($errors)
585  {
586  return $this->showCreateSourcePoolDefinitionFormCmd($form);
587  }
588 
589  $form->applySubmit( $sourcePoolDefinition, $availableTaxonomyIds );
590 
591  $this->sourcePoolDefinitionList->loadDefinitions();
592  $sourcePoolDefinition->setSequencePosition( $this->sourcePoolDefinitionList->getNextPosition() );
593  $sourcePoolDefinition->saveToDb();
594  $this->sourcePoolDefinitionList->addDefinition($sourcePoolDefinition);
595 
596  $this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
597  $this->sourcePoolDefinitionList->saveDefinitions();
598 
599  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
600  $this->questionSetConfig->saveToDb();
601 
602  $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
603 
604  if($redirect_back_to_form)
605  {
606  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_qsc_modified_add_new_rule"), true);
607  $this->ctrl->setParameter($this, 'src_pool_def_id', $sourcePoolDefinition->getId());
608  $this->ctrl->setParameter($this, 'quest_pool_id', $sourcePoolDefinition->getPoolId());
609  $this->ctrl->redirect($this, self::CMD_SHOW_CREATE_SRC_POOL_DEF_FORM);
610  }
611  else
612  {
613  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
614  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
615  }
616  }
617 
619  {
620  require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php';
621 
623  $this->ctrl, $this->lng, $this->testOBJ, $this, $this->questionSetConfig
624  );
625 
626  $form->setSaveCommand(self::CMD_SAVE_CREATE_SRC_POOL_DEF_FORM);
627  $form->setSaveAndNewCommand(self::CMD_SAVE_AND_NEW_CREATE_SRC_POOL_DEF_FORM);
628 
629  return $form;
630  }
631 
633  {
634  $this->questionSetConfig->loadFromDb();
635 
637  $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($defId);
638  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
639 
640  if($form === null)
641  {
642  $form = $this->buildEditSourcePoolDefinitionFormGUI();
643  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
644  }
645 
646  $this->tpl->setContent( $this->ctrl->getHTML($form) );
647  }
648 
650  {
651  $this->questionSetConfig->loadFromDb();
652 
654  $sourcePoolDefinition = $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByDefinitionId($defId);
655  $availableTaxonomyIds = ilObjTaxonomy::getUsageOfObject($sourcePoolDefinition->getPoolId());
656 
657  $form = $this->buildEditSourcePoolDefinitionFormGUI();
658  $form->build($sourcePoolDefinition, $availableTaxonomyIds);
659 
660  $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
661  $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
662 
663  if($errors)
664  {
665  return $this->showSourcePoolDefinitionListCmd($form);
666  }
667 
668  $form->applySubmit($sourcePoolDefinition, $availableTaxonomyIds);
669 
670  $sourcePoolDefinition->saveToDb();
671 
672  $this->sourcePoolDefinitionList->loadDefinitions();
673  $this->stagingPool->rebuild( $this->sourcePoolDefinitionList );
674 
675  $this->questionSetConfig->setLastQuestionSyncTimestamp(time());
676  $this->questionSetConfig->saveToDb();
677 
678  $this->testOBJ->saveCompleteStatus( $this->questionSetConfig );
679 
680  ilUtil::sendSuccess($this->lng->txt("tst_msg_random_question_set_config_modified"), true);
681  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
682  }
683 
685  {
686  require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php';
687 
689  $this->ctrl, $this->lng, $this->testOBJ, $this, $this->questionSetConfig
690  );
691 
692  $form->setSaveCommand(self::CMD_SAVE_EDIT_SRC_POOL_DEF_FORM);
693 
694  return $form;
695  }
696 
697  private function fetchQuestionPoolIdParameter()
698  {
699  if( isset($_POST['quest_pool_id']) && (int)$_POST['quest_pool_id'] )
700  {
701  return (int)$_POST['quest_pool_id'];
702  }
703 
704  if( isset($_GET['quest_pool_id']) && (int)$_GET['quest_pool_id'] )
705  {
706  return (int)$_GET['quest_pool_id'];
707  }
708 
709  require_once 'Modules/Test/exceptions/class.ilTestMissingQuestionPoolIdParameterException.php';
711  }
712 
714  {
715  if( isset($_POST['src_pool_def_id']) && (int)$_POST['src_pool_def_id'] )
716  {
717  return (int)$_POST['src_pool_def_id'];
718  }
719 
720  if( isset($_GET['src_pool_def_id']) && (int)$_GET['src_pool_def_id'] )
721  {
722  return (int)$_GET['src_pool_def_id'];
723  }
724 
725  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
727  }
728 
730  {
731  if( !isset($_POST['src_pool_def_ids']) || !is_array($_POST['src_pool_def_ids']) )
732  {
733  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
735  }
736 
737  $definitionIds = array();
738 
739  foreach($_POST['src_pool_def_ids'] as $definitionId)
740  {
741  $definitionId = (int)$definitionId;
742 
743  if( !$definitionId )
744  {
745  require_once 'Modules/Test/exceptions/class.ilTestMissingSourcePoolDefinitionParameterException.php';
747  }
748 
749  $definitionIds[] = $definitionId;
750  }
751 
752  return $definitionIds;
753  }
754 
756  {
757  $availablePools = $this->testOBJ->getAvailableQuestionpools(
758  true, $this->questionSetConfig->arePoolsWithHomogeneousScoredQuestionsRequired(), false, true, true
759  );
760 
761  if( isset($availablePools[$poolId]) )
762  {
763  $originalPoolData = $availablePools[$poolId];
764 
765  $originalPoolData['qpl_path'] = $this->questionSetConfig->getQuestionPoolPathString($poolId);
766 
767  return $this->sourcePoolDefinitionFactory->getSourcePoolDefinitionByOriginalPoolData($originalPoolData);
768  }
769 
770  require_once 'Modules/Test/exceptions/class.ilTestQuestionPoolNotAvailableAsSourcePoolException.php';
772  }
773 
774  protected function fetchPoolIdsParameter()
775  {
776  if( isset($_POST['derive_pool_ids']) && is_array($_POST['derive_pool_ids']) )
777  {
778  $poolIds = array();
779 
780  foreach($_POST['derive_pool_ids'] as $poolId)
781  {
782  $poolIds[] = (int)$poolId;
783  }
784  }
785  elseif( isset($_GET['derive_pool_ids']) && preg_match('/^\d+(\:\d+)*$/', $_GET['derive_pool_ids']))
786  {
787  $poolIds = explode(':', $_GET['derive_pool_ids']);
788  }
789  elseif( isset($_GET['derive_pool_id']) && (int)$_GET['derive_pool_id'])
790  {
791  $poolIds = array( (int)$_GET['derive_pool_id'] );
792  }
793 
794  return $poolIds;
795  }
796 
797  protected function fetchTargetRefParameter()
798  {
799  if( isset($_GET['target_ref']) && (int)$_GET['target_ref'] )
800  {
801  return (int)$_GET['target_ref'];
802  }
803 
804  return null;
805  }
806 
807  private function selectPoolDerivationTargetCmd()
808  {
809  $this->ctrl->setParameter($this, 'derive_pool_ids', implode(':', $this->fetchPoolIdsParameter()));
810 
811  require_once 'Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php';
812  $explorer = new ilRepositorySelectorExplorerGUI(
813  $this, self::CMD_SHOW_SRC_POOL_DEF_LIST, $this, self::CMD_DERIVE_NEW_POOLS, 'target_ref'
814  );
815  $explorer->setClickableTypes($this->objDefinition->getExplorerContainerTypes());
816  $explorer->setSelectableTypes(array());
817 
818  ilUtil::sendInfo($this->lng->txt('tst_please_select_target_for_pool_derives'));
819 
820  $this->tpl->setContent($this->ctrl->getHTML($explorer));
821  }
822 
823  private function deriveNewPoolsCmd()
824  {
825  $poolIds = $this->fetchPoolIdsParameter();
826  $targetRef = $this->fetchTargetRefParameter();
827 
828  if( count($poolIds) )
829  {
830  $this->sourcePoolDefinitionList->loadDefinitions();
831 
832  require_once 'Modules/Test/classes/class.ilTestRandomQuestionSetPoolDeriver.php';
833 
834  foreach($poolIds as $poolId)
835  {
836  $lostPool = $this->sourcePoolDefinitionList->getLostPool($poolId);
837 
838  $deriver = new ilTestRandomQuestionSetPoolDeriver($this->db, $this->pluginAdmin, $this->testOBJ);
839  $deriver->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
840  $deriver->setTargetContainerRef($targetRef);
841  $deriver->setOwnerId($GLOBALS['DIC']['ilUser']->getId());
842  $newPool = $deriver->derive($lostPool);
843 
844  $srcPoolDefinition = $this->sourcePoolDefinitionList->getDefinitionBySourcePoolId($newPool->getId());
845  $srcPoolDefinition->setPoolTitle($newPool->getTitle());
846  $srcPoolDefinition->setPoolPath($this->questionSetConfig->getQuestionPoolPathString($newPool->getId()));
847  $srcPoolDefinition->saveToDb();
848 
850  $this->testOBJ->getTestId(), $lostPool->getId(), $newPool->getId()
851  );
852  }
853 
854  ilUtil::sendSuccess($this->lng->txt('tst_non_available_pool_newly_derived'), true);
855  }
856 
857  $this->ctrl->redirect($this, self::CMD_SHOW_SRC_POOL_DEF_LIST);
858  }
859 }
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.
$cmd
Definition: sahs_server.php:35
Administration class for plugins.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
showEditSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
Interface ilDBInterface.
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
__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.
showGeneralConfigFormCmd(ilTestRandomQuestionSetGeneralConfigFormGUI $form=null)
showCreateSourcePoolDefinitionFormCmd(ilTestRandomQuestionSetPoolDefinitionFormGUI $form=null)
$_POST["username"]
Class ilAccessHandler.