Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA 26290, block forms if pool-sync is currently in place #4616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions Modules/Test/classes/class.ilTestRandomQuestionSetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,12 @@ private function insertDbRecord($testId)

public function isQuestionSetConfigured() : bool
{
// fau: delayCopyRandomQuestions - question set is not configured if date of last synchronisation is empty
if ($this->getLastQuestionSyncTimestamp() == 0) {
return false;
}
// fau.

if (!$this->isQuestionAmountConfigComplete()) {
return false;
}

if (!$this->hasSourcePoolDefinitions()) {
return false;
}

if (!$this->isQuestionSetBuildable()) {
return false;
}

return true;
return (
$this->getLastQuestionSyncTimestamp() != 0
&& $this->isQuestionAmountConfigComplete()
&& $this->hasSourcePoolDefinitions()
&& $this->isQuestionSetBuildable()
);
}

public function isQuestionAmountConfigComplete() : bool
Expand Down
132 changes: 99 additions & 33 deletions Modules/Test/classes/class.ilTestRandomQuestionSetConfigGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ilTestRandomQuestionSetConfigGUI
const CMD_BUILD_QUESTION_STAGE = 'buildQuestionStage';
const CMD_SELECT_DERIVATION_TARGET = 'selectPoolDerivationTarget';
const CMD_DERIVE_NEW_POOLS = 'deriveNewPools';
const CMD_RESET_POOLSYNC = 'resetPoolSync';

const HTTP_PARAM_AFTER_REBUILD_QUESTION_STAGE_CMD = 'afterRebuildQuestionStageCmd';
private \ILIAS\Test\InternalRequestService $testrequest;
Expand Down Expand Up @@ -123,6 +124,11 @@ class ilTestRandomQuestionSetConfigGUI
*/
private $processLockerFactory;

/**
* @var ArrayAccess
*/
protected $dic;

public function __construct(
ilCtrl $ctrl,
ilAccessHandler $access,
Expand All @@ -146,15 +152,18 @@ public function __construct(
$this->db = $db;
$this->tree = $tree;
$this->pluginAdmin = $pluginAdmin;
$this->objDefinition = $GLOBALS['DIC']['objDefinition'];
$this->testOBJ = $testOBJ;

$this->dic = $DIC;
$this->objDefinition = $this->dic['objDefinition'];

$this->questionSetConfig = new ilTestRandomQuestionSetConfig(
$this->tree,
$this->db,
$this->pluginAdmin,
$this->testOBJ
);
$this->questionSetConfig->loadFromDb();

$this->sourcePoolDefinitionFactory = new ilTestRandomQuestionSetSourcePoolDefinitionFactory(
$this->db,
Expand Down Expand Up @@ -341,36 +350,38 @@ private function fetchAfterRebuildQuestionStageCmdParameter()

private function showGeneralConfigFormCmd(ilTestRandomQuestionSetGeneralConfigFormGUI $form = null)
{
$disabled_form = $this->preventFormBecauseOfSync();

if ($form === null) {
$this->questionSetConfig->loadFromDb();
$form = $this->buildGeneralConfigFormGUI();
$form = $this->buildGeneralConfigFormGUI($disabled_form);
}

$this->tpl->setContent($this->ctrl->getHTML($form));

$this->configStateMessageHandler->setContext(
ilTestRandomQuestionSetConfigStateMessageHandler::CONTEXT_GENERAL_CONFIG
);

$this->configStateMessageHandler->handle();

if ($this->configStateMessageHandler->hasValidationReports()) {
if ($this->configStateMessageHandler->isValidationFailed()) {
$this->tpl->setOnScreenMessage('failure', $this->configStateMessageHandler->getValidationReportHtml());
} else {
$this->tpl->setOnScreenMessage('info', $this->configStateMessageHandler->getValidationReportHtml());
if (!$disabled_form) {
$this->configStateMessageHandler->setContext(
ilTestRandomQuestionSetConfigStateMessageHandler::CONTEXT_GENERAL_CONFIG
);

$this->configStateMessageHandler->handle();

if ($this->configStateMessageHandler->hasValidationReports()) {
if ($this->configStateMessageHandler->isValidationFailed()) {
$this->tpl->setOnScreenMessage('failure', $this->configStateMessageHandler->getValidationReportHtml());
} else {
$this->tpl->setOnScreenMessage('info', $this->configStateMessageHandler->getValidationReportHtml());
}
}

if ($this->testrequest->isset('modified') && (int) $this->testrequest->raw('modified')) {
$this->tpl->setOnScreenMessage('success', $this->getGeneralModificationSuccessMessage());
}
}

if ($this->testrequest->isset('modified') && (int) $this->testrequest->raw('modified')) {
$this->tpl->setOnScreenMessage('success', $this->getGeneralModificationSuccessMessage());
}
}

private function saveGeneralConfigFormCmd()
{
$this->questionSetConfig->loadFromDb();

$form = $this->buildGeneralConfigFormGUI();

$errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
Expand All @@ -392,7 +403,8 @@ private function saveGeneralConfigFormCmd()
$this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
}

private function buildGeneralConfigFormGUI() : ilTestRandomQuestionSetGeneralConfigFormGUI

private function buildGeneralConfigFormGUI(bool $disabled = false) : ilTestRandomQuestionSetGeneralConfigFormGUI
{
require_once 'Modules/Test/classes/forms/class.ilTestRandomQuestionSetGeneralConfigFormGUI.php';

Expand All @@ -404,9 +416,18 @@ private function buildGeneralConfigFormGUI() : ilTestRandomQuestionSetGeneralCon
$this->questionSetConfig
);

//TODO: should frozen config not lead to 'completely disabled' as well?!
$form->setEditModeEnabled(!$this->isFrozenConfigRequired());


if ($disabled) {
$form->setEditModeEnabled(false);
}

$form->build();

if ($disabled) {
$form->clearCommandButtons();
}

return $form;
}
Expand All @@ -415,25 +436,31 @@ private function showSourcePoolDefinitionListCmd()
{
$this->questionSetConfig->loadFromDb();

$disabled_form = $this->preventFormBecauseOfSync();

$content = '';

if (!$this->isFrozenConfigRequired()) {
if (!$this->isFrozenConfigRequired() && !$disabled_form) {
$toolbar = $this->buildSourcePoolDefinitionListToolbarGUI();
$content .= $this->ctrl->getHTML($toolbar);
}

$table = $this->buildSourcePoolDefinitionListTableGUI();
$table = $this->buildSourcePoolDefinitionListTableGUI($disabled_form);
$table->init($this->sourcePoolDefinitionList);
$content .= $this->ctrl->getHTML($table);
if (!$this->sourcePoolDefinitionList->areAllUsedPoolsAvailable()) {

if ($this->sourcePoolDefinitionList->areAllUsedPoolsAvailable()) {
$table = $this->buildNonAvailablePoolsTableGUI();
$table->init($this->sourcePoolDefinitionList);
$content .= $this->ctrl->getHTML($table);
}

$this->tpl->setContent($content);

if ($disabled_form) {
return;
}

$this->configStateMessageHandler->setContext(
ilTestRandomQuestionSetConfigStateMessageHandler::CONTEXT_POOL_SELECTION
);
Expand Down Expand Up @@ -494,7 +521,7 @@ private function buildSourcePoolDefinitionListToolbarGUI() : ilTestRandomQuestio
return $toolbar;
}

private function buildSourcePoolDefinitionListTableGUI() : ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI
private function buildSourcePoolDefinitionListTableGUI(bool $disabled = false) : ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI
{
require_once 'Modules/Test/classes/tables/class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php';

Expand Down Expand Up @@ -524,6 +551,9 @@ private function buildSourcePoolDefinitionListTableGUI() : ilTestRandomQuestionS
$translater->loadLabels($this->sourcePoolDefinitionList);
$table->setTaxonomyFilterLabelTranslater($translater);

if ($disabled) {
$table->setDefinitionEditModeEnabled(false);
}
$table->build();

return $table;
Expand Down Expand Up @@ -763,10 +793,7 @@ private function fetchQuestionPoolIdParameter() : int
}

if ($this->testrequest->isset('quest_pool_ref') && (int) $this->testrequest->raw('quest_pool_ref')) {
global $DIC; /* @var ILIAS\DI\Container $DIC */
/* @var ilObjectDataCache $objCache */
$objCache = $DIC['ilObjDataCache'];

$objCache = $this->dic['ilObjDataCache'];
return $objCache->lookupObjId((int) $this->testrequest->raw('quest_pool_ref'));
}

Expand Down Expand Up @@ -891,7 +918,7 @@ private function deriveNewPoolsCmd()
$deriver = new ilTestRandomQuestionSetPoolDeriver($this->db, $this->pluginAdmin, $this->testOBJ);
$deriver->setSourcePoolDefinitionList($this->sourcePoolDefinitionList);
$deriver->setTargetContainerRef($targetRef);
$deriver->setOwnerId($GLOBALS['DIC']['ilUser']->getId());
$deriver->setOwnerId($this->dic['ilUser']->getId());
$newPool = $deriver->derive($lostPool);

$srcPoolDefinition = $this->sourcePoolDefinitionList->getDefinitionBySourcePoolId($newPool->getId());
Expand Down Expand Up @@ -936,4 +963,43 @@ public function getPoolConfigTabLabel() : string
{
return $this->lng->txt('tst_rnd_quest_cfg_tab_pool');
}


protected function preventFormBecauseOfSync() : bool
{
$return = false;
$last_sync = $this->questionSetConfig->getLastQuestionSyncTimestamp();
if ($last_sync != 0) {
$return = true;

$sync_date = new ilDateTime($last_sync, IL_CAL_UNIX);
$msg = sprintf(
$this->lng->txt('tst_msg_rand_quest_set_stage_pool_last_sync'),
ilDatePresentation::formatDate($sync_date)
);

$href = $this->ctrl->getLinkTarget($this, self::CMD_RESET_POOLSYNC);
$label = $this->lng->txt('tst_btn_reset_pool_sync');

$buttons = [
$this->dic->ui()->factory()->button()->standard($label, $href)
];

$msgbox = $this->dic->ui()->factory()->messageBox()
->info($msg)
->withButtons($buttons);
$message = $this->dic->ui()->renderer()->render($msgbox);
$this->dic->ui()->mainTemplate()->setCurrentBlock('mess');
$this->dic->ui()->mainTemplate()->setVariable('MESSAGE', $message);
$this->dic->ui()->mainTemplate()->parseCurrentBlock();
}
return $return;
}

public function resetPoolSyncCmd() : void
{
$this->questionSetConfig->setLastQuestionSyncTimestamp(0);
$this->questionSetConfig->saveToDb();
$this->ctrl->redirect($this, self::CMD_SHOW_GENERAL_CONFIG_FORM);
}
}
3 changes: 2 additions & 1 deletion lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -16824,4 +16824,5 @@ notes#:#notes_no_comments_found#:#Es wurden keine Kommentare gefunden, die den S
notes#:#note_text#:#Text
mcst#:#mcst_view_abandoned#:#Die aktuell gewählte Ansicht wird nicht mehr unterstützt. Bitte wählen Sie in den Einstellungen einen andere Ansicht aus.
prtf#:#prtf_copy_pg#:#Seite kopieren
prtf#:#prtf_copy_blog_pg#:#Blogseite kopieren
prtf#:#prtf_copy_blog_pg#:#Blogseite kopieren
assessment#:#tst_btn_reset_pool_sync#:#Bearbeiten/Synchronisation aufheben
3 changes: 2 additions & 1 deletion lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -16810,4 +16810,5 @@ notes#:#notes_no_comments_found#:#No comments found that match your seach criter
notes#:#note_text#:#Text
mcst#:#mcst_view_abandoned#:#The current presentation mode has been abandoned. Please open the settings and switch to another mode.
prtf#:#prtf_copy_pg#:#Copy Page
prtf#:#prtf_copy_blog_pg#:#Copy Blog Page
prtf#:#prtf_copy_blog_pg#:#Copy Blog Page
assessment#:#tst_btn_reset_pool_sync#:#Edit/Cancel Synchronisation