2020
2121namespace 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
3126class 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 = '' ;
0 commit comments