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
|
1 |
|
public function getParamDefinitions( array $definitions ) { |
36
|
1 |
|
$params = parent::getParamDefinitions( $definitions ); |
37
|
|
|
|
38
|
1 |
|
$params['class'] = [ |
39
|
|
|
'message' => 'srf-paramdesc-class', |
40
|
|
|
'default' => '', |
41
|
|
|
]; |
42
|
|
|
|
43
|
1 |
|
$params['theme'] = [ |
44
|
|
|
'message' => 'srf-paramdesc-theme', |
45
|
|
|
'default' => 'bootstrap', |
46
|
|
|
'values' => [ 'bootstrap' ] // feel free to add more designs |
47
|
|
|
]; |
48
|
|
|
|
49
|
1 |
|
return $params; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @see ResultPrinter::getResultText |
54
|
|
|
* |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
1 |
|
protected function getResultText( QueryResult $res, $outputmode ) { |
58
|
|
|
|
59
|
1 |
|
$resourceFormatter = new ResourceFormatter(); |
60
|
1 |
|
$data = $resourceFormatter->getData( $res, $outputmode, $this->params ); |
61
|
|
|
|
62
|
1 |
|
$this->isHTML = true; |
63
|
1 |
|
$id = $resourceFormatter->session(); |
64
|
|
|
|
65
|
|
|
// Add options |
66
|
1 |
|
$data['version'] = '0.2.5'; |
67
|
|
|
|
68
|
|
|
// Encode data object |
69
|
1 |
|
$resourceFormatter->encode( $id, $data ); |
70
|
|
|
|
71
|
|
|
// Init RL module |
72
|
1 |
|
$resourceFormatter->registerResources( [ 'ext.srf.datatables' ] ); |
73
|
|
|
|
74
|
|
|
// Element includes info, spinner, and container placeholder |
75
|
1 |
|
return Html::rawElement( |
76
|
1 |
|
'div', |
77
|
|
|
[ |
78
|
1 |
|
'class' => 'srf-datatables' . ( $this->params['class'] ? ' ' . $this->params['class'] : '' ), |
79
|
1 |
|
'data-theme' => $this->params['theme'], |
80
|
|
|
], |
81
|
1 |
|
Html::element( |
82
|
1 |
|
'div', |
83
|
|
|
[ |
84
|
1 |
|
'class' => 'top' |
85
|
|
|
], |
86
|
1 |
|
'' |
87
|
1 |
|
) . $resourceFormatter->placeholder() . Html::element( |
88
|
1 |
|
'div', |
89
|
|
|
[ |
90
|
1 |
|
'id' => $id, |
91
|
1 |
|
'class' => 'container', |
92
|
1 |
|
'style' => 'display:none;' |
93
|
|
|
] |
94
|
|
|
) |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|