Completed
Push — master ( 1a7397...8cd977 )
by Daryl
04:36
created

Map_View::the_map()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
crap 1
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
		$height       = $this->_model->height();
37 1
		$width        = $this->_model->width();
38 1
		$map_id       = $this->_model->html_id();
39 1
		$map_params   = $this->_model->make_args();
40 1
		$markers      = $this->_make_markers_args();
41 1
		$info_windows = $this->_make_info_windows();
42
43 1
		require $args['template'];
44
		
45 1
	}
46
	
47
	/**
48
	 * @return array
49
	 */
50 1
	protected function _make_markers_args() {
51
52 1
		$marker_args = array();
53
54 1
		foreach ( $this->_model->markers() as $marker ) {
55 1
			$label  = $marker->label();
56
			$args = array(
57 1
				'position'  => $marker->position(),
58 1
				'title'     => $marker->title(),
59
			);
60
61 1
			if ( ! empty( $label->text() ) ) {
62 1
				$args['label'] = json_encode( array(
63 1
					'color'      => $label->color(),
64 1
					'fontFamily' => $label->font_family(),
65 1
					'fontSize'   => $label->font_size(),
66 1
					'fontWeight' => $label->font_weight(),
67 1
					'text'       => $label->text(),
68
				) );
69
			}
70
71 1
			$marker_args[] = $args;
72
		}
73
74 1
		return $marker_args;
75
76
	}
77
78
	/**
79
	 * @return array
80
	 */
81 1
	protected function _make_info_windows() {
82
83 1
		$windows = array();
84
85
		/**
86
		 * @var Marker $marker
87
		 */
88 1
		foreach( $this->_model->markers() as $marker ) {
89 1
			$info_window = $marker->info_window();
90 1
			$windows[]   = array(
91 1
				'content'      => $info_window->content(),
0 ignored issues
show
Documentation Bug introduced by
The method content does not exist on object<Clubdeuce\WPGoogleMaps\Info_Window>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
92 1
				'pixel_offset' => $info_window->pixel_offset(),
0 ignored issues
show
Documentation Bug introduced by
The method pixel_offset does not exist on object<Clubdeuce\WPGoogleMaps\Info_Window>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
93 1
				'position'     => $info_window->position(),
0 ignored issues
show
Documentation Bug introduced by
The method position does not exist on object<Clubdeuce\WPGoogleMaps\Info_Window>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
94 1
				'max_width'    => $info_window->max_width(),
0 ignored issues
show
Documentation Bug introduced by
The method max_width does not exist on object<Clubdeuce\WPGoogleMaps\Info_Window>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
95
			);
96
		}
97
98 1
		return $windows;
99
100
	}
101
	
102
}