Completed
Push — master ( 564666...efaf30 )
by Jeroen De
03:01
created

GeoJsonPage::addToOutputPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Presentation;
6
7
use Html;
8
9
class GeoJsonPage {
10
11
	private $json;
12
13
	public function __construct( string $json ) {
14
		$this->json = $json;
15
	}
16
17
	public function addToParserOutput( \ParserOutput $parserOutput ) {
18
		$parserOutput->setText( $this->getMapHtml() );
19
		$parserOutput->addModules( 'ext.maps.leaflet.editor' );
20
	}
21
22
	public function addToOutputPage( \OutputPage $output ) {
23
		$output->addHTML( $this->getMapHtml() );
24
		$output->addModules( 'ext.maps.leaflet.editor' );
25
	}
26
27
	private function getMapHtml(): string {
28
		return
29
			Html::element(
30
				'script',
31
				[],
32
				'var GeoJson =' . $this->json . ';'
33
			)
34
			. $this->wrapHtmlInThumbDivs(
35
				Html::rawElement(
36
					'div',
37
					[
38
						'id' => 'GeoJsonMap',
39
						'style' => "width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;",
40
						'class' => 'maps-map maps-leaflet maps-geojson-editor'
41
					],
42
					Html::element(
43
						'div',
44
						[
45
							'class' => 'maps-loading-message'
46
						],
47
						wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
48
					)
49
				)
50
			);
51
	}
52
53
	private function wrapHtmlInThumbDivs( string $html ): string {
54
		return Html::rawElement(
55
			'div',
56
			[
57
				'class' => 'thumb'
58
			],
59
			Html::rawElement(
60
				'div',
61
				[
62
					'class' => 'thumbinner'
63
				],
64
				$html
65
			)
66
		);
67
	}
68
69
}
70