|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SRF\Outline; |
|
4
|
|
|
|
|
5
|
|
|
use SMWResultPrinter as ResultPrinter; |
|
6
|
|
|
use SMWQueryResult as QueryResult; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* A class to print query results in an outline format, along with some |
|
10
|
|
|
* helper classes to handle the aggregation |
|
11
|
|
|
* |
|
12
|
|
|
* @license GNU GPL v2+ |
|
13
|
|
|
* @since 1.4.3 |
|
14
|
|
|
* |
|
15
|
|
|
* @author Yaron Koren |
|
16
|
|
|
*/ |
|
17
|
|
|
class OutlineResultPrinter extends ResultPrinter { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @see ResultPrinter::getName |
|
21
|
|
|
* |
|
22
|
|
|
* {@inheritDoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function getName() { |
|
25
|
|
|
return wfMessage( 'srf_printername_outline' )->text(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @see SMWResultPrinter::getParamDefinitions |
|
30
|
|
|
* |
|
31
|
|
|
* @since 1.8 |
|
32
|
|
|
* |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
2 |
|
public function getParamDefinitions( array $definitions ) { |
|
36
|
2 |
|
$params = parent::getParamDefinitions( $definitions ); |
|
37
|
|
|
|
|
38
|
2 |
|
$params['outlineproperties'] = [ |
|
39
|
|
|
'islist' => true, |
|
40
|
|
|
'default' => [], |
|
41
|
|
|
'message' => 'srf_paramdesc_outlineproperties', |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
2 |
|
$params[] = [ |
|
45
|
|
|
'name' => 'template', |
|
46
|
|
|
'message' => 'smw-paramdesc-template', |
|
47
|
|
|
'default' => '', |
|
48
|
|
|
]; |
|
49
|
|
|
|
|
50
|
2 |
|
$params[] = [ |
|
51
|
|
|
'name' => 'userparam', |
|
52
|
|
|
'message' => 'smw-paramdesc-userparam', |
|
53
|
|
|
'default' => '', |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
2 |
|
$params[] = [ |
|
57
|
|
|
'name' => 'named args', |
|
58
|
|
|
'type' => 'boolean', |
|
59
|
|
|
'message' => 'smw-paramdesc-named_args', |
|
60
|
|
|
'default' => true, |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
2 |
|
return $params; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @see ResultPrinter::getResultText |
|
68
|
|
|
* |
|
69
|
|
|
* {@inheritDoc} |
|
70
|
|
|
*/ |
|
71
|
3 |
|
protected function getResultText( QueryResult $res, $outputMode ) { |
|
72
|
|
|
|
|
73
|
|
|
// for each result row, create an array of the row itself |
|
74
|
|
|
// and all its sorted-on fields, and add it to the initial |
|
75
|
|
|
// 'tree' |
|
76
|
3 |
|
$outlineTree = new OutlineTree(); |
|
77
|
|
|
|
|
78
|
3 |
|
while ( $row = $res->getNext() ) { |
|
79
|
2 |
|
$outlineTree->addItem( $this->newOutlineItem( $row ) ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// now, cycle through the outline properties, creating the |
|
83
|
|
|
// tree |
|
84
|
3 |
|
foreach ( $this->params['outlineproperties'] as $property ) { |
|
85
|
2 |
|
$outlineTree->addProperty( $property ); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
3 |
|
if ( $this->params['template'] !== '' ) { |
|
89
|
1 |
|
$this->hasTemplates = true; |
|
90
|
1 |
|
$templateBuilder = new TemplateBuilder( |
|
91
|
1 |
|
$this->params |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
1 |
|
$templateBuilder->setLinker( $this->mLinker ); |
|
95
|
1 |
|
$result = $templateBuilder->build( $outlineTree ); |
|
96
|
|
|
} else { |
|
97
|
2 |
|
$listTreeBuilder = new ListTreeBuilder( |
|
98
|
2 |
|
$this->params + [ 'showHeaders' => $this->mShowHeaders ] |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
2 |
|
$listTreeBuilder->setLinker( $this->mLinker ); |
|
102
|
2 |
|
$result = $listTreeBuilder->build( $outlineTree ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
3 |
|
if ( $this->linkFurtherResults( $res ) ) { |
|
106
|
|
|
$link = $this->getFurtherResultsLink( |
|
107
|
|
|
$res, |
|
108
|
|
|
$outputMode |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$result .= $link->getText( $outputMode, $this->mLinker ) . "\n"; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
3 |
|
return $result; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
private function newOutlineItem( $row ) { |
|
118
|
|
|
|
|
119
|
2 |
|
$outlineItem = new OutlineItem( $row ); |
|
120
|
|
|
|
|
121
|
2 |
|
foreach ( $row as $field ) { |
|
122
|
2 |
|
$name = $field->getPrintRequest()->getText( SMW_OUTPUT_HTML ); |
|
123
|
|
|
|
|
124
|
2 |
|
if ( !in_array( $name, $this->params['outlineproperties'] ) ) { |
|
125
|
2 |
|
continue; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
2 |
|
while ( ( $dataValue = $field->getNextDataValue() ) !== false ) { |
|
129
|
2 |
|
$outlineItem->addFieldValue( |
|
130
|
2 |
|
$name, |
|
131
|
2 |
|
$dataValue->getLongWikiText( $this->getLinker() ) |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
2 |
|
return $outlineItem; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|