Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PFListBoxInput
0.00% covered (danger)
0.00%
0 / 49
0.00% covered (danger)
0.00%
0 / 3
272
0.00% covered (danger)
0.00%
0 / 1
 getName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getParameters
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 getHtmlText
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 1
210
1<?php
2/**
3 * @file
4 * @ingroup PF
5 */
6
7/**
8 * @ingroup PFFormInput
9 */
10class PFListBoxInput extends PFMultiEnumInput {
11
12    public static function getName(): string {
13        return 'listbox';
14    }
15
16    public static function getParameters() {
17        $params = parent::getParameters();
18        $params[] = [
19            'name' => 'size',
20            'type' => 'int',
21            'description' => wfMessage( 'Pf_forminputs_listboxsize' )->text()
22        ];
23        return $params;
24    }
25
26    /**
27     * Returns the HTML code to be included in the output page for this input.
28     * @return string
29     */
30    public function getHtmlText(): string {
31        global $wgPageFormsTabIndex, $wgPageFormsFieldNum;
32
33        $className = ( $this->mIsMandatory ) ? 'mandatoryField' : 'createboxInput';
34        if ( array_key_exists( 'class', $this->mOtherArgs ) ) {
35            $className .= ' ' . $this->mOtherArgs['class'];
36        }
37        $input_id = "input_$wgPageFormsFieldNum";
38        // get list delimiter - default is comma
39        if ( array_key_exists( 'delimiter', $this->mOtherArgs ) ) {
40            $delimiter = $this->mOtherArgs['delimiter'];
41        } else {
42            $delimiter = ',';
43        }
44        $cur_values = PFValuesUtils::getValuesArray( $this->mCurrentValue, $delimiter );
45
46        $possible_values = $this->mOtherArgs['possible_values'];
47        if ( $possible_values == null ) {
48            $possible_values = [];
49        }
50        $optionsText = '';
51        foreach ( $possible_values as $possible_value ) {
52            if (
53                array_key_exists( 'value_labels', $this->mOtherArgs ) &&
54                is_array( $this->mOtherArgs['value_labels'] ) &&
55                array_key_exists( $possible_value, $this->mOtherArgs['value_labels'] )
56            ) {
57                $optionLabel = $this->mOtherArgs['value_labels'][$possible_value];
58            } else {
59                $optionLabel = $possible_value;
60            }
61            $optionAttrs = [ 'value' => $possible_value ];
62            if ( in_array( $possible_value, $cur_values ) ) {
63                $optionAttrs['selected'] = 'selected';
64            }
65            $optionsText .= Html::element( 'option', $optionAttrs, $optionLabel );
66        }
67
68        if ( array_key_exists( 'show on select', $this->mOtherArgs ) ) {
69            $className .= ' pfShowIfSelected';
70            PFFormUtils::setShowOnSelect( $this->mOtherArgs['show on select'], $input_id );
71        }
72
73        $selectAttrs = [
74            'id' => $input_id,
75            'tabindex' => $wgPageFormsTabIndex,
76            'name' => $this->mInputName . '[]',
77            'class' => $className,
78            'multiple' => 'multiple'
79        ];
80        if ( array_key_exists( 'size', $this->mOtherArgs ) ) {
81            $selectAttrs['size'] = $this->mOtherArgs['size'];
82        }
83        if ( $this->mIsDisabled ) {
84            $selectAttrs['disabled'] = 'disabled';
85        }
86        $text = Html::rawElement( 'select', $selectAttrs, $optionsText );
87        $text .= Html::hidden( $this->mInputName . '[is_list]', 1 );
88        if ( $this->mIsMandatory ) {
89            $text = Html::rawElement( 'span', [ 'class' => 'inputSpan mandatoryFieldSpan' ], $text );
90        }
91
92        return $text;
93    }
94}