|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SRF; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\ResultPrinter; |
|
6
|
|
|
use SMWQueryResult as QueryResult; |
|
7
|
|
|
use Html; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* DataTables and SMWAPI. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 1.9 |
|
13
|
|
|
* @licence GNU GPL v2 or later |
|
14
|
|
|
* |
|
15
|
|
|
* @author mwjames |
|
16
|
|
|
*/ |
|
17
|
|
|
class DataTables extends ResultPrinter { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @see ResultPrinter::getName |
|
21
|
|
|
* |
|
22
|
|
|
* {@inheritDoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getName() { |
|
25
|
|
|
return $this->msg( 'srf-printername-datatables' )->text(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @see ResultPrinter::getParamDefinitions |
|
30
|
|
|
* |
|
31
|
|
|
* @since 1.8 |
|
32
|
|
|
* |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getParamDefinitions( array $definitions ) { |
|
36
|
|
|
$params = parent::getParamDefinitions( $definitions ); |
|
37
|
|
|
|
|
38
|
|
|
$params['class'] = [ |
|
39
|
|
|
'message' => 'srf-paramdesc-class', |
|
40
|
|
|
'default' => '', |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
$params['theme'] = [ |
|
44
|
|
|
'message' => 'srf-paramdesc-theme', |
|
45
|
|
|
'default' => 'bootstrap', |
|
46
|
|
|
'values' => [ 'bootstrap' ] // feel free to add more designs |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
return $params; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @see ResultPrinter::getResultText |
|
54
|
|
|
* |
|
55
|
|
|
* {@inheritDoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getResultText( QueryResult $res, $outputmode ) { |
|
58
|
|
|
|
|
59
|
|
|
$resourceFormatter = new ResourceFormatter(); |
|
60
|
|
|
$data = $resourceFormatter->getData( $res, $outputmode, $this->params ); |
|
61
|
|
|
|
|
62
|
|
|
$this->isHTML = true; |
|
63
|
|
|
$id = $resourceFormatter->session(); |
|
64
|
|
|
|
|
65
|
|
|
// Add options |
|
66
|
|
|
$data['version'] = '0.2.5'; |
|
67
|
|
|
|
|
68
|
|
|
// Encode data object |
|
69
|
|
|
$resourceFormatter->encode( $id, $data ); |
|
70
|
|
|
|
|
71
|
|
|
// Init RL module |
|
72
|
|
|
$resourceFormatter->registerResources( [ 'ext.srf.datatables' ] ); |
|
73
|
|
|
|
|
74
|
|
|
// Element includes info, spinner, and container placeholder |
|
75
|
|
|
return Html::rawElement( |
|
76
|
|
|
'div', |
|
77
|
|
|
[ |
|
78
|
|
|
'class' => 'srf-datatables' . ( $this->params['class'] ? ' ' . $this->params['class'] : '' ), |
|
79
|
|
|
'data-theme' => $this->params['theme'], |
|
80
|
|
|
], |
|
81
|
|
|
Html::element( |
|
82
|
|
|
'div', |
|
83
|
|
|
[ |
|
84
|
|
|
'class' => 'top' |
|
85
|
|
|
], |
|
86
|
|
|
'' |
|
87
|
|
|
) . $resourceFormatter->placeholder() . Html::element( |
|
88
|
|
|
'div', |
|
89
|
|
|
[ |
|
90
|
|
|
'id' => $id, |
|
91
|
|
|
'class' => 'container', |
|
92
|
|
|
'style' => 'display:none;' |
|
93
|
|
|
] |
|
94
|
|
|
) |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|