XOOPS  2.6.0
DateTime.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
12 namespace Xoops\Form;
13 
25 class DateTime extends ElementTray
26 {
36  public function __construct($caption, $name, $size = 2, $value = 0, $showtime = true)
37  {
38  parent::__construct($caption, '');
39  $value = intval($value);
40  $value = ($value > 0) ? $value : time();
41  $datetime = getdate($value);
42  $date = new DateSelect('', $name . '[date]', $size, $value);
43  $date->setAttribute('id', $name.'-date');
44  $this->addElement($date);
45 
46  if ($showtime) {
47  $timearray = array();
48  for ($i = 0; $i < 24; ++$i) {
49  for ($j = 0; $j < 60; $j = $j + 10) {
50  $key = ($i * 3600) + ($j * 60);
51  $timearray[$key] = ($j != 0) ? $i . ':' . $j : $i . ':0' . $j;
52  }
53  }
54  ksort($timearray);
55 
56  $timeselect =
57  new Select('', $name . '[time]', $datetime['hours'] * 3600 + 600 * ceil($datetime['minutes'] / 10));
58  $timeselect->setAttribute('id', $name.'-time');
59  $timeselect->addOptionArray($timearray);
60  $timeselect->setClass('span2');
61  $this->addElement($timeselect);
62  } else {
63  $this->addElement(new Hidden($name . '[time]', 0));
64  }
65  }
66 }
$i
Definition: dialog.php:68
addElement(Element $formElement, $required=false)
Definition: ElementTray.php:80
$j
Definition: help.php:169
__construct($caption, $name, $size=2, $value=0, $showtime=true)
Definition: DateTime.php:36