Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoExcelFormat
0.00% covered (danger)
0.00%
0 / 20
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 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 queryAndDisplay
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2/**
3 * @author Yaron Koren
4 * @ingroup Cargo
5 */
6
7class CargoExcelFormat extends CargoDeferredFormat {
8
9    public static function allowedParameters() {
10        return [
11            'filename' => [ 'type' => 'string' ],
12            'link text' => [ 'type' => 'string' ],
13            'parse values' => [ 'type' => 'boolean' ]
14        ];
15    }
16
17    /**
18     * @param array $sqlQueries
19     * @param array $displayParams Unused
20     * @param array|null $querySpecificParams Unused
21     * @return string HTML
22     */
23    public function queryAndDisplay( $sqlQueries, $displayParams, $querySpecificParams = null ) {
24        $ce = SpecialPage::getTitleFor( 'CargoExport' );
25        $queryParams = $this->sqlQueriesToQueryParams( $sqlQueries );
26        $queryParams['format'] = 'excel';
27        if ( array_key_exists( 'filename', $displayParams ) && $displayParams['filename'] != '' ) {
28            $queryParams['filename'] = $displayParams['filename'];
29        }
30        if ( array_key_exists( 'parse values', $displayParams ) && $displayParams['parse values'] != '' ) {
31            $queryParams['parse values'] = $displayParams['parse values'];
32        }
33        if ( array_key_exists( 'link text', $displayParams ) && $displayParams['link text'] != '' ) {
34            $linkText = $displayParams['link text'];
35        } else {
36            $linkText = wfMessage( 'cargo-viewxls' )->text();
37        }
38        $linkAttrs = [
39            'href' => $ce->getFullURL( $queryParams ),
40        ];
41        $text = Html::rawElement( 'a', $linkAttrs, $linkText );
42
43        return $text;
44    }
45
46}