Skip to content

Commit

Permalink
TA: QuestionList, separate overview- and questionlist settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Sep 12, 2023
1 parent c583db4 commit 350dc05
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,9 @@ private function getParticipantsFunctionalitySettingsForStorage(array $section):
->withUsePreviousAnswerAllowed($section['use_previous_answers'])
->withSuspendTestAllowed($section['allow_suspend_test'])
->withPostponedQuestionsMoveToEnd($section['postponed_questions_behaviour'])
->withQuestionListMode($section['enable_question_list'])
->withQuestionMarkingEnabled($section['enable_question_marking']);
->withUsrPassOverviewMode($section['usr_pass_overview'])
->withQuestionMarkingEnabled($section['enable_question_marking'])
->withQuestionListEnabled($section['enable_question_list']);
}

private function getFinishingSettingsForStorage(array $section): ilObjTestSettingsFinishing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ protected function doSelect(string $where_part): ilObjTestMainSettings
. 'sequence_settings,' . PHP_EOL
. 'show_summary,' . PHP_EOL
. 'show_marker,' . PHP_EOL
. 'show_questionlist,' . PHP_EOL
. 'enable_examview,' . PHP_EOL
. 'showfinalstatement,' . PHP_EOL
. 'finalstatement,' . PHP_EOL
Expand Down Expand Up @@ -169,7 +170,8 @@ protected function doSelect(string $where_part): ilObjTestMainSettings
(bool) $row['show_cancel'],
(bool) $row['sequence_settings'],
$row['show_summary'],
(bool) $row['show_marker']
(bool) $row['show_marker'],
(bool) $row['show_questionlist']
),
new ilObjTestSettingsFinishing(
$test_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public function __construct(
protected bool $use_previous_answers_allowed = false,
protected bool $suspend_test_allowed = false,
protected bool $postponed_questions_move_to_end = false,
protected int $question_list_mode = 0,
protected bool $question_marking_enabled = false
protected int $usrpass_overview_mode = 0,
protected bool $question_marking_enabled = false,
protected bool $question_list_enabled = false
) {
parent::__construct($test_id);
}
Expand Down Expand Up @@ -69,7 +70,12 @@ public function toForm(
)->withValue($this->getPostponedQuestionsMoveToEnd() ? '1' : '0')
->withAdditionalTransformation($refinery->kindlyTo()->bool());

$inputs['enable_question_list'] = $this->getInputEnableQuestionList(
$inputs['enable_question_list'] = $f->checkbox(
$lng->txt('tst_enable_questionlist'),
$lng->txt('tst_enable_questionlist_description')
)->withValue($this->getQuestionListEnabled());

$inputs['usr_pass_overview'] = $this->getInputUsrPassOverview(
$lng,
$f,
$refinery
Expand All @@ -83,7 +89,7 @@ public function toForm(
return $f->section($inputs, $lng->txt('tst_sequence_properties'));
}

private function getInputEnableQuestionList(
private function getInputUsrPassOverview(
\ilLanguage $lng,
FieldFactory $f,
Refinery $refinery
Expand All @@ -94,46 +100,46 @@ static function (?array $vs): int {
return 0;
}

$question_list_mode = 1;
$usrpass_overview_mode = 1;

if ($vs['show_at_beginning'] === true) {
$question_list_mode += 2;
$usrpass_overview_mode += 2;
}

if ($vs['show_at_end'] === true) {
$question_list_mode += 4;
$usrpass_overview_mode += 4;
}

if ($vs['show_description'] === true) {
$question_list_mode += 8;
$usrpass_overview_mode += 8;
}

return $question_list_mode;
return $usrpass_overview_mode;
}
);

$sub_inputs_question_list['show_at_beginning'] = $f->checkbox(
$sub_inputs_usrpass_questionlist['show_at_beginning'] = $f->checkbox(
$lng->txt('tst_list_of_questions_start')
);
$sub_inputs_question_list['show_at_end'] = $f->checkbox(
$sub_inputs_usrpass_questionlist['show_at_end'] = $f->checkbox(
$lng->txt('tst_list_of_questions_end')
);
$sub_inputs_question_list['show_description'] = $f->checkbox(
$sub_inputs_usrpass_questionlist['show_description'] = $f->checkbox(
$lng->txt('tst_list_of_questions_with_description')
);

$enable_question_list = $f->optionalGroup(
$sub_inputs_question_list,
$lng->txt('tst_show_summary'),
$lng->txt('tst_show_summary_description')
$enable_usrpass_questionlist = $f->optionalGroup(
$sub_inputs_usrpass_questionlist,
$lng->txt('Xtst_show_summary'),
$lng->txt('Xtst_show_summary_description')
)->withValue(null)
->withAdditionalTransformation($trafo);

if ($this->getQuestionListEnabled() === false) {
return $enable_question_list;
if ($this->getUsrPassOverviewEnabled() === false) {
return $enable_usrpass_questionlist;
}

return $enable_question_list->withValue(
return $enable_usrpass_questionlist->withValue(
[
'show_at_beginning' => $this->getShownQuestionListAtBeginning(),
'show_at_end' => $this->getShownQuestionListAtEnd(),
Expand All @@ -148,8 +154,9 @@ public function toStorage(): array
'use_previous_answers' => ['integer', (int) $this->getUsePreviousAnswerAllowed()],
'show_cancel' => ['integer', (int) $this->getSuspendTestAllowed()],
'sequence_settings' => ['integer', (int) $this->getPostponedQuestionsMoveToEnd()],
'show_summary' => ['integer', $this->getQuestionListMode()],
'show_marker' => ['integer', (int) $this->getQuestionMarkingEnabled()]
'show_summary' => ['integer', $this->getUsrPassOverviewMode()],
'show_marker' => ['integer', (int) $this->getQuestionMarkingEnabled()],
'show_questionlist' => ['integer', $this->getQuestionListEnabled()]
];
}

Expand Down Expand Up @@ -186,46 +193,57 @@ public function withPostponedQuestionsMoveToEnd(bool $postponed_questions_move_t
return $clone;
}

public function getQuestionListMode(): int
public function getQuestionListEnabled(): bool
{
return $this->question_list_mode;
return $this->question_list_enabled;
}
public function getQuestionListEnabled(): bool
public function withQuestionListEnabled(bool $question_list_enabled): self
{
$clone = clone $this;
$clone->question_list_enabled = $question_list_enabled;
return $clone;
}

public function getUsrPassOverviewMode(): int
{
return $this->usrpass_overview_mode;
}
public function getUsrPassOverviewEnabled(): bool
{
if (($this->question_list_mode & 1) > 0) {
if (($this->usrpass_overview_mode & 1) > 0) {
return true;
}

return false;
}
public function getShownQuestionListAtBeginning(): bool
{
if (($this->question_list_mode & 2) > 0) {
if (($this->usrpass_overview_mode & 2) > 0) {
return true;
}

return false;
}
public function getShownQuestionListAtEnd(): bool
{
if (($this->question_list_mode & 4) > 0) {
if (($this->usrpass_overview_mode & 4) > 0) {
return true;
}

return false;
}
public function getShowDescriptionInQuestionList(): bool
{
if (($this->question_list_mode & 8) > 0) {
if (($this->usrpass_overview_mode & 8) > 0) {
return true;
}

return false;
}
public function withQuestionListMode(int $question_list_mode): self
public function withUsrPassOverviewMode(int $usrpass_overview_mode): self
{
$clone = clone $this;
$clone->question_list_mode = $question_list_mode;
$clone->usrpass_overview_mode = $usrpass_overview_mode;
return $clone;
}

Expand Down
13 changes: 13 additions & 0 deletions Modules/Test/classes/Setup/class.ilTest9DBUpdateSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,17 @@ public function step_7(): void
$this->db->dropTable('tst_seq_qst_postponed');
}
}
public function step_8(): void
{
if (!$this->db->tableColumnExists('tst_tests', 'show_questionlist')) {
$this->db->addTableColumn(
'tst_tests',
'show_questionlist',
[
'type' => 'integer',
'length' => 1
]
);
}
}
}

0 comments on commit 350dc05

Please sign in to comment.