ILIAS  release_8 Revision v8.24
class.ilScheduleInputGUI.php
Go to the documentation of this file.
1<?php
2
25{
27 protected array $value = [];
28 protected string $validationFailureMessage;
29
30 public function __construct(
31 string $a_title = "",
32 string $a_postvar = ""
33 ) {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->tpl = $DIC["tpl"];
38 parent::__construct($a_title, $a_postvar);
39 }
40
41 public function setValue(array $a_value): void
42 {
43 $this->value = $a_value;
44 }
45
46 public function getValue(): array
47 {
48 return $this->value;
49 }
50
51 public function setValidationFailureMessage(string $a_msg): void
52 {
53 $this->validationFailureMessage = $a_msg;
54 }
55
56 public function getValidationFailureMessage(): string
57 {
59 }
60
66 public function setValueByArray(array $a_values): void
67 {
68 $this->setValue($this->getPostData($this->getPostVar(), false));
69 }
70
71 public function checkInput(): bool
72 {
74
75 $data = $this->getPostData($this->getPostVar(), false);
76 if (count($data)) {
77 // slots may not overlap
78 foreach ($data as $slot => $days) {
79 if (!$days) {
80 $this->setAlert($lng->txt("msg_input_does_not_match_regexp"));
81 return false;
82 }
83
84 $parts = explode("-", $slot);
85 $from = str_replace(":", "", $parts[0]);
86 $to = str_replace(":", "", $parts[1]);
87 if ($from >= $to) {
88 $this->setAlert($lng->txt("msg_input_does_not_match_regexp"));
89 return false;
90 }
91
92 foreach ($data as $rslot => $rdays) {
93 if ($slot != $rslot && $rdays && array_intersect($days, $rdays)) {
94 $rparts = explode("-", $rslot);
95 $rfrom = str_replace(":", "", $rparts[0]);
96 $rto = str_replace(":", "", $rparts[1]);
97
98 if (($rfrom > $from && $rfrom < $to) ||
99 ($rto > $from && $rto < $to) ||
100 ($rfrom < $from && $rto > $to)) {
101 $this->setAlert($lng->txt("msg_input_does_not_match_regexp"));
102 return false;
103 }
104 }
105 }
106 }
107
108 return true;
109 }
110
111 if ($this->getRequired()) {
112 $this->setAlert($lng->txt("msg_input_is_required"));
113 return false;
114 }
115
116 return true;
117 }
118
119 public function getInput(): array
120 {
121 return $this->getPostData($this->getPostVar());
122 }
123
124 public function getPostData(
125 string $a_post_var,
126 $a_remove_invalid = true
127 ): array {
128 $res = array();
129 for ($loop = 0; $loop < 240; $loop++) {
130 $days = $this->strArray($a_post_var . "_days~" . $loop);
131 $from = self::parseTime(
132 $this->str($a_post_var . "_from_hh~" . $loop),
133 $this->str($a_post_var . "_from_mm~" . $loop)
134 );
135 $to = self::parseTime(
136 $this->str($a_post_var . "_to_hh~" . $loop),
137 $this->str($a_post_var . "_to_mm~" . $loop)
138 );
139
140 // only if any part was edited (js based gui)
141 if ($days || $from !== "00:00" || $to !== "00:00") {
142 $slot = $from . "-" . $to;
143 if ($days) {
144 if (isset($res[$slot])) {
145 $res[$slot] = array_unique(array_merge($res[$slot], $days));
146 } else {
147 $res[$slot] = $days;
148 }
149 } else {
150 $res[$slot] = array();
151 }
152
153 if ($a_remove_invalid && !($days && $from && $to && $from !== $to)) {
154 unset($res[$slot]);
155 }
156 }
157 }
158 return $res;
159 }
160
161 protected function render(
162 string $a_mode = ""
163 ): string {
164 $lng = $this->lng;
165
166 $tpl = new ilTemplate("tpl.schedule_input.html", true, true, "Modules/BookingManager");
167
168 $lng->loadLanguageModule("dateplaner");
169
170 $def = $this->getValue();
171 if (!$def) {
172 $def = array(null => null);
173 }
174
175 $days = array("Mo", "Tu", "We", "Th", "Fr", "Sa", "Su");
176 $row = 0;
177 foreach ($def as $slot => $days_select) {
178 $tpl->setCurrentBlock("days");
179 foreach ($days as $day) {
180 $day_value = strtolower($day);
181
182 $tpl->setVariable("ROW", $row);
183 $tpl->setVariable("ID", $this->getFieldId());
184 $tpl->setVariable("POST_VAR", $this->getPostVar());
185 $tpl->setVariable("DAY", $day_value);
186 $tpl->setVariable("TXT_DAY", $lng->txt($day . "_short"));
187
188 if ($days_select && in_array($day_value, $days_select, true)) {
189 $tpl->setVariable("DAY_STATUS", " checked=\"checked\"");
190 }
191
192 $tpl->parseCurrentBlock();
193 }
194
195 $tpl->setCurrentBlock("row");
196 $tpl->setVariable("ROW", $row);
197 $tpl->setVariable("ID", $this->getFieldId());
198 $tpl->setVariable("POST_VAR", $this->getPostVar());
199 $tpl->setVariable("TXT_FROM", $lng->txt("cal_from"));
200 $tpl->setVariable("TXT_TO", $lng->txt("cal_until"));
201 $tpl->setVariable("IMG_MULTI_ADD", ilGlyphGUI::get(ilGlyphGUI::ADD));
202 $tpl->setVariable("IMG_MULTI_REMOVE", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
203 $tpl->setVariable("TXT_MULTI_ADD", $lng->txt("add"));
204 $tpl->setVariable("TXT_MULTI_REMOVE", $lng->txt("remove"));
205
206 if ($slot) {
207 $parts = explode("-", $slot);
208 $from = explode(":", $parts[0]);
209 $to = explode(":", $parts[1]);
210
211 $tpl->setVariable("FROM_HH_VALUE", $from[0]);
212 $tpl->setVariable("FROM_MM_VALUE", $from[1]);
213 $tpl->setVariable("TO_HH_VALUE", $to[0]);
214 $tpl->setVariable("TO_MM_VALUE", $to[1]);
215 }
216
217 // manage hidden buttons
218 if ($row > 0) {
219 // inline needed because of JS
220 $tpl->setVariable("ADD_STYLE", " style=\"display:none\"");
221 // $tpl->setVariable("ADD_CLASS", "ilNoDisplay");
222 } else {
223 // inline needed because of JS
224 $tpl->setVariable("RMV_STYLE", " style=\"display:none\"");
225 // $tpl->setVariable("RMV_CLASS", "ilNoDisplay");
226 }
227
228 $tpl->parseCurrentBlock();
229
230 $row++;
231 }
232
233 return $tpl->get();
234 }
235
236 public function insert(ilTemplate $a_tpl): void
237 {
239
240 $tpl->addJavascript("Modules/BookingManager/js/ScheduleInput.js");
241
242 $html = $this->render();
243
244 $a_tpl->setCurrentBlock("prop_generic");
245 $a_tpl->setVariable("PROP_GENERIC", $html);
246 $a_tpl->parseCurrentBlock();
247 }
248
252 protected static function parseTime(
253 string $a_hours,
254 string $a_minutes
255 ): string {
256 $hours = (int) $a_hours;
257 $min = (int) $a_minutes;
258 if ($hours > 23 || $min > 59) {
259 return false;
260 }
261 return str_pad($hours, 2, "0", STR_PAD_LEFT) . ":" .
262 str_pad($min, 2, "0", STR_PAD_LEFT);
263 }
264}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This class represents a property in a property form.
static get(string $a_glyph, string $a_text="")
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
checkInput()
Check input, strip slashes etc.
setValueByArray(array $a_values)
Set value by array.
setValidationFailureMessage(string $a_msg)
__construct(string $a_title="", string $a_postvar="")
static parseTime(string $a_hours, string $a_minutes)
Parse/normalize incoming time values.
getPostData(string $a_post_var, $a_remove_invalid=true)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:47
$lng