ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilScheduleInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $tpl;
17
18 protected $value;
19
26 public function __construct($a_title = "", $a_postvar = "")
27 {
28 global $DIC;
29
30 $this->lng = $DIC->language();
31 $this->tpl = $DIC["tpl"];
32 parent::__construct($a_title, $a_postvar);
33 }
34
40 public function setValue($a_value)
41 {
42 $this->value = $a_value;
43 }
44
50 public function getValue()
51 {
52 return $this->value;
53 }
54
60 public function setValidationFailureMessage($a_msg)
61 {
62 $this->validationFailureMessage = $a_msg;
63 }
64
66 {
67 return $this->validationFailureMessage;
68 }
69
75 public function setValueByArray($a_values)
76 {
77 $this->setValue(self::getPostData($this->getPostVar(), false));
78 }
79
85 public function checkInput()
86 {
88
89 $data = self::getPostData($this->getPostVar(), false);
90 if (sizeof($data)) {
91 // slots may not overlap
92 foreach ($data as $slot => $days) {
93 if (!$days) {
94 $this->setAlert($lng->txt("msg_input_does_not_match_regexp"));
95 return false;
96 }
97
98 $parts = explode("-", $slot);
99 $from = str_replace(":", "", $parts[0]);
100 $to = str_replace(":", "", $parts[1]);
101 if ($from >= $to) {
102 $this->setAlert($lng->txt("msg_input_does_not_match_regexp"));
103 return false;
104 }
105
106 foreach ($data as $rslot => $rdays) {
107 if ($slot != $rslot && $rdays && array_intersect($days, $rdays)) {
108 $rparts = explode("-", $rslot);
109 $rfrom = str_replace(":", "", $rparts[0]);
110 $rto = str_replace(":", "", $rparts[1]);
111
112 if (($rfrom > $from && $rfrom < $to) ||
113 ($rto > $from && $rto < $to) ||
114 ($rfrom < $from && $rto > $to)) {
115 $this->setAlert($lng->txt("msg_input_does_not_match_regexp"));
116 return false;
117 }
118 }
119 }
120 }
121
122 return true;
123 }
124
125 if ($this->getRequired()) {
126 $this->setAlert($lng->txt("msg_input_is_required"));
127 return false;
128 }
129
130 return true;
131 }
132
133 public static function getPostData($a_post_var, $a_remove_invalid = true)
134 {
135 $res = array();
136 for ($loop = 0; $loop < 240; $loop++) {
137 $days = $_POST[$a_post_var . "_days~" . $loop];
138 $from = self::parseTime(
139 $_POST[$a_post_var . "_from_hh~" . $loop],
140 $_POST[$a_post_var . "_from_mm~" . $loop]
141 );
142 $to = self::parseTime(
143 $_POST[$a_post_var . "_to_hh~" . $loop],
144 $_POST[$a_post_var . "_to_mm~" . $loop]
145 );
146
147 // only if any part was edited (js based gui)
148 if ($days || $from != "00:00" || $to != "00:00") {
149 $slot = $from . "-" . $to;
150 if ($days) {
151 if (isset($res[$slot])) {
152 $res[$slot] = array_unique(array_merge($res[$slot], $days));
153 } else {
154 $res[$slot] = $days;
155 }
156 } else {
157 $res[$slot] = array();
158 }
159
160 if ($a_remove_invalid && !($days && $from && $to && $from != $to)) {
161 unset($res[$slot]);
162 }
163 }
164 }
165
166 return $res;
167 }
168
172 protected function render($a_mode = "")
173 {
175
176 $tpl = new ilTemplate("tpl.schedule_input.html", true, true, "Modules/BookingManager");
177
178 $lng->loadLanguageModule("dateplaner");
179
180 $def = $this->getValue();
181 if (!$def) {
182 $def = array(null => null);
183 }
184
185 $days = array("Mo", "Tu", "We", "Th", "Fr", "Sa", "Su");
186 $row = 0;
187 foreach ($def as $slot => $days_select) {
188 $tpl->setCurrentBlock("days");
189 foreach ($days as $day) {
190 $day_value = strtolower($day);
191
192 $tpl->setVariable("ROW", $row);
193 $tpl->setVariable("ID", $this->getFieldId());
194 $tpl->setVariable("POST_VAR", $this->getPostVar());
195 $tpl->setVariable("DAY", $day_value);
196 $tpl->setVariable("TXT_DAY", $lng->txt($day . "_short"));
197
198 if ($days_select && in_array($day_value, $days_select)) {
199 $tpl->setVariable("DAY_STATUS", " checked=\"checked\"");
200 }
201
202 $tpl->parseCurrentBlock();
203 }
204
205 $tpl->setCurrentBlock("row");
206 $tpl->setVariable("ROW", $row);
207 $tpl->setVariable("ID", $this->getFieldId());
208 $tpl->setVariable("POST_VAR", $this->getPostVar());
209 $tpl->setVariable("TXT_FROM", $lng->txt("cal_from"));
210 $tpl->setVariable("TXT_TO", $lng->txt("cal_until"));
211 $tpl->setVariable("IMG_MULTI_ADD", ilGlyphGUI::get(ilGlyphGUI::ADD));
212 $tpl->setVariable("IMG_MULTI_REMOVE", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
213 $tpl->setVariable("TXT_MULTI_ADD", $lng->txt("add"));
214 $tpl->setVariable("TXT_MULTI_REMOVE", $lng->txt("remove"));
215
216 if ($slot) {
217 $parts = explode("-", $slot);
218 $from = explode(":", $parts[0]);
219 $to = explode(":", $parts[1]);
220
221 $tpl->setVariable("FROM_HH_VALUE", $from[0]);
222 $tpl->setVariable("FROM_MM_VALUE", $from[1]);
223 $tpl->setVariable("TO_HH_VALUE", $to[0]);
224 $tpl->setVariable("TO_MM_VALUE", $to[1]);
225 }
226
227 // manage hidden buttons
228 if ($row > 0) {
229 // inline needed because of JS
230 $tpl->setVariable("ADD_STYLE", " style=\"display:none\"");
231 // $tpl->setVariable("ADD_CLASS", "ilNoDisplay");
232 } else {
233 // inline needed because of JS
234 $tpl->setVariable("RMV_STYLE", " style=\"display:none\"");
235 // $tpl->setVariable("RMV_CLASS", "ilNoDisplay");
236 }
237
238 $tpl->parseCurrentBlock();
239
240 $row++;
241 }
242
243 return $tpl->get();
244 }
245
251 public function insert(&$a_tpl)
252 {
254
255 $tpl->addJavascript("Modules/BookingManager/js/ScheduleInput.js");
256
257 $html = $this->render();
258
259 $a_tpl->setCurrentBlock("prop_generic");
260 $a_tpl->setVariable("PROP_GENERIC", $html);
261 $a_tpl->parseCurrentBlock();
262 }
263
269 protected static function parseTime($a_hours, $a_minutes)
270 {
271 $hours = (int) $a_hours;
272 $min = (int) $a_minutes;
273 if ($hours > 23 || $min > 59) {
274 return false;
275 }
276 return str_pad($hours, 2, "0", STR_PAD_LEFT) . ":" .
277 str_pad($min, 2, "0", STR_PAD_LEFT);
278 }
279}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a text property in a property form.
static parseTime($a_hours, $a_minutes)
Parse/normalize incoming time values.
setValueByArray($a_values)
Set value by array.
insert(&$a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
render($a_mode="")
Render item.
setValue($a_value)
Set Value.
__construct($a_title="", $a_postvar="")
Constructor.
static getPostData($a_post_var, $a_remove_invalid=true)
setValidationFailureMessage($a_msg)
Set message string for validation failure.
special template class to simplify handling of ITX/PEAR
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
foreach($_POST as $key=> $value) $res
$data
Definition: storeScorm.php:23