FormDateTimePicker   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 145
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 105
c 0
b 0
f 0
dl 0
loc 145
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B render() 0 119 4
A __construct() 0 6 5
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopspoll;
4
5
/**
6
 * Xoopspoll form timepicker
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright ::   &copy; {@link https://xoops.org/ XOOPS Project}
16
 * @license   ::     {@link https://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU GPL 2}
17
 * @subpackage::  class
18
 * @since     ::       1.40
19
 * @author    ::      TXMod Xoops (aka timgno) {@link https://www.txmodxoops.org/ TXMod Xoops}
20
 * @author    ::      zyspec <[email protected]>
21
 * @credits::     {@link https://www.trentrichardson.com Trent Richardson}
22
 */
23
24
/**
25
 * Creates a text field with jquery ui calendar & time select popup
26
 */
27
class FormDateTimePicker extends \XoopsFormText
28
{
29
    /**
30
     * Contains the maximum field size
31
     */
32
    public const MAXSIZE = 25;
33
34
    /**
35
     * Constructor to build FormDateTimePicker object
36
     * @param mixed $caption HTML description to display for the element
37
     * @param mixed $name    HTML element name (ie. name='$name')
38
     * @param mixed $size    size of field to display
39
     * @param mixed $value   timestamp of date/time to show
40
     */
41
    public function __construct($caption, $name, $size, $value)
42
    {
43
        $value = (!\is_numeric($value) || (0 === (int)$value)) ? \time($value) : (int)$value;
0 ignored issues
show
Unused Code introduced by
The call to time() has too many arguments starting with $value. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        $value = (!\is_numeric($value) || (0 === (int)$value)) ? /** @scrutinizer ignore-call */ \time($value) : (int)$value;

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
44
        $size  = (int)$size;
45
        $size  = ($size > 0 && $size <= self::MAXSIZE) ? $size : self::MAXSIZE;
46
        parent::__construct($caption, $name, $size, self::MAXSIZE, $value);
47
    }
48
49
    /**
50
     * Generate the HTML <input> to display the date/time field
51
     * @return string HTML code used to display in a form
52
     */
53
    public function render(): string
54
    {
55
        static $included = false;
56
57
        $ele_name  = $this->getName();
58
        $ele_value = $this->getValue(true);
59
        //        if (is_string($ele_value)) {
60
        if (\is_numeric($ele_value)) {
61
            //            $display_value = '';
62
            //            $display_value = formatTimestamp($ele_value, 'm');
63
            $display_value = \ucfirst(\date(_MEDIUMDATESTRING, (int)$ele_value));
64
        } else {
65
            $display_value = $ele_value;
66
            $ele_value     = \time();
0 ignored issues
show
Unused Code introduced by
The assignment to $ele_value is dead and can be removed.
Loading history...
67
        }
68
69
        if (\is_object($GLOBALS['xoTheme'])) {
70
            $moduleHandler = \xoops_getHandler('module');
71
            $sys_module    = $moduleHandler->getByDirname('system');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
            /** @scrutinizer ignore-call */ 
72
            $sys_module    = $moduleHandler->getByDirname('system');
Loading history...
72
            $configHandler = \xoops_getHandler('config');
73
            $moduleConfig  = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid'));
0 ignored issues
show
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
            /** @scrutinizer ignore-call */ 
74
            $moduleConfig  = $configHandler->getConfigsByCat(0, $sys_module->getVar('mid'));
Loading history...
74
            $jq_theme_dir  = $moduleConfig['jquery_theme'];
75
76
            $GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url("modules/system/css/ui/{$jq_theme_dir}/ui.all.css"));
77
            $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
78
            $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
79
            $GLOBALS['xoTheme']->addScript('browse.php?modules/xoopspoll/assets/js/jquery-ui-timepicker-addon.js');
80
            $GLOBALS['xoTheme']->addScript('browse.php?modules/xoopspoll/assets/js/jquery-ui-sliderAccess.js');
81
            $GLOBALS['xoTheme']->addStylesheet($GLOBALS['xoops']->url('modules/xoopspoll/assets/css/datetimepicker.css'));
82
83
            if (!$included) {
84
                $included = true;
85
                \xoops_loadLanguage('admin', 'xoopspoll');
86
                // setup regional date variables
87
                $reg_values = "closeText: '"
88
                              . \_AM_XOOPSPOLL_DTP_CLOSETEXT
89
                              . "',"
90
                              . "prevText: '"
91
                              . \_AM_XOOPSPOLL_DTP_PREVTEXT
92
                              . "',"
93
                              . "nextText: '"
94
                              . \_AM_XOOPSPOLL_DTP_NEXTTEXT
95
                              . "',"
96
                              . "currentText: '"
97
                              . \_AM_XOOPSPOLL_DTP_CURRENTTEXT
98
                              . "',"
99
                              . 'monthNames: ['
100
                              . \_AM_XOOPSPOLL_DTP_MONTHNAMES
101
                              . '],'
102
                              . 'monthNamesShort: ['
103
                              . \_AM_XOOPSPOLL_DTP_MONTHNAMESSHORT
104
                              . '],'
105
                              . 'dayNames: ['
106
                              . \_AM_XOOPSPOLL_DTP_DAYNAMES
107
                              . '],'
108
                              . 'dayNamesShort: ['
109
                              . \_AM_XOOPSPOLL_DTP_DAYNAMESSHORT
110
                              . '],'
111
                              . 'dayNamesMin: ['
112
                              . \_AM_XOOPSPOLL_DTP_DAYNAMESMIN
113
                              . '],'
114
                              . "weekHeader: '"
115
                              . \_AM_XOOPSPOLL_DTP_WEEKHEADER
116
                              . "',"
117
                              . "dateFormat: '"
118
                              . \_AM_XOOPSPOLL_DTP_DATEFORMAT
119
                              . "',"
120
                              . "firstDay: '"
121
                              . \_AM_XOOPSPOLL_DTP_FIRSTDAY
122
                              . "',"
123
                              . 'isRTL: '
124
                              . \_AM_XOOPSPOLL_DTP_ISRTL
125
                              . ','
126
                              . 'showMonthAfterYear: '
127
                              . \_AM_XOOPSPOLL_DTP_SHOWMONTHAFTERYEAR
128
                              . ','
129
                              . "yearSuffix: '"
130
                              . \_AM_XOOPSPOLL_DTP_YEARSUFFIX
131
                              . "',";
132
                // set regional time variables
133
                $reg_values .= "timeOnlyTitle: '"
134
                               . \_AM_XOOPSPOLL_DTP_TIMEONLYTITLE
135
                               . "',"
136
                               . "timeText: '"
137
                               . \_AM_XOOPSPOLL_DTP_TIMETEXT
138
                               . "',"
139
                               . "hourText: '"
140
                               . \_AM_XOOPSPOLL_DTP_HOURTEXT
141
                               . "',"
142
                               . "minuteText: '"
143
                               . \_AM_XOOPSPOLL_DTP_MINUTETEXT
144
                               . "',"
145
                               . "secondText: '"
146
                               . \_AM_XOOPSPOLL_DTP_SECONDTEXT
147
                               . "',"
148
                               . "millisecText: '"
149
                               . \_AM_XOOPSPOLL_DTP_MILLISECTEXT
150
                               . "',"
151
                               . "timeFormat: '"
152
                               . \_AM_XOOPSPOLL_DTP_TIMEFORMAT
153
                               . "',"
154
                               . 'ampm: false,'
155
                               . 'stepMinute: 5';
156
157
                $GLOBALS['xoTheme']->addScript(
158
                    '',
159
                    '',
160
                    '
161
                  $(function() {
162
                      $( ".datetimepicker" ).datetimepicker({
163
                          ' . $reg_values . '
164
                      });
165
                  });
166
        '
167
                );
168
            }
169
        }
170
171
        return "<input type='text' name='{$ele_name}' id='{$ele_name}' class='datetimepicker' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='{$display_value}'" . $this->getExtra() . '>';
172
    }
173
}
174