|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace ModernTimeline\SlidePresenter; |
|
6
|
|
|
|
|
7
|
|
|
use ModernTimeline\ResultFacade\PropertyValueCollection; |
|
8
|
|
|
use ModernTimeline\ResultFacade\Subject; |
|
9
|
|
|
use SMW\DataValueFactory; |
|
10
|
|
|
|
|
11
|
|
|
class TemplateSlidePresenter implements SlidePresenter { |
|
12
|
|
|
|
|
13
|
|
|
private $templateName; |
|
14
|
|
|
|
|
15
|
1 |
|
public function __construct( string $templateName ) { |
|
16
|
1 |
|
$this->templateName = $templateName; |
|
17
|
1 |
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function getText( Subject $subject ): string { |
|
20
|
|
|
$parser = $this->getParser(); |
|
21
|
|
|
|
|
22
|
|
|
return $parser->recursiveTagParseFully( |
|
23
|
|
|
( new TemplateSlidePresenter( $this->templateName ) )->getTemplateText( $subject ) |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
private function getParser(): \Parser { |
|
28
|
|
|
return $GLOBALS['wgParser']; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
public function getTemplateText( Subject $subject ): string { |
|
32
|
1 |
|
return '{{' . implode( '|', $this->getTemplateSegments( $subject ) ) . '}}'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
private function getTemplateSegments( Subject $subject ): array { |
|
36
|
1 |
|
return array_merge( |
|
37
|
|
|
[ |
|
38
|
1 |
|
$this->templateName, |
|
39
|
1 |
|
$this->parameter( 'title', $subject->getWikiPage()->getTitle()->getFullText() ) |
|
40
|
|
|
], |
|
41
|
1 |
|
array_map( |
|
42
|
1 |
|
function( PropertyValueCollection $pvc ) { |
|
43
|
1 |
|
return $this->parameter( |
|
44
|
1 |
|
$pvc->getPrintRequest()->getText( null ) ?? '', |
|
45
|
1 |
|
$pvc->getDataItems() === [] ? '' : $this->dataItemToText( $pvc->getDataItems()[0] ) |
|
46
|
|
|
); |
|
47
|
1 |
|
}, |
|
48
|
1 |
|
$subject->getPropertyValueCollections() |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
private function dataItemToText( \SMWDataItem $dataItem ): string { |
|
54
|
1 |
|
return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
private function parameter( string $name, string $value ): string { |
|
58
|
1 |
|
return $name . '=' . $value; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|