ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Test\Presentation\WorkingTime Class Reference
+ Collaboration diagram for ILIAS\Test\Presentation\WorkingTime:

Public Member Functions

 __construct (private readonly \ilLanguage $lng, private readonly ?int $starting_time, private readonly int $processing_time)
 
 prepareWorkingTimeJsTemplate (\ilObjTest $object, array $date, string $check_url, string $redirect_url)
 
 getMessageBox (UIFactory $ui_factory, bool $verbose)
 
 getMessage (bool $verbose)
 

Private Member Functions

 getUserProcessingTimeMinutesAndSeconds ()
 
 getUserProcessingTimeString ()
 
 getUserRemainingTimeString ()
 

Detailed Description

Definition at line 26 of file WorkingTime.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Test\Presentation\WorkingTime::__construct ( private readonly \ilLanguage  $lng,
private readonly ?int  $starting_time,
private readonly int  $processing_time 
)

Definition at line 28 of file WorkingTime.php.

32 {
33 }

Member Function Documentation

◆ getMessage()

ILIAS\Test\Presentation\WorkingTime::getMessage ( bool  $verbose)

Definition at line 94 of file WorkingTime.php.

94 : 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 }

◆ getMessageBox()

ILIAS\Test\Presentation\WorkingTime::getMessageBox ( UIFactory  $ui_factory,
bool  $verbose 
)

Definition at line 83 of file WorkingTime.php.

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 }

◆ getUserProcessingTimeMinutesAndSeconds()

ILIAS\Test\Presentation\WorkingTime::getUserProcessingTimeMinutesAndSeconds ( )
private

Definition at line 101 of file WorkingTime.php.

101 : array
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 }

◆ getUserProcessingTimeString()

ILIAS\Test\Presentation\WorkingTime::getUserProcessingTimeString ( )
private

Definition at line 109 of file WorkingTime.php.

109 : 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 }
const IL_CAL_FKT_GETDATE
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

References ilDatePresentation\formatDate(), IL_CAL_FKT_GETDATE, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getUserRemainingTimeString()

ILIAS\Test\Presentation\WorkingTime::getUserRemainingTimeString ( )
private

Definition at line 136 of file WorkingTime.php.

136 : 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 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ prepareWorkingTimeJsTemplate()

ILIAS\Test\Presentation\WorkingTime::prepareWorkingTimeJsTemplate ( \ilObjTest  $object,
array  $date,
string  $check_url,
string  $redirect_url 
)

Definition at line 35 of file WorkingTime.php.

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 }
const IL_CAL_TIMESTAMP
const IL_CAL_UNIX
special template class to simplify handling of ITX/PEAR

The documentation for this class was generated from the following file: