Skip to content

Commit 2949396

Browse files
committed
Test: Show Remaining Time
See: https://mantis.ilias.de/view.php?id=45780
1 parent fbc018e commit 2949396

4 files changed

Lines changed: 50 additions & 33 deletions

File tree

components/ILIAS/Test/classes/class.ilTestPlayerAbstractGUI.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,14 +1839,17 @@ private function outProcessingTime(int $active_id, bool $verbose): void
18391839
$starting_time = $this->object->getStartingTimeOfUser($active_id);
18401840
$working_time = new WorkingTime(
18411841
$this->lng,
1842-
$this->ui_factory,
1843-
$this->ui_renderer,
18441842
$starting_time,
18451843
$this->object->getProcessingTimeInSeconds($active_id)
18461844
);
18471845

18481846
$this->tpl->setCurrentBlock('enableprocessingtime');
1849-
$this->tpl->setVariable('USER_WORKING_TIME_MESSAGE_BOX', $working_time->getMessageBox($verbose));
1847+
$this->tpl->setVariable(
1848+
'USER_WORKING_TIME_MESSAGE_BOX',
1849+
$this->ui_renderer->render(
1850+
$working_time->getMessageBox($this->ui_factory, $verbose)
1851+
)
1852+
);
18501853
$this->tpl->parseCurrentBlock();
18511854

18521855
$working_time_js_template = $working_time->prepareWorkingTimeJsTemplate(

components/ILIAS/Test/classes/class.ilTestSubmissionReviewGUI.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ protected function show(): void
178178
$starting_time = $this->object->getStartingTimeOfUser($active_id);
179179
$working_time = new WorkingTime(
180180
$this->lng,
181-
$this->ui_factory,
182-
$this->ui_renderer,
183181
$starting_time,
184182
$this->object->getProcessingTimeInSeconds($active_id)
185183
);
186184

187-
$html .= $working_time->getMessageBox(true);
185+
$html .= $this->ui_renderer->render(
186+
$working_time->getMessageBox($this->ui_factory, true)
187+
);
188188

189189
$class = $this->getObject()->isFixedTest()
190190
? ilTestPlayerFixedQuestionSetGUI::class

components/ILIAS/Test/src/Presentation/WorkingTime.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,26 @@
2020

2121
namespace ILIAS\Test\Presentation;
2222

23-
use ilDatePresentation;
24-
use ilDateTime;
25-
use ILIAS\UI\Factory;
26-
use ILIAS\UI\Renderer;
27-
use ilLanguage;
28-
use ilObjTest;
29-
use ilTemplate;
23+
use ILIAS\UI\Component\MessageBox\MessageBox;
24+
use ILIAS\UI\Factory as UIFactory;
3025

3126
class WorkingTime
3227
{
3328
public function __construct(
34-
private readonly ilLanguage $lng,
35-
private readonly Factory $ui_factory,
36-
private readonly Renderer $ui_renderer,
37-
private readonly int $starting_time,
29+
private readonly \ilLanguage $lng,
30+
private readonly ?int $starting_time,
3831
private readonly int $processing_time
3932
) {
4033
}
4134

4235
public function prepareWorkingTimeJsTemplate(
43-
ilObjTest $object,
36+
\ilObjTest $object,
4437
array $date,
4538
string $check_url,
4639
string $redirect_url
47-
): ilTemplate {
40+
): \ilTemplate {
4841
[$processing_time_minutes, $processing_time_seconds] = $this->getUserProcessingTimeMinutesAndSeconds();
49-
$template = new ilTemplate('tpl.workingtime.js', true, true, 'components/ILIAS/Test');
42+
$template = new \ilTemplate('tpl.workingtime.js', true, true, 'components/ILIAS/Test');
5043
$template->setVariable('STRING_MINUTE', $this->lng->txt('minute'));
5144
$template->setVariable('STRING_MINUTES', $this->lng->txt('minutes'));
5245
$template->setVariable('STRING_SECOND', $this->lng->txt('second'));
@@ -60,7 +53,7 @@ public function prepareWorkingTimeJsTemplate(
6053
$template->setVariable('MINUTE', $date['minutes']);
6154
$template->setVariable('SECOND', $date['seconds']);
6255
if ($object->isEndingTimeEnabled()) {
63-
$date_time = new ilDateTime($object->getEndingTime(), IL_CAL_UNIX);
56+
$date_time = new \ilDateTime($object->getEndingTime(), IL_CAL_UNIX);
6457
preg_match('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $date_time->get(IL_CAL_TIMESTAMP), $matches);
6558
if ($matches !== []) {
6659
$template->setVariable('ENDYEAR', $matches[1]);
@@ -87,12 +80,22 @@ public function prepareWorkingTimeJsTemplate(
8780
return $template;
8881
}
8982

90-
public function getMessageBox(bool $verbose): string
83+
public function getMessageBox(
84+
UIFactory $ui_factory,
85+
bool $verbose
86+
): MessageBox {
87+
return $ui_factory->messageBox()->info(
88+
$verbose
89+
? $this->getMessage($verbose)
90+
: "<div class='ilTstWorkingFormBlock_WorkingTime'>{$this->getMessage($verbose)}</div>"
91+
);
92+
}
93+
94+
public function getMessage(bool $verbose): string
9195
{
92-
$message_text = $verbose
93-
? $this->getUserProcessingTimeString() . ' <span id="timeleft">' . $this->getUserRemainingTimeString() . '</span>'
94-
: '<div class="ilTstWorkingFormBlock_WorkingTime"><span id="timeleft" class="ilTstWorkingFormInfo_ProcessTimeLeft">' . $this->getUserRemainingTimeString() . '</span></div>';
95-
return $this->ui_renderer->render($this->ui_factory->messageBox()->info($message_text));
96+
return $verbose
97+
? "{$this->getUserProcessingTimeString()} <span id='timeleft'>{$this->getUserRemainingTimeString()}</span>"
98+
: "<span id='timeleft' class='ilTstWorkingFormInfo_ProcessTimeLeft'>{$this->getUserRemainingTimeString()}</span>";
9699
}
97100

98101
private function getUserProcessingTimeMinutesAndSeconds(): array
@@ -105,6 +108,10 @@ private function getUserProcessingTimeMinutesAndSeconds(): array
105108

106109
private function getUserProcessingTimeString(): string
107110
{
111+
if ($this->starting_time === null) {
112+
return '';
113+
}
114+
108115
[$processing_time_minutes, $processing_time_seconds] = $this->getUserProcessingTimeMinutesAndSeconds();
109116

110117
$str_processing_time = '';
@@ -121,14 +128,16 @@ private function getUserProcessingTimeString(): string
121128

122129
return sprintf(
123130
$this->lng->txt('tst_time_already_spent'),
124-
ilDatePresentation::formatDate(new ilDateTime(getdate($this->starting_time), IL_CAL_FKT_GETDATE)),
131+
\ilDatePresentation::formatDate(new \ilDateTime(getdate($this->starting_time), IL_CAL_FKT_GETDATE)),
125132
$str_processing_time
126133
);
127134
}
128135

129136
private function getUserRemainingTimeString(): string
130137
{
131-
$time_left = $this->starting_time + $this->processing_time - time();
138+
$time_left = $this->starting_time === null
139+
? $this->processing_time
140+
: $this->starting_time + $this->processing_time - time();
132141
$time_left_minutes = floor($time_left / 60);
133142
$time_left_seconds = $time_left - $time_left_minutes * 60;
134143
$str_time_left = '';

components/ILIAS/Test/src/Presentation/class.TestScreenGUI.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,16 @@ private function handleRenderMessageBox(array $elements): array
174174
$message_box_message_elements[] = $this->lng->txt('tst_launcher_status_message_password');
175175
}
176176

177-
if ($test_behaviour_settings->getProcessingTimeEnabled() && !$this->isUserOutOfProcessingTime()) {
178-
$message_box_message_elements[] = sprintf(
179-
$this->lng->txt('tst_time_limit_message'),
180-
$test_behaviour_settings->getProcessingTimeAsMinutes()
181-
);
177+
if ($test_behaviour_settings->getProcessingTimeEnabled()
178+
&& !$this->isUserOutOfProcessingTime()
179+
&& $this->hasAvailablePasses()) {
180+
$active_id = $this->test_session->getActiveId();
181+
$starting_time = $this->object->getStartingTimeOfUser($active_id);
182+
$message_box_message_elements[] = (new WorkingTime(
183+
$this->lng,
184+
$starting_time === false ? null : $starting_time,
185+
$this->object->getProcessingTimeInSeconds($active_id)
186+
))->getMessage(false);
182187
}
183188

184189
$nr_of_tries = $this->object->getNrOfTries();

0 commit comments

Comments
 (0)