19 declare(strict_types=1);
35 private readonly
Factory $ui_factory,
36 private readonly
Renderer $ui_renderer,
37 private readonly
int $starting_time,
38 private readonly
int $processing_time
49 $template =
new ilTemplate(
'tpl.workingtime.js',
true,
true,
'components/ILIAS/Test');
50 $template->setVariable(
'STRING_MINUTE', $this->
lng->txt(
'minute'));
51 $template->setVariable(
'STRING_MINUTES', $this->
lng->txt(
'minutes'));
52 $template->setVariable(
'STRING_SECOND', $this->
lng->txt(
'second'));
53 $template->setVariable(
'STRING_SECONDS', $this->
lng->txt(
'seconds'));
54 $template->setVariable(
'STRING_TIMELEFT', $this->
lng->txt(
'tst_time_already_spent_left'));
55 $template->setVariable(
'AND', strtolower($this->
lng->txt(
'and')));
56 $template->setVariable(
'YEAR', $date[
'year']);
57 $template->setVariable(
'MONTH', $date[
'mon'] - 1);
58 $template->setVariable(
'DAY', $date[
'mday']);
59 $template->setVariable(
'HOUR', $date[
'hours']);
60 $template->setVariable(
'MINUTE', $date[
'minutes']);
61 $template->setVariable(
'SECOND', $date[
'seconds']);
64 preg_match(
'/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $date_time->get(
IL_CAL_TIMESTAMP), $matches);
65 if ($matches !== []) {
66 $template->setVariable(
'ENDYEAR', $matches[1]);
67 $template->setVariable(
'ENDMONTH', $matches[2] - 1);
68 $template->setVariable(
'ENDDAY', $matches[3]);
69 $template->setVariable(
'ENDHOUR', $matches[4]);
70 $template->setVariable(
'ENDMINUTE', $matches[5]);
71 $template->setVariable(
'ENDSECOND', $matches[6]);
76 $template->setVariable(
'YEARNOW', $datenow[
'year']);
77 $template->setVariable(
'MONTHNOW', $datenow[
'mon'] - 1);
78 $template->setVariable(
'DAYNOW', $datenow[
'mday']);
79 $template->setVariable(
'HOURNOW', $datenow[
'hours']);
80 $template->setVariable(
'MINUTENOW', $datenow[
'minutes']);
81 $template->setVariable(
'SECONDNOW', $datenow[
'seconds']);
82 $template->setVariable(
'PTIME_M', $processing_time_minutes);
83 $template->setVariable(
'PTIME_S', $processing_time_seconds);
84 $template->setVariable(
'REDIRECT_URL', $redirect_url);
85 $template->setVariable(
'CHECK_URL', $check_url);
92 $message_text = $verbose
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));
100 $processing_time_minutes = floor($this->processing_time / 60);
101 $processing_time_seconds = $this->processing_time - $processing_time_minutes * 60;
103 return [$processing_time_minutes, $processing_time_seconds];
110 $str_processing_time =
'';
111 if ($processing_time_minutes > 0) {
112 $str_processing_time =
"$processing_time_minutes {$this->lng->txt($processing_time_minutes === 1 ? 'minute' : 'minutes')}";
115 if ($processing_time_seconds > 0) {
116 if ($str_processing_time !==
'') {
117 $str_processing_time .=
" {$this->lng->txt('and')} ";
119 $str_processing_time .=
"$processing_time_seconds {$this->lng->txt($processing_time_seconds === 1 ? 'second' : 'seconds')}";
123 $this->
lng->txt(
'tst_time_already_spent'),
131 $time_left = $this->starting_time + $this->processing_time - time();
132 $time_left_minutes = floor($time_left / 60);
133 $time_left_seconds = $time_left - $time_left_minutes * 60;
135 if ($time_left_minutes > 0) {
136 $str_time_left =
"$time_left_minutes {$this->lng->txt($time_left_minutes === 1 ? 'minute' : 'minutes')}";
138 if ($time_left < 300 && $time_left_seconds > 0) {
139 if ($str_time_left !==
'') {
140 $str_time_left .=
" {$this->lng->txt('and')} ";
142 $str_time_left .=
"$time_left_seconds {$this->lng->txt($time_left_seconds === 1 ? 'second' : 'seconds')}";
145 return sprintf($this->
lng->txt(
'tst_time_already_spent_left'), $str_time_left);
getUserRemainingTimeString()
prepareWorkingTimeJsTemplate(ilObjTest $object, array $date, string $check_url, string $redirect_url)
getUserProcessingTimeString()
getMessageBox(bool $verbose)
__construct(private readonly ilLanguage $lng, private readonly Factory $ui_factory, private readonly Renderer $ui_renderer, private readonly int $starting_time, private readonly int $processing_time)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
getUserProcessingTimeMinutesAndSeconds()