MartinFormDateTime::MartinFormDateTime()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 8
nop 5
dl 0
loc 19
rs 9.3222
c 0
b 0
f 0
1
<?php
2
/**
3
 * @method:日历类
4
 * @license   http://www.blags.org/
5
 * @created   :2010年05月25日 22时33分
6
 * @copyright 1997-2010 The Martin Group
7
 * @author    Martin <[email protected]>
8
 * */
9
if (!defined("XOOPS_ROOT_PATH")) {
10
    die("XOOPS root path not defined");
11
}
12
13
/**
14
 * @method: 日期
15
 * @license   http://www.blags.org/
16
 * @created   :2010年05月25日 22时33分
17
 * @copyright 1997-2010 The Martin Group
18
 * @author    Martin <[email protected]>
19
 * */
20
class MartinFormDateTime extends XoopsFormElementTray
21
{
22
    /**
23
     * MartinFormDateTime constructor.
24
     * @param      $caption
25
     * @param      $name
26
     * @param int  $size
27
     * @param int  $value
28
     * @param bool $is_time
29
     */
30
    public function MartinFormDateTime($caption, $name, $size = 15, $value = 0, $is_time = true)
31
    {
32
        $this->XoopsFormElementTray($caption, '&nbsp;');
33
        $value    = (int)($value);
34
        $value    = ($value > 0) ? $value : time();
35
        $datetime = getDate($value);
36
        $this->addElement(new XoopsFormTextDateSelect('', $name . '[date]', $size, $value));
37
        $timearray = array();
38
        for ($i = 0; $i < 24; $i++) {
39
            for ($j = 0; $j < 60; $j = $j + 10) {
40
                $key             = ($i * 3600) + ($j * 60);
41
                $timearray[$key] = ($j != 0) ? $i . ':' . $j : $i . ':0' . $j;
42
            }
43
        }
44
        ksort($timearray);
45
        $timeselect = new XoopsFormSelect('', $name . '[time]', $datetime['hours'] * 3600 + 600 * floor($datetime['minutes'] / 10));
46
        $timeselect->addOptionArray($timearray);
47
        $this->addElement($timeselect);
48
    }
49
}
50