Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CargoBarChartFormat | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
allowedParameters | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
queryAndDisplay | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | /** |
3 | * @author Yaron Koren |
4 | * @ingroup Cargo |
5 | */ |
6 | |
7 | class CargoBarChartFormat extends CargoDeferredFormat { |
8 | public static function allowedParameters() { |
9 | return [ |
10 | 'height' => [ 'type' => 'int', 'label' => wfMessage( 'cargo-viewdata-heightparam' )->parse() ], |
11 | 'width' => [ 'type' => 'int', 'label' => wfMessage( 'cargo-viewdata-widthparam' )->parse() ] |
12 | ]; |
13 | } |
14 | |
15 | /** |
16 | * @param array $sqlQueries |
17 | * @param array $displayParams |
18 | * @param array|null $querySpecificParams Unused |
19 | * @return string HTML |
20 | */ |
21 | public function queryAndDisplay( $sqlQueries, $displayParams, $querySpecificParams = null ) { |
22 | $this->mOutput->addModules( [ 'ext.cargo.nvd3' ] ); |
23 | $ce = SpecialPage::getTitleFor( 'CargoExport' ); |
24 | $queryParams = $this->sqlQueriesToQueryParams( $sqlQueries ); |
25 | $queryParams['format'] = 'nvd3chart'; |
26 | |
27 | $svgAttrs = []; |
28 | if ( array_key_exists( 'width', $displayParams ) && $displayParams['width'] != '' ) { |
29 | $width = $displayParams['width']; |
30 | // Add on "px", if no unit is defined. |
31 | if ( is_numeric( $width ) ) { |
32 | $width .= "px"; |
33 | } |
34 | $svgAttrs['width'] = $width; |
35 | } else { |
36 | $svgAttrs['width'] = "100%"; |
37 | } |
38 | if ( array_key_exists( 'height', $displayParams ) && $displayParams['height'] != '' ) { |
39 | $height = $displayParams['height']; |
40 | // Add on "px", if no unit is defined. |
41 | if ( is_numeric( $height ) ) { |
42 | $height .= "px"; |
43 | } |
44 | $svgAttrs['height'] = $height; |
45 | } else { |
46 | // Stub value, so that we know to replace it. |
47 | $svgAttrs['height'] = '1px'; |
48 | } |
49 | |
50 | $svgText = Html::element( 'svg', $svgAttrs, '' ); |
51 | |
52 | $divAttrs = [ |
53 | 'class' => 'cargoBarChart', |
54 | 'dataurl' => $ce->getFullURL( $queryParams ), |
55 | ]; |
56 | $text = Html::rawElement( 'div', $divAttrs, $svgText ); |
57 | |
58 | return $text; |
59 | } |
60 | |
61 | } |