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
|
|
|
public function __construct( string $templateName ) { |
16
|
|
|
$this->templateName = $templateName; |
17
|
|
|
} |
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
|
|
|
public function getTemplateText( Subject $subject ): string { |
32
|
|
|
return '{{' . implode( '|', $this->getTemplateSegments( $subject ) ) . '}}'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
private function getTemplateSegments( Subject $subject ): array { |
36
|
|
|
return array_merge( |
37
|
|
|
[ |
38
|
|
|
$this->templateName, |
39
|
|
|
$this->parameter( 'title', $subject->getWikiPage()->getTitle()->getFullText() ) |
40
|
|
|
], |
41
|
|
|
array_map( |
42
|
|
|
function( PropertyValueCollection $pvc ) { |
43
|
|
|
return $this->parameter( |
44
|
|
|
$pvc->getPrintRequest()->getText( null ) ?? '', |
45
|
|
|
$pvc->getDataItems() === [] ? '' : $this->dataItemToText( $pvc->getDataItems()[0] ) |
46
|
|
|
); |
47
|
|
|
}, |
48
|
|
|
$subject->getPropertyValueCollections()->toArray() |
49
|
|
|
) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function dataItemToText( \SMWDataItem $dataItem ): string { |
54
|
|
|
return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function parameter( string $name, string $value ): string { |
58
|
|
|
return $name . '=' . $value; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|