Completed
Branch master (55a138)
by Michael
03:21
created

FormDateTime   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 57 6
1
<?php namespace XoopsModules\Extcal\Form;
2
3
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
4
5
/**
6
 * Class FormDateTime.
7
 */
8
class FormDateTime
9
{
10
    /**
11
     * @param ThemeForm $form
12
     * @param int             $startTS
13
     * @param int             $endTS
14
     *
15
     * @return FormDateTime
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
16
     */
17
    public function __construct($form, $startTS = 0, $endTS = 0)
18
    {
19
        $startTS       = (int)$startTS;
20
        $startTS       = ($startTS > 0) ? $startTS : time();
21
        $startDatetime = getdate($startTS);
22
23
        $endTS       = (int)$endTS;
24
        $endTS       = ($endTS > 0) ? $endTS : time();
25
        $endDatetime = getdate($endTS);
26
27
        $timearray = [];
28
        for ($i = 0; $i < 24; ++$i) {
29
            for ($j = 0; $j < _EXTCAL_TS_MINUTE; $j += 15) {
30
                $key             = ($i * _EXTCAL_TS_HOUR) + ($j * _EXTCAL_TS_MINUTE);
31
                $timearray[$key] = (0 != $j) ? $i . ':' . $j : $i . ':0' . $j;
32
            }
33
        }
34
        ksort($timearray);
35
36
        // test new calendar
37
        //         require_once (XOOPS_ROOT_PATH . "/class/xoopsform/dateselect/formdateselect.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
        //         $test = new \XoopsFormDateSelect('', 'event_start[date]', 15, $startTS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
        //         $test->setExtra('onBlur=\'validDate("event_start[date]", "event_start[time]", "event_end[date]", "event_end[time]");\'');
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
        //         $form->addElement($test);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
42
        // Start date element's form
43
        $startElmtTray = new \XoopsFormElementTray(_MD_EXTCAL_START_DATE, '&nbsp;');
44
45
        $startDate = new \XoopsFormTextDateSelect('', 'event_start[date]', 15, $startTS);
46
        $startDate->setExtra('onBlur=\'validDate("event_start[date]", "event_start[time]", "event_end[date]", "event_end[time]");\'');
47
        $startElmtTray->addElement($startDate);
48
49
        $startTime = new \XoopsFormSelect('', 'event_start[time]', $startDatetime['hours'] * _EXTCAL_TS_HOUR + 600 * ceil($startDatetime['minutes'] / 10));
50
        $startTime->setExtra('onChange=\'validDate("event_start[date]", "event_start[time]", "event_end[date]", "event_end[time]");\'');
51
        $startTime->addOptionArray($timearray);
52
        $startElmtTray->addElement($startTime);
53
54
        $form->addElement($startElmtTray, true);
55
56
        // End date element's form
57
        $endElmtTray     = new \XoopsFormElementTray(_MD_EXTCAL_END_DATE, '<br>');
58
        $endDateElmtTray = new \XoopsFormElementTray('', '&nbsp;');
59
60
        $endElmtTray->addElement( new \XoopsFormRadioYN(_MD_EXTCAL_EVENT_END, 'have_end', 1));
61
62
        $endDate = new \XoopsFormTextDateSelect('', 'event_end[date]', 15, $endTS);
63
        $endDate->setExtra('onBlur=\'validDate("event_start[date]", "event_start[time]", "event_end[date]", "event_end[time]");\'');
64
        $endDateElmtTray->addElement($endDate);
65
66
        $endTime = new \XoopsFormSelect('', 'event_end[time]', $endDatetime['hours'] * _EXTCAL_TS_HOUR + 600 * ceil($endDatetime['minutes'] / 10));
67
        $endTime->setExtra('onChange=\'validDate("event_start[date]", "event_start[time]", "event_end[date]", "event_end[time]");\'');
68
        $endTime->addOptionArray($timearray);
69
        $endDateElmtTray->addElement($endTime);
70
71
        $endElmtTray->addElement($endDateElmtTray);
72
        $form->addElement($endElmtTray);
73
    }
74
}
75