Completed
Push — newparam ( 72433c...c5fad3 )
by Jeroen De
01:21
created

GeoJsonMapPageUi   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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