Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 50 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
PFDateTimePicker | |
0.00% |
0 / 50 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getHtmlText | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
getOtherPropTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getParameters | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
getResourceModuleNames | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * @author Stephan Gambke |
5 | * @author Sam Wilson |
6 | * @author Amr El-Absy |
7 | * @file |
8 | * @ingroup PageForms |
9 | */ |
10 | |
11 | /** |
12 | * @ingroup PageForms |
13 | */ |
14 | |
15 | use MediaWiki\Widget\DateTimeInputWidget; |
16 | |
17 | class PFDateTimePicker extends PFFormInput { |
18 | |
19 | public static function getName(): string { |
20 | return 'datetimepicker'; |
21 | } |
22 | |
23 | /** |
24 | * @param string $input_number The number of the input in the form. |
25 | * @param string $cur_value The current value of the input field. |
26 | * @param string $input_name The name of the input. |
27 | * @param bool $disabled Is this input disabled? |
28 | * @param array $other_args An associative array of other parameters that were present in the |
29 | * input definition. |
30 | */ |
31 | public function __construct( $input_number, $cur_value, $input_name, $disabled, array $other_args ) { |
32 | if ( $cur_value != '' ) { |
33 | list( $year, $month, $day, $time ) = PFDateInput::parseDate( $cur_value, true ); |
34 | $cur_value = sprintf( '%04d-%02d-%02dT%sZ', $year, $month, $day, $time ); |
35 | } |
36 | parent::__construct( $input_number, $cur_value, $input_name, $disabled, $other_args ); |
37 | } |
38 | |
39 | /** |
40 | * Returns the HTML code to be included in the output page for this input. |
41 | * |
42 | * Ideally this HTML code should provide a basic functionality even if the |
43 | * browser is not JavaScript capable. I.e. even without JavaScript the user |
44 | * should be able to input values. |
45 | * @return string |
46 | */ |
47 | public function getHtmlText(): string { |
48 | $inputID = 'input_' . $this->mInputNumber; |
49 | $widget = new DateTimeInputWidget( [ |
50 | 'type' => 'datetime', |
51 | 'name' => $this->mInputName, |
52 | 'value' => $this->mCurrentValue, |
53 | 'id' => $inputID, |
54 | 'classes' => [ 'pfDateTimePicker', 'pfPicker' ], |
55 | 'infusable' => true, |
56 | 'disabled' => $this->mIsDisabled |
57 | ] ); |
58 | $text = $widget->toString(); |
59 | |
60 | // Unfortunately, DateTimeInputWidget only allows 24-hour |
61 | // (as opposed to AM/PM) data entry, so we'll add a label to |
62 | // explain the situation. DateTimeInputWidget unfortunately |
63 | // also doesn't allow a 'label' parameter, so we have to add it |
64 | // manually. The 'for' seems to have no effect, sadly, but |
65 | // we'll add it anyway. |
66 | $text .= Html::element( 'label', |
67 | [ |
68 | 'for' => $inputID, |
69 | 'class' => 'pf-datetimepicker-help oo-ui-labelWidget oo-ui-inline-help', |
70 | 'style' => 'margin-top: 4px;' |
71 | ], |
72 | wfMessage( 'pf-datetimepicker-24hour' )->parse() |
73 | ); |
74 | |
75 | // We need a wrapper div so that OOUI won't override |
76 | // any classes added by "show on select". |
77 | $wrapperClass = 'pfPickerWrapper'; |
78 | if ( isset( $this->mOtherArgs[ 'mandatory' ] ) ) { |
79 | $wrapperClass .= ' mandatory'; |
80 | } |
81 | |
82 | return Html::rawElement( 'div', [ 'class' => $wrapperClass ], $text ); |
83 | } |
84 | |
85 | /** |
86 | * Returns the set of SMW property types which this input can |
87 | * handle, but for which it isn't the default input. |
88 | * @return string[] |
89 | */ |
90 | public static function getOtherPropTypesHandled() { |
91 | return [ '_str', '_dat' ]; |
92 | } |
93 | |
94 | /** |
95 | * Returns the set of parameters for this form input. |
96 | * @return array[] |
97 | */ |
98 | public static function getParameters() { |
99 | $params = array_merge( |
100 | parent::getParameters(), |
101 | PFDatePickerInput::getParameters() |
102 | ); |
103 | |
104 | $params['mintime'] = [ |
105 | 'name' => 'mintime', |
106 | 'type' => 'string', |
107 | 'description' => wfMessage( 'pageforms-timepicker-mintime' )->text(), |
108 | ]; |
109 | $params['maxtime'] = [ |
110 | 'name' => 'maxtime', |
111 | 'type' => 'string', |
112 | 'description' => wfMessage( 'pageforms-timepicker-maxtime' )->text(), |
113 | ]; |
114 | $params['interval'] = [ |
115 | 'name' => 'interval', |
116 | 'type' => 'int', |
117 | 'description' => wfMessage( 'pageforms-timepicker-interval' )->text(), |
118 | ]; |
119 | |
120 | return $params; |
121 | } |
122 | |
123 | /** |
124 | * Returns the names of the resource modules this input type uses. |
125 | * |
126 | * Returns the names of the modules as an array or - if there is only one |
127 | * module - as a string. |
128 | * |
129 | * @return null|string|array |
130 | */ |
131 | public function getResourceModuleNames() { |
132 | return [ 'ext.pageforms.datetimepicker' ]; |
133 | } |
134 | |
135 | } |