Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
PFRatingInput | |
0.00% |
0 / 55 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOtherPropTypesHandled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaultCargoTypes | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getParameters | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
getHtmlText | |
0.00% |
0 / 33 |
|
0.00% |
0 / 1 |
72 |
1 | <?php |
2 | /** |
3 | * @file |
4 | * @ingroup PF |
5 | */ |
6 | |
7 | /** |
8 | * @ingroup PFFormInput |
9 | */ |
10 | class PFRatingInput extends PFFormInput { |
11 | |
12 | public static function getName(): string { |
13 | return 'rating'; |
14 | } |
15 | |
16 | public static function getOtherPropTypesHandled() { |
17 | return [ '_num' ]; |
18 | } |
19 | |
20 | public static function getDefaultCargoTypes() { |
21 | return [ |
22 | 'Rating' => [] |
23 | ]; |
24 | } |
25 | |
26 | public static function getParameters() { |
27 | $params = parent::getParameters(); |
28 | |
29 | $params['star width'] = [ |
30 | 'name' => 'star width', |
31 | 'type' => 'string', |
32 | 'description' => wfMessage( 'pf_forminputs_starwidth' )->text() |
33 | ]; |
34 | $params['num stars'] = [ |
35 | 'name' => 'num stars', |
36 | 'type' => 'int', |
37 | 'description' => wfMessage( 'pf_forminputs_numstars' )->text() |
38 | ]; |
39 | $params['allow half stars'] = [ |
40 | 'name' => 'allow half stars', |
41 | 'type' => 'boolean', |
42 | 'description' => wfMessage( 'pf_forminputs_allowhalfstars' )->text() |
43 | ]; |
44 | |
45 | return $params; |
46 | } |
47 | |
48 | /** |
49 | * Returns the HTML code to be included in the output page for this input. |
50 | * @return string |
51 | */ |
52 | public function getHtmlText(): string { |
53 | global $wgPageFormsFieldNum; |
54 | |
55 | $className = 'pfRating'; |
56 | if ( $this->mIsMandatory ) { |
57 | $className .= ' mandatoryField'; |
58 | } |
59 | if ( array_key_exists( 'class', $this->mOtherArgs ) ) { |
60 | $className .= ' ' . $this->mOtherArgs['class']; |
61 | } |
62 | $input_id = "input_$wgPageFormsFieldNum"; |
63 | $ratingAttrs = [ |
64 | 'class' => $className, |
65 | // Not useful, since the rating can't be modified |
66 | // via the keyboard. |
67 | // 'tabindex' => $wgPageFormsTabIndex, |
68 | 'data-curvalue' => $this->mCurrentValue |
69 | |
70 | ]; |
71 | if ( $this->mIsDisabled ) { |
72 | $ratingAttrs['disabled'] = 'disabled'; |
73 | } |
74 | if ( array_key_exists( 'origName', $this->mOtherArgs ) ) { |
75 | $ratingAttrs['origname'] = $this->mOtherArgs['origName']; |
76 | } |
77 | if ( array_key_exists( 'star width', $this->mOtherArgs ) ) { |
78 | $ratingAttrs['data-starwidth'] = $this->mOtherArgs['star width']; |
79 | } else { |
80 | $ratingAttrs['data-starwidth'] = '24px'; |
81 | } |
82 | if ( array_key_exists( 'num stars', $this->mOtherArgs ) ) { |
83 | $ratingAttrs['data-numstars'] = $this->mOtherArgs['num stars']; |
84 | } else { |
85 | $ratingAttrs['data-numstars'] = 5; |
86 | } |
87 | if ( array_key_exists( 'allow half stars', $this->mOtherArgs ) ) { |
88 | $ratingAttrs['data-allows-half'] = true; |
89 | } |
90 | $hiddenInputAttrs = [ |
91 | 'id' => $input_id |
92 | ]; |
93 | |
94 | $hiddenInput = Html::hidden( |
95 | $this->mInputName, |
96 | $this->mCurrentValue, |
97 | $hiddenInputAttrs |
98 | ); |
99 | |
100 | $text = Html::element( 'div', $ratingAttrs ) . ' ' . $hiddenInput; |
101 | // For some reason this wrapper has to be a div, not a span, |
102 | // or else the HTML gets messed up. |
103 | $text = Html::rawElement( 'div', [ 'class' => 'pfRatingWrapper' ], $text ); |
104 | |
105 | return $text; |
106 | } |
107 | } |