summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/ModernTimeline/src/SlidePresenter/SimpleSlidePresenter.php
blob: 14be23e1d4fa9ea800d8c8293a289b5a60d89bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

declare( strict_types = 1 );

namespace ModernTimeline\SlidePresenter;

use ModernTimeline\ResultFacade\Subject;
use SMW\DataValueFactory;
use SMW\Query\PrintRequest;

class SimpleSlidePresenter implements SlidePresenter {

	public function getText( Subject $subject ): string {
		return implode( '<br>', iterator_to_array( $this->getDisplayValues( $subject ) ) );
	}

	private function getDisplayValues( Subject $subject ) {
		foreach ( $subject->getPropertyValueCollections() as $propertyValues ) {
			foreach ( $propertyValues->getDataItems() as $dataItem ) {
				yield $this->getDisplayValue( $propertyValues->getPrintRequest(), $dataItem );
			}
		}
	}

	private function getDisplayValue( PrintRequest $pr, \SMWDataItem $dataItem ) {
		$property = $pr->getText( null );
		$value = $this->dataItemToText( $dataItem );

		if ( $property === '' ) {
			return $value;
		}

		return $property . ': ' . $value;
	}

	private function dataItemToText( \SMWDataItem $dataItem ): string {
		return DataValueFactory::getInstance()->newDataValueByItem( $dataItem )->getLongHTMLText();
	}

}