Completed
Pull Request — master (#384)
by Nischay
07:59
created

EventCalendar   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.29%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 121
ccs 33
cts 35
cp 0.9429
rs 10
c 0
b 0
f 0

3 Methods

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