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