Completed
Push — master ( 6dc7d8...407c40 )
by Karsten
15:45
created

formats/slideshow/SRF_SlideShow.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * File holding the SRF_SlideShow class
4
 *
5
 * @author Stephan Gambke
6
 * @file
7
 * @ingroup SemanticResultFormats
8
 */
9
10
/**
11
 * The SRF_SlideShow class.
12
 *
13
 * @ingroup SemanticResultFormats
14
 */
15
class SRFSlideShow extends SMWResultPrinter {
16
17
	/**
18
	 * Get a human readable label for this printer.
19
	 *
20
	 * @return string
21
	 */
22
	public function getName() {
23
		return wfMessage( 'srf-printername-slideshow' )->text();
24
	}
25
26
	/**
27
	 * Return serialised results in specified format.
28
	 * Implemented by subclasses.
29
	 */
30
	protected function getResultText( SMWQueryResult $res, $outputmode ) {
31
32
		$html = '';
33
		$id = uniqid();
34
35
		// build an array of article IDs contained in the result set
36
		$objects = [];
37
		foreach ( $res->getResults() as $key => $object ) {
38
39
			$objects[] = [ $object->getTitle()->getArticleId() ];
40
41
			$html .= $key . ': ' . $object->getSerialization() . "<br>\n";
42
		}
43
44
		// build an array of data about the printrequests
45
		$printrequests = [];
46
		foreach ( $res->getPrintRequests() as $key => $printrequest ) {
47
			$data = $printrequest->getData();
48
			if ( $data instanceof SMWPropertyValue ) {
0 ignored issues
show
The class SMWPropertyValue does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
49
				$name = $data->getDataItem()->getKey();
50
			} else {
51
				$name = null;
52
			}
53
			$printrequests[] = [
54
				$printrequest->getMode(),
55
				$printrequest->getLabel(),
56
				$name,
57
				$printrequest->getOutputFormat(),
58
				$printrequest->getParameters(),
59
			];
60
61
		}
62
63
		// write out results and query params into JS arrays
64
		// Define the srf_filtered_values array
65
		SMWOutputs::requireScript(
66
			'srf_slideshow',
67
			Html::inlineScript(
68
				'srf_slideshow = {};'
69
			)
70
		);
71
72
		SMWOutputs::requireScript(
73
			'srf_slideshow' . $id,
74
			Html::inlineScript(
75
				'srf_slideshow["' . $id . '"] = ' . json_encode(
76
					[
77
						$objects,
78
						$this->params['template'],
79
						$this->params['delay'] * 1000,
80
						$this->params['height'],
81
						$this->params['width'],
82
						$this->params['nav controls'],
83
						$this->params['effect'],
84
						json_encode( $printrequests ),
85
					]
86
				) . ';'
87
			)
88
		);
89
90
		SMWOutputs::requireResource( 'ext.srf.slideshow' );
91
92
		if ( $this->params['nav controls'] ) {
93
			SMWOutputs::requireResource( 'jquery.ui.slider' );
94
		}
95
96
		return Html::element(
97
			'div',
98
			[
99
				'id' => $id,
100
				'class' => 'srf-slideshow ' . $id . ' ' . $this->params['class']
101
			]
102
		);
103
	}
104
105
	/**
106
	 * Check whether a "further results" link would normally be generated for this
107
	 * result set with the given parameters.
108
	 *
109
	 * @param SMWQueryResult $results
110
	 *
111
	 * @return boolean
112
	 */
113
	protected function linkFurtherResults( SMWQueryResult $results ) {
114
		return false;
115
	}
116
117
	/**
118
	 * @see SMWResultPrinter::getParamDefinitions
119
	 *
120
	 * @since 1.8
121
	 *
122
	 * @param $definitions array of IParamDefinition
123
	 *
124
	 * @return array of IParamDefinition|array
125
	 */
126
	public function getParamDefinitions( array $definitions ) {
127
		$params = parent::getParamDefinitions( $definitions );
128
129
		$params['template'] = [
130
			'default' => '',
131
			'message' => 'smw_paramdesc_template',
132
		];
133
134
		// TODO: Implement named args
135
//		$params['named args'] = new Parameter( 'named args', Parameter::TYPE_BOOLEAN, false );
136
//		$params['named args']->setMessage( 'smw_paramdesc_named_args' );
137
138
		$params['class'] = [
139
			'default' => '',
140
			'message' => 'srf-paramdesc-class',
141
		];
142
143
		$params['height'] = [
144
			'default' => '100px',
145
			'message' => 'srf-paramdesc-height',
146
		];
147
148
		$params['width'] = [
149
			'default' => '200px',
150
			'message' => 'srf-paramdesc-width',
151
		];
152
153
		$params['delay'] = [
154
			'type' => 'integer',
155
			'default' => 5,
156
			'message' => 'srf-paramdesc-delay',
157
		];
158
159
		$params['nav controls'] = [
160
			'type' => 'boolean',
161
			'default' => false,
162
			'message' => 'srf-paramdesc-navigation-controls',
163
		];
164
165
		$params['effect'] = [
166
			'default' => 'none',
167
			'message' => 'srf-paramdesc-effect',
168
			'values' => [
169
				'none',
170
				'slide left',
171
				'slide right',
172
				'slide up',
173
				'slide down',
174
				'fade',
175
				'hide',
176
			],
177
		];
178
179
		return $params;
180
	}
181
182
}
183