1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace ModernTimeline; |
6
|
|
|
|
7
|
|
|
use ModernTimeline\ResultFacade\ResultFormat; |
8
|
|
|
use ModernTimeline\ResultFacade\ResultSimplifier; |
9
|
|
|
use ModernTimeline\ResultFacade\ResultFormatRegistry; |
10
|
|
|
use ModernTimeline\ResultFacade\SimpleQueryResult; |
11
|
|
|
use ModernTimeline\ResultFacade\SubjectCollection; |
12
|
|
|
use ParamProcessor\Param; |
13
|
|
|
use ParamProcessor\ProcessedParam; |
14
|
|
|
use ParamProcessor\ProcessingResult; |
15
|
|
|
use SMW\Parser\RecursiveTextProcessor; |
16
|
|
|
use SMW\Query\ResultPrinter; |
17
|
|
|
use SMWQuery; |
18
|
|
|
use SMWQueryResult; |
19
|
|
|
|
20
|
|
|
class ModernTimelinePrinter implements ResultPrinter { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var ResultFormat |
24
|
|
|
*/ |
25
|
|
|
private $format; |
26
|
|
|
|
27
|
5 |
|
public function __construct() { |
28
|
5 |
|
$registry = new ResultFormatRegistry(); |
29
|
|
|
|
30
|
5 |
|
$registry->newFormat() |
31
|
5 |
|
->withName( 'moderntimeline' ) |
32
|
5 |
|
->andMessageKey( 'modern-timeline-format-name' ) |
33
|
5 |
|
->andParameterDefinitions( TimelineOptions::getTimelineParameterDefinitions() ) |
34
|
5 |
|
->andPresenterBuilder( function() { |
35
|
4 |
|
return new TimelinePresenter(); |
36
|
5 |
|
} ) |
37
|
5 |
|
->register(); |
38
|
|
|
|
39
|
5 |
|
$this->format = $registry->getFormatByName( 'moderntimeline' ); |
40
|
5 |
|
} |
41
|
|
|
|
42
|
|
|
public function getName(): string { |
43
|
|
|
return wfMessage( $this->format->getNameMessageKey() )->text(); |
44
|
|
|
} |
45
|
|
|
|
46
|
5 |
|
public function getParamDefinitions( array $definitions ) { |
47
|
5 |
|
return array_merge( $definitions, $this->format->getParameterDefinitions() ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param SMWQueryResult $result |
52
|
|
|
* @param Param[] $parameters |
53
|
|
|
* @param int $outputMode |
54
|
|
|
* |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
4 |
|
public function getResult( SMWQueryResult $result, array $parameters, $outputMode ): string { |
58
|
4 |
|
return $this->format->buildPresenter()->presentResult( |
59
|
4 |
|
new SimpleQueryResult( |
60
|
4 |
|
$this->simplifyResult( $result ), |
61
|
4 |
|
$this->newProcessingResultFromParams( $parameters ) |
62
|
|
|
) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
4 |
|
private function simplifyResult( SMWQueryResult $result ): SubjectCollection { |
67
|
4 |
|
return ( new ResultSimplifier() )->newSubjectCollection( $result ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* This is code copied over from ParamProcessor to go from the deprecated Param[] to ProcessingResult. |
72
|
|
|
* Once the main ResultPrinter interface has been migrated away from Param this can be removed. |
73
|
|
|
*/ |
74
|
4 |
|
private function newProcessingResultFromParams( array $params ): ProcessingResult { |
75
|
4 |
|
$parameters = []; |
76
|
|
|
|
77
|
4 |
|
foreach ( $params as $param ) { |
78
|
4 |
|
$processedParam = new ProcessedParam( |
79
|
4 |
|
$param->getName(), |
80
|
4 |
|
$param->getValue(), |
81
|
4 |
|
$param->wasSetToDefault() |
82
|
|
|
); |
83
|
|
|
|
84
|
4 |
|
if ( !$param->wasSetToDefault() ) { |
85
|
4 |
|
$processedParam->setOriginalName( $param->getOriginalName() ); |
86
|
4 |
|
$processedParam->setOriginalValue( $param->getOriginalValue() ); |
87
|
|
|
} |
88
|
|
|
|
89
|
4 |
|
$parameters[$processedParam->getName()] = $processedParam; |
90
|
|
|
} |
91
|
|
|
|
92
|
4 |
|
return new ProcessingResult( |
93
|
4 |
|
$parameters, |
94
|
4 |
|
[] |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
4 |
|
public function getQueryMode( $context ): int { |
99
|
4 |
|
return SMWQuery::MODE_INSTANCES; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function setShowErrors( $show ) { |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function isExportFormat(): bool { |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
|
109
|
4 |
|
public function getDefaultSort(): string { |
110
|
4 |
|
return 'ASC'; |
111
|
|
|
} |
112
|
|
|
|
113
|
4 |
|
public function isDeferrable(): bool { |
114
|
4 |
|
return false; |
115
|
|
|
} |
116
|
|
|
|
117
|
1 |
|
public function supportsRecursiveAnnotation(): bool { |
118
|
1 |
|
return false; |
119
|
|
|
} |
120
|
|
|
|
121
|
5 |
|
public function setRecursiveTextProcessor( RecursiveTextProcessor $recursiveTextProcessor ) { |
122
|
5 |
|
} |
123
|
|
|
} |
124
|
|
|
|