Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoCalendarFormat
0.00% covered (danger)
0.00%
0 / 46
0.00% covered (danger)
0.00%
0 / 2
272
0.00% covered (danger)
0.00%
0 / 1
 allowedParameters
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 queryAndDisplay
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 1
240
1<?php
2/**
3 * @author Yaron Koren
4 * @ingroup Cargo
5 */
6
7use MediaWiki\Html\Html;
8
9class CargoCalendarFormat 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            'start date' => [ 'type' => 'date' ],
16            'color' => [ 'type' => 'string' ],
17            'text color' => [ 'type' => 'string' ]
18        ];
19    }
20
21    /**
22     * @param array $sqlQueries
23     * @param array $displayParams
24     * @param array|null $querySpecificParams
25     * @return string HTML
26     */
27    public function queryAndDisplay( $sqlQueries, $displayParams, $querySpecificParams = null ) {
28        $this->mOutput->addModules( [ 'ext.cargo.calendar' ] );
29        $ce = SpecialPage::getTitleFor( 'CargoExport' );
30        $queryParams = $this->sqlQueriesToQueryParams( $sqlQueries );
31        $queryParams['format'] = 'fullcalendar';
32        $queryParams['color'] = [];
33        $queryParams['text color'] = [];
34        foreach ( $sqlQueries as $i => $sqlQuery ) {
35            if ( $querySpecificParams != null ) {
36                if ( array_key_exists( 'color', $querySpecificParams[$i] ) ) {
37                    $queryParams['color'][] = $querySpecificParams[$i]['color'];
38                } else {
39                    // Stick an empty value in there, to
40                    // preserve the order for the queries
41                    // that do contain a color.
42                    $queryParams['color'][] = null;
43                }
44                if ( array_key_exists( 'text color', $querySpecificParams[$i] ) ) {
45                    $queryParams['text color'][] = $querySpecificParams[$i]['text color'];
46                } else {
47                    // Stick an empty value in there, to
48                    // preserve the order for the queries
49                    // that do contain a color.
50                    $queryParams['text color'][] = null;
51                }
52            }
53        }
54
55        $width = CargoUtils::getCSSSize( $displayParams, 'width', '100%' );
56
57        if ( array_key_exists( 'height', $displayParams ) && $displayParams['height'] != '' ) {
58            $height = $displayParams['height'];
59            // The height should be either a number or "auto".
60            if ( !is_numeric( $height ) ) {
61                if ( $height != "auto" ) {
62                    $height = null;
63                }
64            }
65        } else {
66            $height = null;
67        }
68
69        $attrs = [
70            'class' => 'cargoCalendar',
71            'dataurl' => $ce->getFullURL( $queryParams ),
72            'style' => "width: $width",
73            'height' => $height,
74        ];
75        if ( array_key_exists( 'view', $displayParams ) && $displayParams['view'] != '' ) {
76            $view = $displayParams['view'];
77            // Enable simpler view names.
78            if ( $view == 'day' ) {
79                $view = 'agendaDay';
80            } elseif ( $view == 'week' ) {
81                $view = 'agendaWeek';
82            }
83            $attrs['startview'] = $view;
84        } else {
85            $attrs['startview'] = 'month';
86        }
87        if ( array_key_exists( 'start date', $displayParams ) && $displayParams['start date'] != '' ) {
88            $attrs['startdate'] = $displayParams['start date'];
89        }
90        $text = Html::rawElement( 'div', $attrs, '' );
91
92        return $text;
93    }
94
95}