ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
WorkingTime.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Factory as UIFactory;
25
27{
28 public function __construct(
29 private readonly \ilLanguage $lng,
30 private readonly ?int $starting_time,
31 private readonly int $processing_time
32 ) {
33 }
34
36 \ilObjTest $object,
37 array $date,
38 string $check_url,
39 string $redirect_url
40 ): \ilTemplate {
41 [$processing_time_minutes, $processing_time_seconds] = $this->getUserProcessingTimeMinutesAndSeconds();
42 $template = new \ilTemplate('tpl.workingtime.js', true, true, 'components/ILIAS/Test');
43 $template->setVariable('STRING_MINUTE', $this->lng->txt('minute'));
44 $template->setVariable('STRING_MINUTES', $this->lng->txt('minutes'));
45 $template->setVariable('STRING_SECOND', $this->lng->txt('second'));
46 $template->setVariable('STRING_SECONDS', $this->lng->txt('seconds'));
47 $template->setVariable('STRING_TIMELEFT', $this->lng->txt('tst_time_already_spent_left'));
48 $template->setVariable('AND', strtolower($this->lng->txt('and')));
49 $template->setVariable('YEAR', $date['year']);
50 $template->setVariable('MONTH', $date['mon'] - 1);
51 $template->setVariable('DAY', $date['mday']);
52 $template->setVariable('HOUR', $date['hours']);
53 $template->setVariable('MINUTE', $date['minutes']);
54 $template->setVariable('SECOND', $date['seconds']);
55 if ($object->isEndingTimeEnabled()) {
56 $date_time = new \ilDateTime($object->getEndingTime(), IL_CAL_UNIX);
57 preg_match('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $date_time->get(IL_CAL_TIMESTAMP), $matches);
58 if ($matches !== []) {
59 $template->setVariable('ENDYEAR', $matches[1]);
60 $template->setVariable('ENDMONTH', $matches[2] - 1);
61 $template->setVariable('ENDDAY', $matches[3]);
62 $template->setVariable('ENDHOUR', $matches[4]);
63 $template->setVariable('ENDMINUTE', $matches[5]);
64 $template->setVariable('ENDSECOND', $matches[6]);
65 }
66 }
67
68 $datenow = getdate();
69 $template->setVariable('YEARNOW', $datenow['year']);
70 $template->setVariable('MONTHNOW', $datenow['mon'] - 1);
71 $template->setVariable('DAYNOW', $datenow['mday']);
72 $template->setVariable('HOURNOW', $datenow['hours']);
73 $template->setVariable('MINUTENOW', $datenow['minutes']);
74 $template->setVariable('SECONDNOW', $datenow['seconds']);
75 $template->setVariable('PTIME_M', $processing_time_minutes);
76 $template->setVariable('PTIME_S', $processing_time_seconds);
77 $template->setVariable('REDIRECT_URL', $redirect_url);
78 $template->setVariable('CHECK_URL', $check_url);
79
80 return $template;
81 }
82
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
95 {
96 return $verbose
97 ? "{$this->getUserProcessingTimeString()} <span id='timeleft'>{$this->getUserRemainingTimeString()}</span>"
98 : "<span id='timeleft' class='ilTstWorkingFormInfo_ProcessTimeLeft'>{$this->getUserRemainingTimeString()}</span>";
99 }
100
102 {
103 $processing_time_minutes = floor($this->processing_time / 60);
104 $processing_time_seconds = $this->processing_time - $processing_time_minutes * 60;
105
106 return [$processing_time_minutes, $processing_time_seconds];
107 }
108
109 private function getUserProcessingTimeString(): string
110 {
111 if ($this->starting_time === null) {
112 return '';
113 }
114
115 [$processing_time_minutes, $processing_time_seconds] = $this->getUserProcessingTimeMinutesAndSeconds();
116
117 $str_processing_time = '';
118 if ($processing_time_minutes > 0) {
119 $str_processing_time = "$processing_time_minutes {$this->lng->txt($processing_time_minutes === 1 ? 'minute' : 'minutes')}";
120 }
121
122 if ($processing_time_seconds > 0) {
123 if ($str_processing_time !== '') {
124 $str_processing_time .= " {$this->lng->txt('and')} ";
125 }
126 $str_processing_time .= "$processing_time_seconds {$this->lng->txt($processing_time_seconds === 1 ? 'second' : 'seconds')}";
127 }
128
129 return sprintf(
130 $this->lng->txt('tst_time_already_spent'),
131 \ilDatePresentation::formatDate(new \ilDateTime(getdate($this->starting_time), IL_CAL_FKT_GETDATE)),
132 $str_processing_time
133 );
134 }
135
136 private function getUserRemainingTimeString(): string
137 {
138 $time_left = $this->starting_time === null
139 ? $this->processing_time
140 : $this->starting_time + $this->processing_time - time();
141 $time_left_minutes = floor($time_left / 60);
142 $time_left_seconds = $time_left - $time_left_minutes * 60;
143 $str_time_left = '';
144 if ($time_left_minutes > 0) {
145 $str_time_left = "$time_left_minutes {$this->lng->txt($time_left_minutes === 1 ? 'minute' : 'minutes')}";
146 }
147 if ($time_left < 300 && $time_left_seconds > 0) {
148 if ($str_time_left !== '') {
149 $str_time_left .= " {$this->lng->txt('and')} ";
150 }
151 $str_time_left .= "$time_left_seconds {$this->lng->txt($time_left_seconds === 1 ? 'second' : 'seconds')}";
152 }
153
154 return sprintf($this->lng->txt('tst_time_already_spent_left'), $str_time_left);
155 }
156}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(private readonly \ilLanguage $lng, private readonly ?int $starting_time, private readonly int $processing_time)
Definition: WorkingTime.php:28
getMessageBox(UIFactory $ui_factory, bool $verbose)
Definition: WorkingTime.php:83
prepareWorkingTimeJsTemplate(\ilObjTest $object, array $date, string $check_url, string $redirect_url)
Definition: WorkingTime.php:35
const IL_CAL_FKT_GETDATE
const IL_CAL_TIMESTAMP
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
language handling
special template class to simplify handling of ITX/PEAR
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:26