Completed
Pull Request — master (#322)
by Stephan
01:54
created

EventCalendar::getResultText()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 40
Code Lines 21

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 8.8571
c 0
b 0
f 0
cc 2
eloc 21
nc 1
nop 2
crap 2
1
<?php
2
3
namespace SRF;
4
5
use SMW\ResultPrinter;
6
use SMWQueryResult as QueryResult;
7
use Html;
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' =>  [ 'month', 'basicweek', 'basicday', 'agendaweek', 'agendaday' ]
53
		];
54
55 1
		$params['firstday'] = [
56
			'message' => 'srf-paramdesc-calendarfirstday',
57
			'default' => 'Sunday',
58
			'values' =>  [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
59
		];
60
61 1
		$params['start'] = [
62
			'message' => 'srf-paramdesc-calendarstart',
63
			'default' => 'current',
64
			'values' =>  [ 'current', 'earliest', 'latest' ]
65
		];
66
67 1
		$params['legend'] = [
68
			'message' => 'srf-paramdesc-calendarlegend',
69
			'default' => 'none',
70
			'values' =>  [ 'none', 'top', 'bottom', 'tooltip', 'pane' ]
71
		];
72
73 1
		$params['dayview'] = [
74
			'type' => 'boolean',
75
			'message' => 'srf-paramdesc-dayview',
76
			'default' => false
77
		];
78
79 1
		$params['class'] = [
80
			'message' => 'srf-paramdesc-class',
81
			'default' => '',
82
		];
83
84 1
		$params['theme'] = [
85
			'message' => 'srf-paramdesc-theme',
86
			'default' => 'basic',
87
			'values' =>  [ 'basic', 'vector' ]
88
		];
89
90 1
		$params['clicktarget'] = [
91
			'message' => 'srf-paramdesc-clicktarget',
92
			'default' => 'none'
93
		];
94
95 1
		return $params;
96
	}
97
98
	/**
99
	 * @see ResultPrinter::getResultText
100
	 *
101
	 * {@inheritDoc}
102
	 */
103 1
	protected function getResultText( QueryResult $res, $outputmode ) {
104
105 1
		$resourceFormatter = new ResourceFormatter();
106 1
		$data = $resourceFormatter->getData( $res, $outputmode, $this->params );
107
108 1
		$this->isHTML = true;
109 1
		$id = $resourceFormatter->session();
110
111
		// Add options
112 1
		$data['version'] = '0.8.0';
113
114
		// Encode data object
115 1
		$resourceFormatter->encode( $id, $data );
116
117
		// Init RL module
118 1
		$resourceFormatter->registerResources( [ 'ext.srf.eventcalendar' ] );
119
120
		// Element includes info, spinner, and container placeholder
121 1
		return Html::rawElement(
122 1
			'div',
123
			[
124 1
				'class' => 'srf-eventcalendar',
125 1
				'data-external-class' => ( $this->params['class'] ? $this->params['class'] : '' )
126
			],
127 1
			Html::element(
128 1
				'div',
129
				[
130 1
					'class' => 'srf-top'
131
				],
132 1
				''
133 1
			) .  $resourceFormatter->placeholder() . Html::element(
134 1
				'div',
135
				[
136 1
					'id' => $id,
137 1
					'class' => 'srf-container',
138 1
					'style' => 'display:none;'
139
				]
140
			)
141
		);
142
	}
143
144
}
145