Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoTimelineFormat
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 2
72
0.00% covered (danger)
0.00%
0 / 1
 allowedParameters
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 queryAndDisplay
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2/**
3 * @author Yaron Koren
4 * @ingroup Cargo
5 */
6
7use MediaWiki\Html\Html;
8
9class CargoTimelineFormat extends CargoDeferredFormat {
10
11    public static function allowedParameters() {
12        return [
13            'height' => [ 'type' => 'int', 'label' => wfMessage( 'cargo-viewdata-heightparam' )->parse() ],
14            'width' => [ 'type' => 'int', 'label' => wfMessage( 'cargo-viewdata-widthparam' )->parse() ]
15        ];
16    }
17
18    /**
19     * @param array $sqlQueries
20     * @param array $displayParams
21     * @param array|null $querySpecificParams Unused
22     * @return string HTML
23     */
24    public function queryAndDisplay( $sqlQueries, $displayParams, $querySpecificParams = null ) {
25        $this->mOutput->addModules( [ 'ext.cargo.timeline' ] );
26        $ce = SpecialPage::getTitleFor( 'CargoExport' );
27        $queryParams = $this->sqlQueriesToQueryParams( $sqlQueries );
28        $queryParams['format'] = 'timeline';
29        // $queryParams['color'] = array();
30        /* foreach ( $sqlQueries as $i => $sqlQuery ) {
31          if ( $querySpecificParams != null ) {
32          // Add any handling here.
33          }
34          } */
35
36        if ( array_key_exists( 'height', $displayParams ) && $displayParams['height'] != '' ) {
37            $height = $displayParams['height'];
38            // Add on "px", if no unit is defined.
39            if ( is_numeric( $height ) ) {
40                $height .= "px";
41            }
42        } else {
43            $height = "350px";
44        }
45        if ( array_key_exists( 'width', $displayParams ) && $displayParams['width'] != '' ) {
46            $width = $displayParams['width'];
47            // Add on "px", if no unit is defined.
48            if ( is_numeric( $width ) ) {
49                $width .= "px";
50            }
51        } else {
52            $width = "100%";
53        }
54
55        $attrs = [
56            'class' => 'cargoTimeline',
57            'dataurl' => $ce->getFullURL( $queryParams ),
58            'style' => "height: $height; width: $width; border: 1px solid #aaa;"
59        ];
60        $text = Html::rawElement( 'div', $attrs, '' );
61
62        return $text;
63    }
64
65}