ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDurationInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
36  protected $lng;
37 
38  protected $months = 0;
39  protected $days = 0;
40  protected $hours = 0;
41  protected $minutes = 0;
42  protected $seconds = 0;
43  protected $showmonths = false;
44  protected $showdays = false;
45  protected $showhours = true;
46  protected $showminutes = true;
47  protected $showseconds = false;
48 
55  public function __construct($a_title = "", $a_postvar = "")
56  {
57  global $DIC;
58 
59  $this->lng = $DIC->language();
60  parent::__construct($a_title, $a_postvar);
61  $this->setType("duration");
62  }
63 
69  public function setDays($a_days)
70  {
71  $this->days = $a_days;
72  }
73 
79  public function getDays()
80  {
81  return $this->days;
82  }
83 
89  public function setHours($a_hours)
90  {
91  $this->hours = $a_hours;
92  }
93 
99  public function getHours()
100  {
101  return $this->hours;
102  }
103 
109  public function setMinutes($a_minutes)
110  {
111  $this->minutes = $a_minutes;
112  }
113 
119  public function getMinutes()
120  {
121  return $this->minutes;
122  }
123 
129  public function setSeconds($a_seconds)
130  {
131  $this->seconds = $a_seconds;
132  }
133 
141  public function setMonths($a_months)
142  {
143  $this->months = $a_months;
144  }
145 
152  public function getMonths()
153  {
154  return $this->months;
155  }
156 
162  public function getSeconds()
163  {
164  return $this->seconds;
165  }
166 
173  public function setShowMonths($a_show_months)
174  {
175  $this->showmonths = $a_show_months;
176  }
177 
183  public function getShowMonths()
184  {
185  return $this->showmonths;
186  }
187 
193  public function setShowDays($a_showdays)
194  {
195  $this->showdays = $a_showdays;
196  }
197 
203  public function getShowDays()
204  {
205  return $this->showdays;
206  }
207 
213  public function setShowHours($a_showhours)
214  {
215  $this->showhours = $a_showhours;
216  }
217 
223  public function getShowHours()
224  {
225  return $this->showhours;
226  }
227 
233  public function setShowMinutes($a_showminutes)
234  {
235  $this->showminutes = $a_showminutes;
236  }
237 
243  public function getShowMinutes()
244  {
245  return $this->showminutes;
246  }
247 
253  public function setShowSeconds($a_showseconds)
254  {
255  $this->showseconds = $a_showseconds;
256  }
257 
263  public function getShowSeconds()
264  {
265  return $this->showseconds;
266  }
267 
273  public function setValueByArray($a_values)
274  {
275  $this->setMonths($a_values[$this->getPostVar()]["MM"]);
276  $this->setDays($a_values[$this->getPostVar()]["dd"]);
277  $this->setHours($a_values[$this->getPostVar()]["hh"]);
278  $this->setMinutes($a_values[$this->getPostVar()]["mm"]);
279  $this->setSeconds($a_values[$this->getPostVar()]["ss"]);
280  }
281 
287  public function checkInput()
288  {
289  $lng = $this->lng;
290 
291  $_POST[$this->getPostVar()]["MM"] =
292  ilUtil::stripSlashes($_POST[$this->getPostVar()]["MM"]);
293  $_POST[$this->getPostVar()]["dd"] =
294  ilUtil::stripSlashes($_POST[$this->getPostVar()]["dd"]);
295  $_POST[$this->getPostVar()]["hh"] =
296  ilUtil::stripSlashes($_POST[$this->getPostVar()]["hh"]);
297  $_POST[$this->getPostVar()]["mm"] =
298  ilUtil::stripSlashes($_POST[$this->getPostVar()]["mm"]);
299  $_POST[$this->getPostVar()]["ss"] =
300  ilUtil::stripSlashes($_POST[$this->getPostVar()]["ss"]);
301 
302  return true;
303  }
304 
310  public function insert($a_tpl)
311  {
312  $html = $this->render();
313 
314  $a_tpl->setCurrentBlock("prop_generic");
315  $a_tpl->setVariable("PROP_GENERIC", $html);
316  $a_tpl->parseCurrentBlock();
317  }
318 
323  public function render()
324  {
325  $lng = $this->lng;
326 
327  $tpl = new ilTemplate("tpl.prop_duration.html", true, true, "Services/Form");
328 
329  if ($this->getShowMonths()) {
330  $tpl->setCurrentBlock("dur_months");
331  $tpl->setVariable("TXT_MONTHS", $lng->txt("form_months"));
332  $val = array();
333  for ($i=0; $i<=36; $i++) {
334  $val[$i] = $i;
335  }
336  $tpl->setVariable(
337  "SELECT_MONTHS",
339  $this->getMonths(),
340  $this->getPostVar() . "[MM]",
341  $val,
342  false,
343  true,
344  0,
345  '',
346  '',
347  $this->getDisabled()
348  )
349  );
350  $tpl->parseCurrentBlock();
351  }
352  if ($this->getShowDays()) {
353  $tpl->setCurrentBlock("dur_days");
354  $tpl->setVariable("TXT_DAYS", $lng->txt("form_days"));
355  $val = array();
356  for ($i=0; $i<=366; $i++) {
357  $val[$i] = $i;
358  }
359  $tpl->setVariable(
360  "SELECT_DAYS",
362  $this->getDays(),
363  $this->getPostVar() . "[dd]",
364  $val,
365  false,
366  true,
367  0,
368  '',
369  '',
370  $this->getDisabled()
371  )
372  );
373  $tpl->parseCurrentBlock();
374  }
375  if ($this->getShowHours()) {
376  $tpl->setCurrentBlock("dur_hours");
377  $tpl->setVariable("TXT_HOURS", $lng->txt("form_hours"));
378  $val = array();
379  for ($i=0; $i<=23; $i++) {
380  $val[$i] = $i;
381  }
382  $tpl->setVariable(
383  "SELECT_HOURS",
385  $this->getHours(),
386  $this->getPostVar() . "[hh]",
387  $val,
388  false,
389  true,
390  0,
391  '',
392  '',
393  $this->getDisabled()
394  )
395  );
396  $tpl->parseCurrentBlock();
397  }
398  if ($this->getShowMinutes()) {
399  $tpl->setCurrentBlock("dur_minutes");
400  $tpl->setVariable("TXT_MINUTES", $lng->txt("form_minutes"));
401  $val = array();
402  for ($i=0; $i<=59; $i++) {
403  $val[$i] = $i;
404  }
405  $tpl->setVariable(
406  "SELECT_MINUTES",
408  $this->getMinutes(),
409  $this->getPostVar() . "[mm]",
410  $val,
411  false,
412  true,
413  0,
414  '',
415  '',
416  $this->getDisabled()
417  )
418  );
419  $tpl->parseCurrentBlock();
420  }
421  if ($this->getShowSeconds()) {
422  $tpl->setCurrentBlock("dur_seconds");
423  $tpl->setVariable("TXT_SECONDS", $lng->txt("form_seconds"));
424  $val = array();
425  for ($i=0; $i<=59; $i++) {
426  $val[$i] = $i;
427  }
428  $tpl->setVariable(
429  "SELECT_SECONDS",
431  $this->getSeconds(),
432  $this->getPostVar() . "[ss]",
433  $val,
434  false,
435  true,
436  0,
437  '',
438  '',
439  $this->getDisabled()
440  )
441  );
442  $tpl->parseCurrentBlock();
443  }
444 
445  return $tpl->get();
446  }
447 
451  public function getTableFilterHTML()
452  {
453  $html = $this->render();
454  return $html;
455  }
456 
460  public function serializeData()
461  {
462  $data = array("months" => $this->getMonths(),
463  "days" => $this->getDays(),
464  "hours" => $this->getHours(),
465  "minutes" => $this->getMinutes(),
466  "seconds" => $this->getSeconds());
467 
468  return serialize($data);
469  }
470 
474  public function unserializeData($a_data)
475  {
476  $data = unserialize($a_data);
477 
478  $this->setMonths($data["months"]);
479  $this->setDays($data["days"]);
480  $this->setHours($data["hours"]);
481  $this->setMinutes($data["minutes"]);
482  $this->setSeconds($data["seconds"]);
483  }
484 
490  public function getValueInSeconds()
491  {
492  $value = 0;
493  if ($this->getShowMonths()) {
494  $value += $this->getMonths()*30*24*60*60;
495  }
496  if ($this->getShowDays()) {
497  $value += $this->getDays()*24*60*60;
498  }
499  if ($this->getShowHours()) {
500  $value += $this->getHours()*60*60;
501  }
502  if ($this->getShowMinutes()) {
503  $value += $this->getMinutes()*60;
504  }
505  if ($this->getShowSeconds()) {
506  $value += $this->getSeconds();
507  }
508  return $value;
509  }
510 }
getShowMonths()
Get show months.
This class represents a duration (typical hh:mm:ss) property in a property form.
getTableFilterHTML()
Get HTML for table filter.
getShowSeconds()
Get Show Seconds.
setValueByArray($a_values)
Set value by array.
setShowMonths($a_show_months)
Set show months.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
setDays($a_days)
Set Days.
getPostVar()
Get Post Variable.
setShowHours($a_showhours)
Set Show Hours.
setHours($a_hours)
Set Hours.
setShowMinutes($a_showminutes)
Set Show Minutes.
getShowHours()
Get Show Hours.
insert($a_tpl)
Insert property html.
setType($a_type)
Set Type.
checkInput()
Check input, strip slashes etc.
getShowMinutes()
Get Show Minutes.
hours($input)
Definition: memcachestat.php:7
unserializeData($a_data)
unserialize data
special template class to simplify handling of ITX/PEAR
getValueInSeconds()
Get combined value in seconds.
setShowDays($a_showdays)
Set Show Days.
__construct($a_title="", $a_postvar="")
Constructor.
setMinutes($a_minutes)
Set Minutes.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
setMonths($a_months)
set months
setShowSeconds($a_showseconds)
Set Show Seconds.
setSeconds($a_seconds)
Set Seconds.
render()
Insert property html.
static formSelect( $selected, $varname, $options, $multiple=false, $direct_text=false, $size="0", $style_class="", $attribs="", $disabled=false)
Builds a select form field with options and shows the selected option first.
This class represents a property in a property form.
$i
Definition: disco.tpl.php:19
$_POST["username"]
$html
Definition: example_001.php:87
sprintf('%.4f', $callTime) seconds