Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 57 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
PFTimePickerInput | |
0.00% |
0 / 57 |
|
0.00% |
0 / 7 |
380 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
setupJsInitAttribs | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
110 | |||
getHtmlText | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
getOtherPropTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParameters | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
getResourceModuleNames | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @author Stephan Gambke |
5 | * @file |
6 | */ |
7 | |
8 | class PFTimePickerInput extends PFFormInput { |
9 | |
10 | public static function getName(): string { |
11 | return 'timepicker'; |
12 | } |
13 | |
14 | /** |
15 | * @param string $input_number The number of the input in the form. |
16 | * @param string $cur_value The current value of the input field. |
17 | * @param string $input_name The name of the input. |
18 | * @param bool $disabled Is this input disabled? |
19 | * @param array $other_args An associative array of other parameters that were present in the |
20 | * input definition. |
21 | */ |
22 | public function __construct( $input_number, $cur_value, $input_name, $disabled, array $other_args ) { |
23 | if ( $cur_value == 'now' ) { |
24 | // Hours and minutes. |
25 | $cur_value = date( 'H:i' ); |
26 | } |
27 | parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
28 | |
29 | $this->addJsInitFunctionData( 'PF_TP_init', $this->setupJsInitAttribs() ); |
30 | } |
31 | |
32 | /** |
33 | * Set up JS attributes |
34 | * |
35 | * @return string[] |
36 | */ |
37 | protected function setupJsInitAttribs() { |
38 | global $wgExtensionAssetsPath; |
39 | |
40 | // store user class(es) for use with buttons |
41 | $userClasses = array_key_exists( 'class', $this->mOtherArgs ) ? $this->mOtherArgs['class'] : ''; |
42 | |
43 | // set min time if valid, else use default |
44 | if ( array_key_exists( 'mintime', $this->mOtherArgs ) |
45 | && ( preg_match( '/^\d+:\d\d$/', trim( $this->mOtherArgs['mintime'] ) ) == 1 ) ) { |
46 | $minTime = trim( $this->mOtherArgs['mintime'] ); |
47 | } else { |
48 | $minTime = '00:00'; |
49 | } |
50 | |
51 | // set max time if valid, else use default |
52 | if ( array_key_exists( 'maxtime', $this->mOtherArgs ) |
53 | && ( preg_match( '/^\d+:\d\d$/', trim( $this->mOtherArgs['maxtime'] ) ) == 1 ) ) { |
54 | $maxTime = trim( $this->mOtherArgs['maxtime'] ); |
55 | } else { |
56 | $maxTime = '23:59'; |
57 | } |
58 | |
59 | // set interval if valid, else use default |
60 | if ( array_key_exists( 'interval', $this->mOtherArgs ) |
61 | && preg_match( '/^\d+$/', trim( $this->mOtherArgs['interval'] ) ) == 1 ) { |
62 | $interval = trim( $this->mOtherArgs['interval'] ); |
63 | } else { |
64 | $interval = '15'; |
65 | } |
66 | |
67 | // build JS code from attributes array |
68 | $jsattribs = [ |
69 | 'minTime' => $minTime, |
70 | 'maxTime' => $maxTime, |
71 | 'interval' => $interval, |
72 | 'format' => 'hh:mm', |
73 | 'currValue' => $this->mCurrentValue, |
74 | 'disabled' => $this->mIsDisabled, |
75 | 'userClasses' => $userClasses |
76 | ]; |
77 | |
78 | if ( array_key_exists( 'part of dtp', $this->mOtherArgs ) ) { |
79 | $jsattribs['partOfDTP'] = $this->mOtherArgs['part of dtp']; |
80 | } |
81 | |
82 | // setup attributes required only for either disabled or enabled timepickers |
83 | if ( $this->mIsDisabled ) { |
84 | $jsattribs['buttonImage'] = $wgExtensionAssetsPath . '/PageForms/images/TimePickerButtonDisabled.gif'; |
85 | |
86 | } else { |
87 | $jsattribs['buttonImage'] = $wgExtensionAssetsPath . '/PageForms/images/TimePickerButton.gif'; |
88 | } |
89 | |
90 | return $jsattribs; |
91 | } |
92 | |
93 | /** |
94 | * Returns the HTML code to be included in the output page for this input. |
95 | * |
96 | * Ideally this HTML code should provide a basic functionality even if the |
97 | * browser is not Javascript capable. I.e. even without Javascript the user |
98 | * should be able to input values. |
99 | * @return string |
100 | */ |
101 | public function getHtmlText(): string { |
102 | // create visible input field (for display) and invisible field (for data) |
103 | $html = PFDatePickerInput::genericTextHTML( $this->mCurrentValue, $this->mInputName, $this->mIsDisabled, $this->mOtherArgs, 'input_' . $this->mInputNumber ); |
104 | |
105 | // wrap in span (e.g. used for mandatory inputs) |
106 | if ( !array_key_exists( 'part of dtp', $this->mOtherArgs ) ) { |
107 | $html = '<span class="inputSpan' . ( array_key_exists( 'mandatory', $this->mOtherArgs ) ? ' mandatoryFieldSpan' : '' ) . '">' . $html . '</span>'; |
108 | } |
109 | |
110 | return $html; |
111 | } |
112 | |
113 | /** |
114 | * Returns the set of SMW property types which this input can |
115 | * handle, but for which it isn't the default input. |
116 | * @return string[] |
117 | */ |
118 | public static function getOtherPropTypesHandled() { |
119 | return [ '_str', '_dat' ]; |
120 | } |
121 | |
122 | /** |
123 | * Returns the set of parameters for this form input. |
124 | * |
125 | * TODO: Specify parameters specific for menuselect. |
126 | * @return array[] |
127 | */ |
128 | public static function getParameters() { |
129 | $params = parent::getParameters(); |
130 | $params['mintime'] = [ |
131 | 'name' => 'mintime', |
132 | 'type' => 'string', |
133 | 'description' => wfMessage( 'semanticformsinputs-timepicker-mintime' )->text(), |
134 | ]; |
135 | $params['maxtime'] = [ |
136 | 'name' => 'maxtime', |
137 | 'type' => 'string', |
138 | 'description' => wfMessage( 'semanticformsinputs-timepicker-maxtime' )->text(), |
139 | ]; |
140 | $params['interval'] = [ |
141 | 'name' => 'interval', |
142 | 'type' => 'int', |
143 | 'description' => wfMessage( 'semanticformsinputs-timepicker-interval' )->text(), |
144 | ]; |
145 | |
146 | return $params; |
147 | } |
148 | |
149 | /** |
150 | * Returns the names of the resource modules this input type uses. |
151 | * |
152 | * Returns the names of the modules as an array or - if there is only one |
153 | * module - as a string. |
154 | * |
155 | * @return null|string|array |
156 | */ |
157 | public function getResourceModuleNames() { |
158 | return 'ext.semanticformsinputs.timepicker'; |
159 | } |
160 | } |