Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 69 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
PFCheckboxesInput | |
0.00% |
0 / 69 |
|
0.00% |
0 / 7 |
506 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultPropTypeLists | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOtherPropTypeListsHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultCargoTypeLists | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getOtherCargoTypeListsHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHTML | |
0.00% |
0 / 53 |
|
0.00% |
0 / 1 |
272 | |||
getHtmlText | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @file |
4 | * @ingroup PF |
5 | */ |
6 | |
7 | /** |
8 | * @ingroup PFFormInput |
9 | */ |
10 | class PFCheckboxesInput extends PFMultiEnumInput { |
11 | |
12 | public static function getName(): string { |
13 | return 'checkboxes'; |
14 | } |
15 | |
16 | public static function getDefaultPropTypeLists() { |
17 | return [ |
18 | 'enumeration' => [] |
19 | ]; |
20 | } |
21 | |
22 | public static function getOtherPropTypeListsHandled() { |
23 | return []; |
24 | } |
25 | |
26 | public static function getDefaultCargoTypeLists() { |
27 | return [ |
28 | 'Enumeration' => [] |
29 | ]; |
30 | } |
31 | |
32 | public static function getOtherCargoTypeListsHandled() { |
33 | return []; |
34 | } |
35 | |
36 | public static function getHTML( $cur_value, $input_name, $is_mandatory, $is_disabled, array $other_args ) { |
37 | global $wgPageFormsTabIndex, $wgPageFormsFieldNum; |
38 | |
39 | $labelClass = 'checkboxLabel'; |
40 | if ( array_key_exists( 'class', $other_args ) ) { |
41 | $labelClass .= ' ' . $other_args['class']; |
42 | } |
43 | $input_id = "input_$wgPageFormsFieldNum"; |
44 | // get list delimiter - default is comma |
45 | if ( array_key_exists( 'delimiter', $other_args ) ) { |
46 | $delimiter = $other_args['delimiter']; |
47 | } else { |
48 | $delimiter = ','; |
49 | } |
50 | $cur_values = PFValuesUtils::getValuesArray( $cur_value, $delimiter ); |
51 | |
52 | $possible_values = $other_args['possible_values']; |
53 | if ( $possible_values == null ) { |
54 | $possible_values = []; |
55 | } |
56 | $text = ''; |
57 | foreach ( $possible_values as $key => $possible_value ) { |
58 | $cur_input_name = $input_name . '[' . $key . ']'; |
59 | |
60 | if ( |
61 | array_key_exists( 'value_labels', $other_args ) && |
62 | is_array( $other_args['value_labels'] ) && |
63 | array_key_exists( $possible_value, $other_args['value_labels'] ) |
64 | ) { |
65 | $label = $other_args['value_labels'][$possible_value]; |
66 | } else { |
67 | $label = $possible_value; |
68 | } |
69 | |
70 | $checkbox_attrs = [ |
71 | 'name' => $cur_input_name, |
72 | 'value' => $possible_value, |
73 | 'id' => $input_id, |
74 | 'tabIndex' => $wgPageFormsTabIndex, |
75 | 'label' => 'checkbox' |
76 | ]; |
77 | if ( in_array( $possible_value, $cur_values ) ) { |
78 | $checkbox_attrs['checked'] = 'checked'; |
79 | $checkbox_attrs['selected'] = true; |
80 | } |
81 | if ( $is_disabled ) { |
82 | $checkbox_attrs['disabled'] = 'disabled'; |
83 | } |
84 | $checkbox_input = new OOUI\CheckboxInputWidget( $checkbox_attrs ) . "<t />"; |
85 | |
86 | // Put a <label> tag around each checkbox, for CSS |
87 | // purposes as well as to clarify this element. |
88 | $text .= "\t" . Html::rawElement( 'label', |
89 | [ 'class' => $labelClass ], |
90 | $checkbox_input . ' ' . $label |
91 | ) . " "; |
92 | $wgPageFormsTabIndex++; |
93 | $wgPageFormsFieldNum++; |
94 | } |
95 | |
96 | $outerSpanID = "span_$wgPageFormsFieldNum"; |
97 | $outerSpanClass = 'checkboxesSpan'; |
98 | if ( $is_mandatory ) { |
99 | $outerSpanClass .= ' mandatoryFieldSpan'; |
100 | } |
101 | |
102 | // @HACK! The current "select all/none" JS code doesn't work |
103 | // when this input is part of a multiple-instance template, so |
104 | // if that happens, just don't display those links. |
105 | // Unfortunately, there's no easy way to know if we're in a |
106 | // multiple-instance template, so look at the input name - if |
107 | // it contains "[num][", we can assume that we are. |
108 | // @TODO - get the JS working in multiple-instance templates - |
109 | // this will probably require rewriting the checkboxes JS |
110 | // to some extent, so the relevant part can be called each |
111 | // time an instance is added. |
112 | if ( strpos( $input_name, '[num][' ) !== false ) { |
113 | // Multiple-instance template; do nothing. |
114 | } elseif ( array_key_exists( 'show select all', $other_args ) || |
115 | ( count( $possible_values ) >= $GLOBALS[ 'wgPageFormsCheckboxesSelectAllMinimum' ] && !array_key_exists( 'hide select all', $other_args ) ) ) { |
116 | $outerSpanClass .= ' select-all'; |
117 | } |
118 | |
119 | if ( array_key_exists( 'show on select', $other_args ) ) { |
120 | $outerSpanClass .= ' pfShowIfChecked'; |
121 | PFFormUtils::setShowOnSelect( $other_args['show on select'], $outerSpanID ); |
122 | } |
123 | |
124 | $text .= Html::hidden( $input_name . '[is_list]', 1 ); |
125 | $outerSpanAttrs = [ 'id' => $outerSpanID, 'class' => $outerSpanClass ]; |
126 | $text = "\t" . Html::rawElement( 'span', $outerSpanAttrs, $text ) . "\n"; |
127 | |
128 | return $text; |
129 | } |
130 | |
131 | /** |
132 | * Returns the HTML code to be included in the output page for this input. |
133 | * @return string |
134 | */ |
135 | public function getHtmlText(): string { |
136 | return self::getHTML( |
137 | $this->mCurrentValue, |
138 | $this->mInputName, |
139 | $this->mIsMandatory, |
140 | $this->mIsDisabled, |
141 | $this->mOtherArgs |
142 | ); |
143 | } |
144 | } |