summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticResultFormats/formats/slideshow/SRF_SlideShow.php
blob: 6c62aba8143f2b76a9083b31eb4c283bd8b18dd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
 * File holding the SRF_SlideShow class
 *
 * @author Stephan Gambke
 * @file
 * @ingroup SemanticResultFormats
 */

/**
 * The SRF_SlideShow class.
 *
 * @ingroup SemanticResultFormats
 */
class SRFSlideShow extends SMWResultPrinter {

	/**
	 * Get a human readable label for this printer.
	 *
	 * @return string
	 */
	public function getName() {
		return wfMessage( 'srf-printername-slideshow' )->text();
	}

	/**
	 * Return serialised results in specified format.
	 * Implemented by subclasses.
	 */
	protected function getResultText( SMWQueryResult $res, $outputmode ) {

		$html = '';
		$id = uniqid();

		// build an array of article IDs contained in the result set
		$objects = [];
		foreach ( $res->getResults() as $key => $object ) {

			$objects[] = [ $object->getTitle()->getArticleId() ];

			$html .= $key . ': ' . $object->getSerialization() . "<br>\n";
		}

		// build an array of data about the printrequests
		$printrequests = [];
		foreach ( $res->getPrintRequests() as $key => $printrequest ) {
			$data = $printrequest->getData();
			if ( $data instanceof SMWPropertyValue ) {
				$name = $data->getDataItem()->getKey();
			} else {
				$name = null;
			}
			$printrequests[] = [
				$printrequest->getMode(),
				$printrequest->getLabel(),
				$name,
				$printrequest->getOutputFormat(),
				$printrequest->getParameters(),
			];

		}

		// write out results and query params into JS arrays
		// Define the srf_filtered_values array
		SMWOutputs::requireScript(
			'srf_slideshow',
			Html::inlineScript(
				'srf_slideshow = {};'
			)
		);

		SMWOutputs::requireScript(
			'srf_slideshow' . $id,
			Html::inlineScript(
				'srf_slideshow["' . $id . '"] = ' . json_encode(
					[
						$objects,
						$this->params['template'],
						$this->params['delay'] * 1000,
						$this->params['height'],
						$this->params['width'],
						$this->params['nav controls'],
						$this->params['effect'],
						json_encode( $printrequests ),
					]
				) . ';'
			)
		);

		SMWOutputs::requireResource( 'ext.srf.slideshow' );

		if ( $this->params['nav controls'] ) {
			SMWOutputs::requireResource( 'jquery.ui.slider' );
		}

		return Html::element(
			'div',
			[
				'id' => $id,
				'class' => 'srf-slideshow ' . $id . ' ' . $this->params['class']
			]
		);
	}

	/**
	 * Check whether a "further results" link would normally be generated for this
	 * result set with the given parameters.
	 *
	 * @param SMWQueryResult $results
	 *
	 * @return boolean
	 */
	protected function linkFurtherResults( SMWQueryResult $results ) {
		return false;
	}

	/**
	 * @see SMWResultPrinter::getParamDefinitions
	 *
	 * @since 1.8
	 *
	 * @param $definitions array of IParamDefinition
	 *
	 * @return array of IParamDefinition|array
	 */
	public function getParamDefinitions( array $definitions ) {
		$params = parent::getParamDefinitions( $definitions );

		$params['template'] = [
			'default' => '',
			'message' => 'smw_paramdesc_template',
		];

		// TODO: Implement named args
//		$params['named args'] = new Parameter( 'named args', Parameter::TYPE_BOOLEAN, false );
//		$params['named args']->setMessage( 'smw_paramdesc_named_args' );

		$params['class'] = [
			'default' => '',
			'message' => 'srf-paramdesc-class',
		];

		$params['height'] = [
			'default' => '100px',
			'message' => 'srf-paramdesc-height',
		];

		$params['width'] = [
			'default' => '200px',
			'message' => 'srf-paramdesc-width',
		];

		$params['delay'] = [
			'type' => 'integer',
			'default' => 5,
			'message' => 'srf-paramdesc-delay',
		];

		$params['nav controls'] = [
			'type' => 'boolean',
			'default' => false,
			'message' => 'srf-paramdesc-navigation-controls',
		];

		$params['effect'] = [
			'default' => 'none',
			'message' => 'srf-paramdesc-effect',
			'values' => [
				'none',
				'slide left',
				'slide right',
				'slide up',
				'slide down',
				'fade',
				'hide',
			],
		];

		return $params;
	}

}