Completed
Push — master ( 81538e...c2bf57 )
by Jeroen De
10:06
created

GeoJsonMapPageUi   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 75
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A forExistingPage() 0 3 1
A __construct() 0 3 1
A addToOutput() 0 11 1
A getJavascript() 0 7 1
A getJsonJs() 0 5 1
A getHtml() 0 19 1
A wrapHtmlInThumbDivs() 0 15 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\GeoJsonPages;
6
7
use Html;
8
use Maps\Presentation\OutputFacade;
9
10
class GeoJsonMapPageUi {
11
12
	private $json;
13
14
	public static function forExistingPage( string $mapJson ): self {
15
		return new self( $mapJson );
16
	}
17
18
	private function __construct( ?string $json ) {
19
		$this->json = $json;
20
	}
21
22
	public function addToOutput( OutputFacade $output ) {
23
		$leafletPath = $GLOBALS['wgScriptPath'] . '/extensions/Maps/resources/lib/leaflet';
24
25
		$output->addHeadItem(
26
			'MapsGeoJsonHeadItem',
27
			Html::linkedStyle( "$leafletPath/leaflet.css" )
28
		);
29
30
		$output->addHTML( $this->getJavascript() . $this->getHtml() );
31
		$output->addModules( 'ext.maps.geojson.page' );
32
	}
33
34
	private function getJavascript(): string {
35
		return Html::element(
36
			'script',
37
			[],
38
			$this->getJsonJs()
39
		);
40
	}
41
42
	private function getJsonJs(): string {
43
		return 'var GeoJson ='
44
			. $this->json
45
			. ';';
46
	}
47
48
	private function getHtml(): string {
49
		return $this->wrapHtmlInThumbDivs(
50
			Html::rawElement(
51
				'div',
52
				[
53
					'id' => 'GeoJsonMap',
54
					'style' => 'width: 100%; height: 600px; background-color: #eeeeee; overflow: hidden;',
55
					'class' => 'maps-map maps-leaflet maps-geojson-editor'
56
				],
57
				Html::element(
58
					'div',
59
					[
60
						'class' => 'maps-loading-message'
61
					],
62
					wfMessage( 'maps-loading-map' )->inContentLanguage()->text()
63
				)
64
			)
65
		);
66
	}
67
68
	private function wrapHtmlInThumbDivs( string $html ): string {
69
		return Html::rawElement(
70
			'div',
71
			[
72
				'class' => 'thumb'
73
			],
74
			Html::rawElement(
75
				'div',
76
				[
77
					'class' => 'thumbinner'
78
				],
79
				$html
80
			)
81
		);
82
	}
83
84
}
85