Completed
Pull Request — master (#6)
by Daryl
01:24
created

Map_View::_make_markers_args()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 15
cts 15
cp 1
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Clubdeuce\WPGoogleMaps;
4
5
/**
6
 * Class Map_View
7
 * @package Clubdeuce\WPGoogleMaps
8
 */
9
class Map_View {
10
11
	/**
12
	 * @var Map
13
	 */
14
	protected $_model;
15
16
	/**
17
	 * Map_View constructor.
18
	 *
19
	 * @param Map $model
20
	 */
21 3
	public function __construct( $model ) {
22
		
23 3
		$this->_model = $model;
24
		
25 3
	}
26
27
	/**
28
	 * @param array $args
29
	 */
30 1
	public function the_map( $args = array() ) { 
31
		
32 1
		$args = wp_parse_args( $args, array(
33 1
			'template' => Google_Maps::source_dir() . '/templates/map-view.php',
34
		) );
35
36 1
		require $args['template'];
37
		
38
	}
39
	
40
	/**
41
	 * @return array
42
	 */
43 1
	protected function _make_markers_args() {
44
45 1
		$marker_args = array();
46
47 1
		foreach ( $this->_model->markers() as $marker ) {
48 1
			$label  = $marker->label();
49
			$args = array(
50 1
				'position'  => $marker->position(),
51 1
				'title'     => $marker->title(),
52
			);
53
54 1
			if ( ! empty( $label->text() ) ) {
55 1
				$args['label'] = json_encode( array(
56 1
					'color'      => $label->color(),
57 1
					'fontFamily' => $label->font_family(),
58 1
					'fontSize'   => $label->font_size(),
59 1
					'fontWeight' => $label->font_weight(),
60 1
					'text'       => $label->text(),
61
				) );
62
			}
63
64 1
			$marker_args[] = $args;
65
		}
66
67 1
		return $marker_args;
68
69
	}
70
71
	/**
72
	 * @return array
73
	 */
74 1
	protected function _make_info_windows() {
75
76 1
		$windows = array();
77
78
		/**
79
		 * @var Marker $marker
80
		 */
81 1
		foreach( $this->_model->markers() as $marker ) {
82 1
			$info_window = $marker->info_window();
83 1
			$windows[]   = array(
84 1
				'content'      => $info_window->content(),
85 1
				'pixel_offset' => $info_window->pixel_offset(),
86 1
				'position'     => $info_window->position(),
87 1
				'max_width'    => $info_window->max_width(),
88
			);
89
		}
90
91 1
		return $windows;
92
93
	}
94
	
95
}