Completed
Pull Request — master (#586)
by
unknown
06:03
created

EventCalendar::getResultText()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 21
cts 21
cp 1
rs 9.28
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace SRF;
4
5
use Html;
6
use SMW\ResultPrinter;
7
use SMWQueryResult as QueryResult;
8
9
/**
10
 * An event calendar printer using the FullCalendar JavaScript library
11
 * and SMWAPI.
12
 *
13
 * @since 1.9
14
 *
15
 * @file
16
 * @ingroup QueryPrinter
17
 *
18
 * @licence GNU GPL v2+
19
 * @author mwjames
20
 */
21
22
/**
23
 * Query printer supporting a JavaScript Event calendar using the
24
 * Semantic MediaWiki Api
25
 *
26
 * @ingroup QueryPrinter
27
 */
28
class EventCalendar extends ResultPrinter {
29
30
	/**
31
	 * @see ResultPrinter::getName
32
	 *
33
	 * {@inheritDoc}
34
	 */
35
	public function getName() {
36
		return $this->msg( 'srf-printername-eventcalendar' )->text();
37
	}
38
39
	/**
40
	 * @see ResultPrinter::getParamDefinitions
41
	 *
42
	 * @since 1.8
43
	 *
44
	 * {@inheritDoc}
45
	 */
46 1
	public function getParamDefinitions( array $definitions ) {
47 1
		$params = parent::getParamDefinitions( $definitions );
48
49 1
		$params['defaultview'] = [
50
			'message' => 'srf-paramdesc-calendardefaultview',
51
			'default' => 'month',
52
			'values' => [
53
				'month',
54
				'basicweek',
55
				'basicday',
56
				'agendaweek',
57
				'agendaday',
58
				'listday',
59
				'listweek',
60
				'listmonth' ]
61
		];
62
63 1
		$params['views'] = [
64
			'message' => 'srf-paramdesc-calendarviews',
65
			'default' => 'month,basicWeek,agendaDay'
66
		];
67 1
		$params['firstday'] = [
68
			'message' => 'srf-paramdesc-calendarfirstday',
69
			'default' => 'Sunday',
70
			'values' => [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
71
		];
72
73 1
		$params['start'] = [
74
			'message' => 'srf-paramdesc-calendarstart',
75
			'default' => 'current',
76
			'values' => [ 'current', 'earliest', 'latest' ]
77
		];
78
79 1
		$params['legend'] = [
80
			'message' => 'srf-paramdesc-calendarlegend',
81
			'default' => 'none',
82
			'values' => [ 'none', 'top', 'bottom', 'tooltip', 'pane' ]
83
		];
84
85 1
		$params['dayview'] = [
86
			'type' => 'boolean',
87
			'message' => 'srf-paramdesc-dayview',
88
			'default' => false
89
		];
90
91 1
		$params['class'] = [
92
			'message' => 'srf-paramdesc-class',
93
			'default' => '',
94
		];
95
96 1
		$params['theme'] = [
97
			'message' => 'srf-paramdesc-theme',
98
			'default' => 'basic',
99
			'values' => [ 'basic', 'vector' ]
100
		];
101
102 1
		$params['clicktarget'] = [
103
			'message' => 'srf-paramdesc-clicktarget',
104
			'default' => 'none'
105
		];
106
107 1
		$params['includeend'] = [
108
			'type' => 'boolean',
109
			'message' => 'srf-paramdesc-includeend',
110
			'default' => false
111
		];
112
113 1
		return $params;
114
	}
115
116
	/**
117
	 * @see ResultPrinter::getResultText
118
	 *
119
	 * {@inheritDoc}
120
	 */
121 1
	protected function getResultText( QueryResult $res, $outputmode ) {
122
123 1
		$resourceFormatter = new ResourceFormatter();
124 1
		$data = $resourceFormatter->getData( $res, $outputmode, $this->params );
125
126 1
		$this->isHTML = true;
127 1
		$id = $resourceFormatter->session();
128
129
		// Add options
130 1
		$data['version'] = '0.8.0';
131
132
		// Encode data object
133 1
		$resourceFormatter->encode( $id, $data );
134
135
		// Init RL module
136 1
		$resourceFormatter->registerResources( [ 'ext.srf.eventcalendar' ] );
137
138
		// Element includes info, spinner, and container placeholder
139 1
		return Html::rawElement(
140 1
			'div',
141
			[
142 1
				'class' => 'srf-eventcalendar',
143 1
				'data-external-class' => ( $this->params['class'] ? $this->params['class'] : '' )
144
			],
145 1
			Html::element(
146 1
				'div',
147
				[
148 1
					'class' => 'srf-top'
149
				],
150 1
				''
151 1
			) . $resourceFormatter->placeholder() . Html::element(
152 1
				'div',
153
				[
154 1
					'id' => $id,
155 1
					'class' => 'srf-container',
156 1
					'style' => 'display:none;'
157
				]
158
			)
159
		);
160
	}
161
162
}
163