Completed
Branch PSR2 (2b7eae)
by Gordon
02:39
created
code/MapExtension.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@
 block discarded – undo
184 184
 
185 185
 	/**
186 186
 	 * Access the map editing field for the purpose of adding guide points
187
-	 * @return [LatLongField] instance of location editing field
187
+	 * @return FormField instance of location editing field
188 188
 	 */
189 189
 	public function getMapField() {
190 190
 		if (!isset($this->mapField)) {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 		'MapPinIcon' => 'Image'
19 19
 	);
20 20
 
21
-	static $defaults = array (
21
+	static $defaults = array(
22 22
 		'Lat' =>0,
23 23
 		'Lon' => 0,
24 24
 		'Zoom' => 4,
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 		// add any KML map layers
156 156
 		if (Object::has_extension($this->owner->ClassName, 'MapLayerExtension')) {
157
-		  foreach($this->owner->MapLayers() as $layer) {
157
+		  foreach ($this->owner->MapLayers() as $layer) {
158 158
 			$map->addKML($layer->KmlFile()->getAbsoluteURL());
159 159
 			// we have a layer, so turn on autozoom
160 160
 			$autozoom = true;
Please login to merge, or discard this patch.
Indentation   +172 added lines, -173 removed lines patch added patch discarded remove patch
@@ -2,173 +2,173 @@  discard block
 block discarded – undo
2 2
 
3 3
 class MapExtension extends DataExtension implements Mappable {
4 4
 
5
-	/*
5
+    /*
6 6
 	 * Template suffix for rendering MapInfoWindow aka  map bubble
7 7
 	 */
8
-	private static $map_info_window_suffix = '_MapInfoWindow';
9
-
10
-	private static $db = array(
11
-		'Lat' => 'Decimal(18,15)',
12
-		'Lon' => 'Decimal(18,15)',
13
-		'ZoomLevel' => 'Int',
14
-		'MapPinEdited' => 'Boolean'
15
-	);
16
-
17
-	static $has_one = array(
18
-		'MapPinIcon' => 'Image'
19
-	);
20
-
21
-	static $defaults = array (
22
-		'Lat' =>0,
23
-		'Lon' => 0,
24
-		'Zoom' => 4,
25
-		'MapPinEdited' => false
26
-	);
27
-
28
-	/*
8
+    private static $map_info_window_suffix = '_MapInfoWindow';
9
+
10
+    private static $db = array(
11
+        'Lat' => 'Decimal(18,15)',
12
+        'Lon' => 'Decimal(18,15)',
13
+        'ZoomLevel' => 'Int',
14
+        'MapPinEdited' => 'Boolean'
15
+    );
16
+
17
+    static $has_one = array(
18
+        'MapPinIcon' => 'Image'
19
+    );
20
+
21
+    static $defaults = array (
22
+        'Lat' =>0,
23
+        'Lon' => 0,
24
+        'Zoom' => 4,
25
+        'MapPinEdited' => false
26
+    );
27
+
28
+    /*
29 29
 	Map editing field
30 30
 	 */
31
-	private $mapField = null;
31
+    private $mapField = null;
32 32
 
33 33
 
34
-	/*
34
+    /*
35 35
 	Add a Location tab containing the map
36 36
 	*/
37
-	public function updateCMSFields(FieldList $fields) {
38
-		// These fields need removed, as they may have already been created by the form scaffolding
39
-		$fields->removeByName('Lat');
40
-		$fields->removeByName('Lon');
41
-		$fields->removeByName('ZoomLevel');
42
-		$fields->removeByName('MapPinIcon');
43
-		$fields->removeByName('MapPinEdited');
44
-
45
-		$fields->addFieldToTab("Root.Location",
46
-			$this->getMapField()
47
-		);
48
-
49
-		$fields->addFieldToTab('Root.Location', $uf = new UploadField('MapPinIcon',
50
-			_t('Mappable.MAP_PIN', 'Map Pin Icon.  Leave this blank for default pin to show')));
51
-		$uf->setFolderName('mapicons');
52
-	}
53
-
54
-
55
-	public function getMappableLatitude() {
56
-		return $this->owner->Lat;
57
-	}
58
-
59
-	public function getMappableLongitude() {
60
-		return $this->owner->Lon;
61
-	}
62
-
63
-
64
-	/**
65
-	 * Renders the map info window for the DataObject.
66
-	 *
67
-	 * Be sure to define a template for that, named by the decorated class suffixed with _MapInfoWindow
68
-	 * e.g. MyPage_MapInfoWindow
69
-	 *
70
-	 * You can change the suffix globally by editing the MapExtension.map_info_window_suffix config val
71
-	 *
72
-	 * @return string
73
-	 */
74
-	public function getMappableMapContent() {
75
-		$defaultTemplate = 'MapInfoWindow';
76
-		$classTemplate =
77
-			SSViewer::get_templates_by_class(
78
-				$this->owner->ClassName,
79
-				Config::inst()->get('MapExtension', 'map_info_window_suffix')
80
-			);
81
-
82
-		$template = count($classTemplate) ? $classTemplate : $defaultTemplate;
83
-		return MapUtil::sanitize($this->owner->renderWith($template));
84
-	}
85
-
86
-
87
-	/*
37
+    public function updateCMSFields(FieldList $fields) {
38
+        // These fields need removed, as they may have already been created by the form scaffolding
39
+        $fields->removeByName('Lat');
40
+        $fields->removeByName('Lon');
41
+        $fields->removeByName('ZoomLevel');
42
+        $fields->removeByName('MapPinIcon');
43
+        $fields->removeByName('MapPinEdited');
44
+
45
+        $fields->addFieldToTab("Root.Location",
46
+            $this->getMapField()
47
+        );
48
+
49
+        $fields->addFieldToTab('Root.Location', $uf = new UploadField('MapPinIcon',
50
+            _t('Mappable.MAP_PIN', 'Map Pin Icon.  Leave this blank for default pin to show')));
51
+        $uf->setFolderName('mapicons');
52
+    }
53
+
54
+
55
+    public function getMappableLatitude() {
56
+        return $this->owner->Lat;
57
+    }
58
+
59
+    public function getMappableLongitude() {
60
+        return $this->owner->Lon;
61
+    }
62
+
63
+
64
+    /**
65
+     * Renders the map info window for the DataObject.
66
+     *
67
+     * Be sure to define a template for that, named by the decorated class suffixed with _MapInfoWindow
68
+     * e.g. MyPage_MapInfoWindow
69
+     *
70
+     * You can change the suffix globally by editing the MapExtension.map_info_window_suffix config val
71
+     *
72
+     * @return string
73
+     */
74
+    public function getMappableMapContent() {
75
+        $defaultTemplate = 'MapInfoWindow';
76
+        $classTemplate =
77
+            SSViewer::get_templates_by_class(
78
+                $this->owner->ClassName,
79
+                Config::inst()->get('MapExtension', 'map_info_window_suffix')
80
+            );
81
+
82
+        $template = count($classTemplate) ? $classTemplate : $defaultTemplate;
83
+        return MapUtil::sanitize($this->owner->renderWith($template));
84
+    }
85
+
86
+
87
+    /*
88 88
 	If the marker pin is not at position 0,0 mark the pin as edited. This provides the option of
89 89
 	filtering out (0,0) point which is often irrelevant for plots
90 90
 	*/
91
-	public function onBeforeWrite() {
92
-		$latzero = ($this->owner->Lat == 0);
93
-		$lonzero = ($this->owner->Lon == 0);
94
-		$latlonzero = $latzero && $lonzero;
95
-
96
-		// if both latitude and longitude still default, do not set the map location as edited
97
-		if (!$latlonzero) {
98
-		  $this->owner->MapPinEdited = true;
99
-		}
100
-	}
91
+    public function onBeforeWrite() {
92
+        $latzero = ($this->owner->Lat == 0);
93
+        $lonzero = ($this->owner->Lon == 0);
94
+        $latlonzero = $latzero && $lonzero;
95
+
96
+        // if both latitude and longitude still default, do not set the map location as edited
97
+        if (!$latlonzero) {
98
+            $this->owner->MapPinEdited = true;
99
+        }
100
+    }
101 101
 
102 102
 
103
-	/*
103
+    /*
104 104
 	If a user has uploaded a map pin icon display that, otherwise
105 105
 	*/
106
-	public function getMappableMapPin() {
107
-		$result = false;
108
-		if ($this->owner->MapPinIconID != 0) {
109
-			$mapPin = $this->owner->MapPinIcon();
110
-			$result = $mapPin->getAbsoluteURL();
111
-		} else {
112
-		  // check for a cached map pin already having been provided for the layer
113
-			if ($this->owner->CachedMapPinURL) {
114
-				$result = $this->owner->CachedMapPinURL;
115
-		  	}
116
-		}
117
-		return $result;
118
-	}
119
-
120
-
121
-	/*
106
+    public function getMappableMapPin() {
107
+        $result = false;
108
+        if ($this->owner->MapPinIconID != 0) {
109
+            $mapPin = $this->owner->MapPinIcon();
110
+            $result = $mapPin->getAbsoluteURL();
111
+        } else {
112
+            // check for a cached map pin already having been provided for the layer
113
+            if ($this->owner->CachedMapPinURL) {
114
+                $result = $this->owner->CachedMapPinURL;
115
+                }
116
+        }
117
+        return $result;
118
+    }
119
+
120
+
121
+    /*
122 122
 		Check for non zero coordinates, on the assumption that (0,0) will never be the desired coordinates
123 123
 	*/
124
-	public function HasGeo() {
125
-		$isOrigin = ($this->owner->Lat == 0) && ($this->owner->Lon == 0);
126
-		$result = !$isOrigin;
127
-		if ($this->owner->hasExtension('MapLayerExtension')) {
128
-			if ($this->owner->MapLayers()->count() > 0) {
129
-				$result = true;
130
-			}
131
-		}
132
-
133
-
134
-		$this->owner->extend('updateHasGeo', $result);
135
-		/**
136
-		 * FIXME - move this to PointsOfInterest module
124
+    public function HasGeo() {
125
+        $isOrigin = ($this->owner->Lat == 0) && ($this->owner->Lon == 0);
126
+        $result = !$isOrigin;
127
+        if ($this->owner->hasExtension('MapLayerExtension')) {
128
+            if ($this->owner->MapLayers()->count() > 0) {
129
+                $result = true;
130
+            }
131
+        }
132
+
133
+
134
+        $this->owner->extend('updateHasGeo', $result);
135
+        /**
136
+         * FIXME - move this to PointsOfInterest module
137 137
 		if ($this->owner->hasExtension('PointsOfInterestLayerExtension')) {
138 138
 			if ($this->owner->PointsOfInterestLayers()->count() > 0) {
139 139
 				$result = true;
140 140
 			}
141 141
 		}
142
-		 */
142
+         */
143 143
 
144
-		return $result;
145
-	}
144
+        return $result;
145
+    }
146 146
 
147 147
 
148
-	/*
148
+    /*
149 149
 	Render a map at the provided lat,lon, zoom from the editing functions,
150 150
 	*/
151
-	public function BasicMap() {
152
-		$map = $this->owner->getRenderableMap()->
153
-			setZoom($this->owner->ZoomLevel)->
154
-			setAdditionalCSSClasses('fullWidthMap')->
155
-			setShowInlineMapDivStyle(true);
156
-
157
-		$autozoom = false;
158
-
159
-		// add any KML map layers
160
-		if (Object::has_extension($this->owner->ClassName, 'MapLayerExtension')) {
161
-		  foreach($this->owner->MapLayers() as $layer) {
162
-			$map->addKML($layer->KmlFile()->getAbsoluteURL());
163
-			// we have a layer, so turn on autozoom
164
-			$autozoom = true;
165
-		  }
166
-			$map->setEnableAutomaticCenterZoom(true);
167
-		}
168
-
169
-		$this->owner->extend('updateBasicMap', $map);
170
-
171
-		/**
151
+    public function BasicMap() {
152
+        $map = $this->owner->getRenderableMap()->
153
+            setZoom($this->owner->ZoomLevel)->
154
+            setAdditionalCSSClasses('fullWidthMap')->
155
+            setShowInlineMapDivStyle(true);
156
+
157
+        $autozoom = false;
158
+
159
+        // add any KML map layers
160
+        if (Object::has_extension($this->owner->ClassName, 'MapLayerExtension')) {
161
+            foreach($this->owner->MapLayers() as $layer) {
162
+            $map->addKML($layer->KmlFile()->getAbsoluteURL());
163
+            // we have a layer, so turn on autozoom
164
+            $autozoom = true;
165
+            }
166
+            $map->setEnableAutomaticCenterZoom(true);
167
+        }
168
+
169
+        $this->owner->extend('updateBasicMap', $map);
170
+
171
+        /**
172 172
 		FIXME - move to POI module
173 173
 		if (Object::has_extension($this->owner->ClassName, 'PointsOfInterestLayerExtension')) {
174 174
 			foreach($this->owner->PointsOfInterestLayers() as $layer) {
@@ -190,37 +190,36 @@  discard block
 block discarded – undo
190 190
 			}
191 191
 			$map->setClusterer(true);
192 192
 		}
193
-
194
-		**/
195
-
196
-		$map->setEnableAutomaticCenterZoom($autozoom);
197
-		$map->setShowInlineMapDivStyle(true);
198
-
199
-		return $map;
200
-	}
201
-
202
-
203
-	/**
204
-	 * Access the map editing field for the purpose of adding guide points
205
-	 * @return [LatLongField] instance of location editing field
206
-	 */
207
-	public function getMapField() {
208
-		if (!isset($this->mapField)) {
209
-			$this->mapField = new LatLongField(array(
210
-				new TextField('Lat', 'Latitude'),
211
-				new TextField('Lon', 'Longitude'),
212
-				new TextField('ZoomLevel', 'Zoom')
213
-				)
214
-			);
215
-		}
216
-		return $this->mapField;
217
-	}
218
-
219
-
220
-	/**
221
-	 * Template helper, used to decide whether or not to use compressed assets
222
-	 */
223
-	public function UseCompressedAssets() {
224
-		return Config::inst()->get('Mappable', 'use_compressed_assets');
225
-	}
193
+         **/
194
+
195
+        $map->setEnableAutomaticCenterZoom($autozoom);
196
+        $map->setShowInlineMapDivStyle(true);
197
+
198
+        return $map;
199
+    }
200
+
201
+
202
+    /**
203
+     * Access the map editing field for the purpose of adding guide points
204
+     * @return [LatLongField] instance of location editing field
205
+     */
206
+    public function getMapField() {
207
+        if (!isset($this->mapField)) {
208
+            $this->mapField = new LatLongField(array(
209
+                new TextField('Lat', 'Latitude'),
210
+                new TextField('Lon', 'Longitude'),
211
+                new TextField('ZoomLevel', 'Zoom')
212
+                )
213
+            );
214
+        }
215
+        return $this->mapField;
216
+    }
217
+
218
+
219
+    /**
220
+     * Template helper, used to decide whether or not to use compressed assets
221
+     */
222
+    public function UseCompressedAssets() {
223
+        return Config::inst()->get('Mappable', 'use_compressed_assets');
224
+    }
226 225
 }
Please login to merge, or discard this patch.
code/shortcodes/GoogleStreetViewShortCodeHandler.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@
 block discarded – undo
8 8
 
9 9
 	public static function parse_googlestreetview($arguments, $caption = null, $parser = null) {
10 10
 		// each of latitude, longitude and heading are required at a bare minimum
11
-		if(!isset($arguments['latitude'])){
11
+		if (!isset($arguments['latitude'])) {
12 12
 			return '';
13 13
 		}
14 14
 
15
-		if(!isset($arguments['longitude'])){
15
+		if (!isset($arguments['longitude'])) {
16 16
 			return '';
17 17
 		}
18 18
 
19
-		if(!isset($arguments['heading'])){
19
+		if (!isset($arguments['heading'])) {
20 20
 			return '';
21 21
 		}
22 22
 
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -2,78 +2,78 @@
 block discarded – undo
2 2
 
3 3
 class GoogleStreetViewShortCodeHandler {
4 4
 
5
-	/* Counter used to ensure unique div ids to allow for multiple StreetViews on on page */
6
-	private static $gsv_ctr = 1;
5
+    /* Counter used to ensure unique div ids to allow for multiple StreetViews on on page */
6
+    private static $gsv_ctr = 1;
7 7
 
8 8
 
9
-	public static function parse_googlestreetview($arguments, $caption = null, $parser = null) {
10
-		// each of latitude, longitude and heading are required at a bare minimum
11
-		if(!isset($arguments['latitude'])){
12
-			return '';
13
-		}
9
+    public static function parse_googlestreetview($arguments, $caption = null, $parser = null) {
10
+        // each of latitude, longitude and heading are required at a bare minimum
11
+        if(!isset($arguments['latitude'])){
12
+            return '';
13
+        }
14 14
 
15
-		if(!isset($arguments['longitude'])){
16
-			return '';
17
-		}
15
+        if(!isset($arguments['longitude'])){
16
+            return '';
17
+        }
18 18
 
19
-		if(!isset($arguments['heading'])){
20
-			return '';
21
-		}
19
+        if(!isset($arguments['heading'])){
20
+            return '';
21
+        }
22 22
 
23
-		// defaults - these can be overriden by using zoom and pitch in the shortcode
24
-		$defaults = array(
25
-			'Zoom' => 1,
26
-			'Pitch' => 0
27
-		);
23
+        // defaults - these can be overriden by using zoom and pitch in the shortcode
24
+        $defaults = array(
25
+            'Zoom' => 1,
26
+            'Pitch' => 0
27
+        );
28 28
 
29
-		// ensure JavaScript for the map service is only downloaded once
30
-		$arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
31
-		MapUtil::set_map_already_rendered(true);
29
+        // ensure JavaScript for the map service is only downloaded once
30
+        $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
31
+        MapUtil::set_map_already_rendered(true);
32 32
 
33
-		// convert parameters to CamelCase as per standard template conventions
34
-		$arguments['Latitude'] = $arguments['latitude'];
35
-		$arguments['Longitude'] = $arguments['longitude'];
36
-		$arguments['Heading'] = $arguments['heading'];
33
+        // convert parameters to CamelCase as per standard template conventions
34
+        $arguments['Latitude'] = $arguments['latitude'];
35
+        $arguments['Longitude'] = $arguments['longitude'];
36
+        $arguments['Heading'] = $arguments['heading'];
37 37
 
38
-		// optional parameter caption
39
-		if (isset($arguments['caption'])) {
40
-			$arguments['Caption'] = $arguments['caption'];
41
-		}
38
+        // optional parameter caption
39
+        if (isset($arguments['caption'])) {
40
+            $arguments['Caption'] = $arguments['caption'];
41
+        }
42 42
 
43
-		// optional parameter pitch
44
-		if (isset($arguments['pitch'])) {
45
-			$arguments['Pitch'] = $arguments['pitch'];
46
-		}
43
+        // optional parameter pitch
44
+        if (isset($arguments['pitch'])) {
45
+            $arguments['Pitch'] = $arguments['pitch'];
46
+        }
47 47
 
48
-		// optional parameter zoom
49
-		if (isset($arguments['zoom'])) {
50
-			$arguments['Zoom'] = $arguments['zoom'];
51
-		}
48
+        // optional parameter zoom
49
+        if (isset($arguments['zoom'])) {
50
+            $arguments['Zoom'] = $arguments['zoom'];
51
+        }
52 52
 
53
-		// the id of the dom element to be used to render the street view
54
-		$arguments['DomID'] = 'google_streetview_'.self::$gsv_ctr;
53
+        // the id of the dom element to be used to render the street view
54
+        $arguments['DomID'] = 'google_streetview_'.self::$gsv_ctr;
55 55
 
56
-		// incrememt the counter to ensure a unique id for each map canvas
57
-		self::$gsv_ctr++;
56
+        // incrememt the counter to ensure a unique id for each map canvas
57
+        self::$gsv_ctr++;
58 58
 
59
-		// merge defaults and arguments
60
-		$customised = array_merge($defaults, $arguments);
59
+        // merge defaults and arguments
60
+        $customised = array_merge($defaults, $arguments);
61 61
 
62
-		// Include google maps JS at the end of the page
63
-		//Requirements::javascriptTemplate("mappable/javascript/google/streetview.google.template.js", $customised);
62
+        // Include google maps JS at the end of the page
63
+        //Requirements::javascriptTemplate("mappable/javascript/google/streetview.google.template.js", $customised);
64 64
 
65 65
 
66
-		//get streetview template template
67
-		$template = new SSViewer('GoogleStreetView');
66
+        //get streetview template template
67
+        $template = new SSViewer('GoogleStreetView');
68 68
 
69
-		//return the template customised with the parmameters
70
-		return $template->process(new ArrayData($customised));
71
-	}
69
+        //return the template customised with the parmameters
70
+        return $template->process(new ArrayData($customised));
71
+    }
72 72
 
73
-	/**
74
-	 * This is only used for testing, otherwise the sequence of tests change the number returned
75
-	 */
76
-	public static function resetCounter() {
77
-		self::$gsv_ctr = 1;
78
-	}
73
+    /**
74
+     * This is only used for testing, otherwise the sequence of tests change the number returned
75
+     */
76
+    public static function resetCounter() {
77
+        self::$gsv_ctr = 1;
78
+    }
79 79
 }
Please login to merge, or discard this patch.
code/shortcodes/GoogleMapShortCodeHandler.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,11 +7,11 @@
 block discarded – undo
7 7
 
8 8
 	public static function parse_googlemap($arguments, $caption = null, $parser = null) {
9 9
 		// each of latitude and longitude are required at a bare minimum
10
-		if(!isset($arguments['latitude'])){
10
+		if (!isset($arguments['latitude'])) {
11 11
 			return '';
12 12
 		}
13 13
 
14
-		if(!isset($arguments['longitude'])){
14
+		if (!isset($arguments['longitude'])) {
15 15
 			return '';
16 16
 		}
17 17
 
Please login to merge, or discard this patch.
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -2,73 +2,73 @@
 block discarded – undo
2 2
 
3 3
 class GoogleMapShortCodeHandler {
4 4
 
5
-	/* Counter used to ensure unique div ids to allow for multiple maps on on page */
6
-	private static $gsv_ctr = 1;
7
-
8
-	public static function parse_googlemap($arguments, $caption = null, $parser = null) {
9
-		// each of latitude and longitude are required at a bare minimum
10
-		if(!isset($arguments['latitude'])){
11
-			return '';
12
-		}
13
-
14
-		if(!isset($arguments['longitude'])){
15
-			return '';
16
-		}
17
-
18
-		// defaults - can be overriden by using zoom and FIXME in the shortcode
19
-		$defaults = array(
20
-			'Zoom' => 5,
21
-			'MapType' => 'road'
22
-		);
23
-
24
-		// ensure JavaScript for the map service is only downloaded once
25
-		$arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
26
-		MapUtil::set_map_already_rendered(true);
27
-
28
-		// convert parameters to CamelCase as per standard template conventions
29
-		$arguments['Latitude'] = $arguments['latitude'];
30
-		$arguments['Longitude'] = $arguments['longitude'];
31
-
32
-		// optional parameter caption
33
-		if (isset($arguments['caption'])) {
34
-			$arguments['Caption'] = $arguments['caption'];
35
-		}
36
-
37
-		if (isset($arguments['maptype'])) {
38
-			$arguments['MapType'] = $arguments['maptype'];
39
-		}
40
-
41
-		// optional parameter zoom
42
-		if (isset($arguments['zoom'])) {
43
-			$arguments['Zoom'] = $arguments['zoom'];
44
-		}
45
-
46
-		// the id of the dom element to be used to render the street view
47
-		$arguments['DomID'] = 'google_sc_map_'.self::$gsv_ctr;
48
-
49
-		// fullscreen
50
-		$arguments['AllowFullScreen'] = Config::inst()->get('Mappable', 'allow_full_screen');
51
-
52
-		// incrememt the counter to ensure a unique id for each map canvas
53
-		self::$gsv_ctr++;
54
-
55
-		// merge defaults and arguments
56
-		$customised = array_merge($defaults, $arguments);
57
-
58
-		// include JavaScript to be appended at the end of the page, namely params for map rendering
59
-		//Requirements::javascriptTemplate("mappable/javascript/google/map.google.template.js", $customised);
60
-
61
-		//get map view template and render the HTML
62
-		$template = new SSViewer('GoogleMapShortCode');
63
-
64
-		//return the template customised with the parmameters
65
-		return $template->process(new ArrayData($customised));
66
-	}
67
-
68
-	/**
69
-	 * This is only used for testing, otherwise the sequence of tests change the number returned
70
-	 */
71
-	public static function resetCounter() {
72
-		self::$gsv_ctr = 1;
73
-	}
5
+    /* Counter used to ensure unique div ids to allow for multiple maps on on page */
6
+    private static $gsv_ctr = 1;
7
+
8
+    public static function parse_googlemap($arguments, $caption = null, $parser = null) {
9
+        // each of latitude and longitude are required at a bare minimum
10
+        if(!isset($arguments['latitude'])){
11
+            return '';
12
+        }
13
+
14
+        if(!isset($arguments['longitude'])){
15
+            return '';
16
+        }
17
+
18
+        // defaults - can be overriden by using zoom and FIXME in the shortcode
19
+        $defaults = array(
20
+            'Zoom' => 5,
21
+            'MapType' => 'road'
22
+        );
23
+
24
+        // ensure JavaScript for the map service is only downloaded once
25
+        $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
26
+        MapUtil::set_map_already_rendered(true);
27
+
28
+        // convert parameters to CamelCase as per standard template conventions
29
+        $arguments['Latitude'] = $arguments['latitude'];
30
+        $arguments['Longitude'] = $arguments['longitude'];
31
+
32
+        // optional parameter caption
33
+        if (isset($arguments['caption'])) {
34
+            $arguments['Caption'] = $arguments['caption'];
35
+        }
36
+
37
+        if (isset($arguments['maptype'])) {
38
+            $arguments['MapType'] = $arguments['maptype'];
39
+        }
40
+
41
+        // optional parameter zoom
42
+        if (isset($arguments['zoom'])) {
43
+            $arguments['Zoom'] = $arguments['zoom'];
44
+        }
45
+
46
+        // the id of the dom element to be used to render the street view
47
+        $arguments['DomID'] = 'google_sc_map_'.self::$gsv_ctr;
48
+
49
+        // fullscreen
50
+        $arguments['AllowFullScreen'] = Config::inst()->get('Mappable', 'allow_full_screen');
51
+
52
+        // incrememt the counter to ensure a unique id for each map canvas
53
+        self::$gsv_ctr++;
54
+
55
+        // merge defaults and arguments
56
+        $customised = array_merge($defaults, $arguments);
57
+
58
+        // include JavaScript to be appended at the end of the page, namely params for map rendering
59
+        //Requirements::javascriptTemplate("mappable/javascript/google/map.google.template.js", $customised);
60
+
61
+        //get map view template and render the HTML
62
+        $template = new SSViewer('GoogleMapShortCode');
63
+
64
+        //return the template customised with the parmameters
65
+        return $template->process(new ArrayData($customised));
66
+    }
67
+
68
+    /**
69
+     * This is only used for testing, otherwise the sequence of tests change the number returned
70
+     */
71
+    public static function resetCounter() {
72
+        self::$gsv_ctr = 1;
73
+    }
74 74
 }
Please login to merge, or discard this patch.
code/MappableDataObjectSet.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 		$gmap = MapUtil::get_map($this->owner, $this->MarkerTemplateValues);
28 28
 		$w = $width ? $width : MapUtil::$map_width;
29 29
 		$h = $height ? $height : MapUtil::$map_height;
30
-		$gmap->setSize($w,$h);
30
+		$gmap->setSize($w, $h);
31 31
 		return $gmap;
32 32
 	}
33 33
 
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -8,27 +8,27 @@
 block discarded – undo
8 8
  */
9 9
 class MappableDataObjectSet extends Extension {
10 10
 
11
-	/**
12
-	 * Optional template values for the map info windows
13
-	 */
14
-	private $MarkerTemplateValues = null;
11
+    /**
12
+     * Optional template values for the map info windows
13
+     */
14
+    private $MarkerTemplateValues = null;
15 15
 
16
-	/**
17
-	 * Pass through values to the markers so that when rendering the map info windows, these
18
-	 * parameters are available to the template.  This is of course optional
19
-	 *
20
-	 * @param array $values hash array of template key to template value
21
-	 */
22
-	public function setMarkerTemplateValues($values) {
23
-		$this->MarkerTemplateValues = $values;
24
-	}
16
+    /**
17
+     * Pass through values to the markers so that when rendering the map info windows, these
18
+     * parameters are available to the template.  This is of course optional
19
+     *
20
+     * @param array $values hash array of template key to template value
21
+     */
22
+    public function setMarkerTemplateValues($values) {
23
+        $this->MarkerTemplateValues = $values;
24
+    }
25 25
 
26
-	public function getRenderableMap($width = null, $height = null) {
27
-		$gmap = MapUtil::get_map($this->owner, $this->MarkerTemplateValues);
28
-		$w = $width ? $width : MapUtil::$map_width;
29
-		$h = $height ? $height : MapUtil::$map_height;
30
-		$gmap->setSize($w,$h);
31
-		return $gmap;
32
-	}
26
+    public function getRenderableMap($width = null, $height = null) {
27
+        $gmap = MapUtil::get_map($this->owner, $this->MarkerTemplateValues);
28
+        $w = $width ? $width : MapUtil::$map_width;
29
+        $h = $height ? $height : MapUtil::$map_height;
30
+        $gmap->setSize($w,$h);
31
+        return $gmap;
32
+    }
33 33
 
34 34
 }
Please login to merge, or discard this patch.
code/MappableData.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 		$gmap = MapUtil::get_map(new ArrayList(array($this->owner)), $this->MarkerTemplateValues);
41 41
 		$w = $width ? $width : MapUtil::$map_width;
42 42
 		$h = $height ? $height : MapUtil::$map_height;
43
-		$gmap->setSize($w,$h);
43
+		$gmap->setSize($w, $h);
44 44
 		$gmap->setZoom($zoom);
45 45
 		$gmap->setEnableAutomaticCenterZoom(false);
46 46
 		if ($this->owner->MapPinEdited) {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 			$urlparts['markers'] = "icon:$pin|$lat,$lng";
90 90
 		}
91 91
 
92
-		$src = htmlentities($apiurl . '?' . http_build_query($urlparts));
92
+		$src = htmlentities($apiurl.'?'.http_build_query($urlparts));
93 93
 		return '<img src="'.$src.'" width="'.$w.'" height="'.$h.'" alt="'.$this->owner->Title.'" />';
94 94
 	}
95 95
 
Please login to merge, or discard this patch.
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -8,93 +8,93 @@
 block discarded – undo
8 8
  */
9 9
 class MappableData extends Extension {
10 10
 
11
-	/**
12
-	 * Optional template values for the map info windows
13
-	 */
14
-	private $MarkerTemplateValues = null;
15
-
16
-	/**
17
-	 * URL of static maps api
18
-	 * @var string
19
-	 */
20
-	private static $staticmap_api_url = '//maps.googleapis.com/maps/api/staticmap';
21
-
22
-	/**
23
-	 * Default zoom for static map
24
-	 * @var int
25
-	 */
26
-	private static $staticmap_default_zoom = 13;
27
-
28
-	/**
29
-	 * Pass through values to the markers so that when rendering the map info windows, these
30
-	 * parameters are available to the template.  This is of course optional
31
-	 *
32
-	 * @param array $values hash array of template key to template value
33
-	 */
34
-	public function setMarkerTemplateValues($values) {
35
-		$this->MarkerTemplateValues = $values;
36
-	}
37
-
38
-
39
-	public function getRenderableMap($width = null, $height = null, $zoom = 9) {
40
-		$gmap = MapUtil::get_map(new ArrayList(array($this->owner)), $this->MarkerTemplateValues);
41
-		$w = $width ? $width : MapUtil::$map_width;
42
-		$h = $height ? $height : MapUtil::$map_height;
43
-		$gmap->setSize($w,$h);
44
-		$gmap->setZoom($zoom);
45
-		$gmap->setEnableAutomaticCenterZoom(false);
46
-		if ($this->owner->MapPinEdited) {
47
-			$gmap->setLatLongCenter(array(
48
-				'lat' => $this->owner->getMappableLatitude(),
49
-				'lng' => $this->owner->getMappableLongitude()
50
-			));
51
-		}
52
-		return $gmap;
53
-	}
54
-
55
-
56
-	/**
57
-	 * returns an <img> with a src set to a static map picture
58
-	 *
59
-	 * You can use MappableData.staticmap_api_url config var to set the domain of the static map.
60
-	 * You can use MappableData.staticmap_default_zoom config var to set the default zoom for the static map.
61
-	 *
62
-	 * @uses Mappable::getMappableMapPin() to draw a special marker, be sure this image is publicly available
63
-	 *
64
-	 * @param int $width
65
-	 * @param int $height
66
-	 * @return string
67
-	 */
68
-	public function StaticMap($width, $height, $zoom = null, $mapType = 'roadmap') {
69
-		$lat = $this->owner->getMappableLatitude();
70
-		$lng = $this->owner->getMappableLongitude();
71
-		$pin = $this->owner->getMappableMapPin();
72
-
73
-		// use provided zoom or set a default
74
-		if ($zoom == null) {
75
-			$zoom = Config::inst()->get('MappableData', 'staticmap_default_zoom');
76
-		}
77
-
78
-		//https://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&key=YOUR_API_KEY
79
-			    //maps.googleapis.com/maps/api/staticmap';
80
-
81
-		$apiurl = Config::inst()->get('MappableData', 'staticmap_api_url');
82
-
83
-		$urlparts = array(
84
-			'center' => "$lat,$lng",
85
-			'markers' => "$lat,$lng",
86
-			'zoom' => $zoom,
87
-			'size' => "{$width}x{$height}",
88
-			'sensor' => 'false', //@todo: make sensor param configurable
89
-			'maptype' => $mapType
90
-		);
91
-		if ($pin) {
92
-			$urlparts['markers'] = "icon:$pin|$lat,$lng";
93
-		}
94
-
95
-		$src = htmlentities($apiurl . '?' . http_build_query($urlparts));
96
-
97
-		return '<img src="'.$src.'" width="'.$width.'" height="'.$height.'" alt="'.$this->owner->Title.'" />';
98
-	}
11
+    /**
12
+     * Optional template values for the map info windows
13
+     */
14
+    private $MarkerTemplateValues = null;
15
+
16
+    /**
17
+     * URL of static maps api
18
+     * @var string
19
+     */
20
+    private static $staticmap_api_url = '//maps.googleapis.com/maps/api/staticmap';
21
+
22
+    /**
23
+     * Default zoom for static map
24
+     * @var int
25
+     */
26
+    private static $staticmap_default_zoom = 13;
27
+
28
+    /**
29
+     * Pass through values to the markers so that when rendering the map info windows, these
30
+     * parameters are available to the template.  This is of course optional
31
+     *
32
+     * @param array $values hash array of template key to template value
33
+     */
34
+    public function setMarkerTemplateValues($values) {
35
+        $this->MarkerTemplateValues = $values;
36
+    }
37
+
38
+
39
+    public function getRenderableMap($width = null, $height = null, $zoom = 9) {
40
+        $gmap = MapUtil::get_map(new ArrayList(array($this->owner)), $this->MarkerTemplateValues);
41
+        $w = $width ? $width : MapUtil::$map_width;
42
+        $h = $height ? $height : MapUtil::$map_height;
43
+        $gmap->setSize($w,$h);
44
+        $gmap->setZoom($zoom);
45
+        $gmap->setEnableAutomaticCenterZoom(false);
46
+        if ($this->owner->MapPinEdited) {
47
+            $gmap->setLatLongCenter(array(
48
+                'lat' => $this->owner->getMappableLatitude(),
49
+                'lng' => $this->owner->getMappableLongitude()
50
+            ));
51
+        }
52
+        return $gmap;
53
+    }
54
+
55
+
56
+    /**
57
+     * returns an <img> with a src set to a static map picture
58
+     *
59
+     * You can use MappableData.staticmap_api_url config var to set the domain of the static map.
60
+     * You can use MappableData.staticmap_default_zoom config var to set the default zoom for the static map.
61
+     *
62
+     * @uses Mappable::getMappableMapPin() to draw a special marker, be sure this image is publicly available
63
+     *
64
+     * @param int $width
65
+     * @param int $height
66
+     * @return string
67
+     */
68
+    public function StaticMap($width, $height, $zoom = null, $mapType = 'roadmap') {
69
+        $lat = $this->owner->getMappableLatitude();
70
+        $lng = $this->owner->getMappableLongitude();
71
+        $pin = $this->owner->getMappableMapPin();
72
+
73
+        // use provided zoom or set a default
74
+        if ($zoom == null) {
75
+            $zoom = Config::inst()->get('MappableData', 'staticmap_default_zoom');
76
+        }
77
+
78
+        //https://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&key=YOUR_API_KEY
79
+                //maps.googleapis.com/maps/api/staticmap';
80
+
81
+        $apiurl = Config::inst()->get('MappableData', 'staticmap_api_url');
82
+
83
+        $urlparts = array(
84
+            'center' => "$lat,$lng",
85
+            'markers' => "$lat,$lng",
86
+            'zoom' => $zoom,
87
+            'size' => "{$width}x{$height}",
88
+            'sensor' => 'false', //@todo: make sensor param configurable
89
+            'maptype' => $mapType
90
+        );
91
+        if ($pin) {
92
+            $urlparts['markers'] = "icon:$pin|$lat,$lng";
93
+        }
94
+
95
+        $src = htmlentities($apiurl . '?' . http_build_query($urlparts));
96
+
97
+        return '<img src="'.$src.'" width="'.$width.'" height="'.$height.'" alt="'.$this->owner->Title.'" />';
98
+    }
99 99
 
100 100
 }
Please login to merge, or discard this patch.
code/MapUtil.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -226,8 +226,9 @@
 block discarded – undo
226 226
 		$gmap = self::instance();
227 227
 		if ($list) {
228 228
 			foreach ($list as $mappable) {
229
-				if (self::ChooseToAddDataobject($mappable))
230
-					$gmap->addMarkerAsObject($mappable, $infowindowtemplateparams);
229
+				if (self::ChooseToAddDataobject($mappable)) {
230
+									$gmap->addMarkerAsObject($mappable, $infowindowtemplateparams);
231
+				}
231 232
 			}
232 233
 		}
233 234
 		return $gmap;
Please login to merge, or discard this patch.
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -3,221 +3,221 @@
 block discarded – undo
3 3
 class MapUtil
4 4
 {
5 5
 
6
-	/**
7
-	 * @var string The Google Maps API key
8
-	 */
9
-	protected static $api_key;
10
-
11
-	/**
12
-	 * @var int Number of active {@see GoogleMapsAPI} instances (for the HTML ID)
13
-	 */
14
-	protected static $instances = 0;
15
-
16
-	/**
17
-	 * @var int The default width of a Google Map
18
-	 */
19
-	public static $map_width = '100%';
20
-
21
-	/**
22
-	 * @var int The default height of a Google Map
23
-	 */
24
-	public static $map_height = '400px';
25
-
26
-	/**
27
-	 * @var int Prefix for the div ID of the map
28
-	 */
29
-	public static $div_id = "google_map";
30
-
31
-	/**
32
-	 * @var boolean Automatic center/zoom for the map
33
-	 */
34
-	public static $automatic_center = true;
35
-
36
-	/**
37
-	 * @var boolean Show the marker fields on the map
38
-	 */
39
-	public static $hide_marker = false;
40
-
41
-	/**
42
-	 * @var boolean Show the marker fields on the map
43
-	 */
44
-	public static $map_type = 'google.maps.MapTypeId.ROADMAP';
45
-
46
-	/**
47
-	 * @var string $center Center of map (adress)
48
-	 */
49
-	public static $center = 'Paris, France';
50
-
51
-	/* Signals whether at least one map has already been rendered */
52
-	private static $map_already_rendered = false;
53
-
54
-	/* Whether or not to allow full screen */
55
-	private static $allow_full_screen = null;
56
-
57
-
58
-	public static function reset() {
59
-		self::$api_key = null;
60
-		self::$instances = 0;
61
-		self::$map_width = '100%';
62
-		self::$map_height = '400px';
63
-		self::$div_id = "google_map";
64
-		self::$automatic_center = true;
65
-		self::$hide_marker = false;
66
-		self::$map_type = 'google.maps.MapTypeId.ROADMAP';
67
-		self::$center = 'Paris, France';
68
-		self::$map_already_rendered = false;
69
-		self::$allow_full_screen = null;
70
-		Config::inst()->update('Mappable', 'language', 'en');
71
-	}
72
-
73
-	/**
74
-	 * Set the API key for Google Maps
75
-	 *
76
-	 * @param string $key
77
-	 */
78
-	public static function set_api_key($key) {
79
-		self::$api_key = $key;
80
-	}
81
-
82
-	/**
83
-	 * @param boolean $new_map_already_rendered
84
-	 */
85
-	public static function set_map_already_rendered($new_map_already_rendered) {
86
-		self::$map_already_rendered = $new_map_already_rendered;
87
-	}
88
-
89
-	public static function get_map_already_rendered() {
90
-		return self::$map_already_rendered;
91
-	}
92
-
93
-	/**
94
-	 * Set the default size of the map
95
-	 *
96
-	 * @param int $width
97
-	 * @param int $height
98
-	 */
99
-	public static function set_map_size($width, $height) {
100
-		self:: $map_width = $width;
101
-		self::$map_height = $height;
102
-	}
103
-
104
-	/**
105
-	 * FIXME - NOT USED?
106
-	 * Set the type of the gmap
107
-	 *
108
-	 * @param string $mapType (can be 'google.maps.MapTypeId.ROADMAP', 'G_SATELLITE_MAP',
109
-	 * 'G_HYBRID_MAP', 'G_PHYSICAL_MAP')
110
-	 *
111
-	 * @return void
112
-	 */
113
-	public static function set_map_type($mapType) {
114
-		self::$map_type = $mapType;
115
-	}
116
-
117
-	/**
118
-	 * Set the center of the gmap (an address, using text geocoder query)
119
-	 *
120
-	 * @param string $center GoogleMap  center (an address)
121
-	 *
122
-	 * @return void
123
-	 */
124
-	public static function set_center($center)
125
-	{
126
-		self::$center = $center;
127
-	}
128
-
129
-	/**
130
-	 * Get a new GoogleMapAPI object and load it with the default settings
131
-	 *
132
-	 * @return MapAPI
133
-	 */
134
-	public static function instance()
135
-	{
136
-		self::$instances++;
137
-
138
-		if (self::$allow_full_screen == null) {
139
-			self::$allow_full_screen = Config::inst()->get('Mappable', 'allow_full_screen');
140
-		}
141
-
142
-		$url = Director::absoluteBaseURL();
143
-
144
-		// remove http and https
145
-		$url = str_replace('http://', '', $url);
146
-		$url = str_replace('https://', '', $url);
147
-		$parts = explode('/', $url);
148
-		$host = $parts[0];
149
-
150
-		$key = self::$api_key;
151
-
152
-		// if an array, get the key by an array keyed by host
153
-		if (is_array($key)) {
154
-			$key = $key[$host];
155
-		}
156
-
157
-		$gmap = new MapAPI($key);
158
-		$gmap->setDivId(self::$div_id."_".self::$instances);
159
-		$gmap->setEnableAutomaticCenterZoom(self::$automatic_center);
160
-		$gmap->setSize(self::$map_width, self::$map_height);
161
-		$gmap->setDefaultHideMarker(self::$hide_marker);
162
-		$gmap->setMapType(self::$map_type);
163
-		$gmap->setCenter(self::$center);
164
-		$gmap->setAllowFullScreen(self::$allow_full_screen);
165
-		$language = Config::inst()->get('Mappable', 'language');
166
-		$gmap->setLang($language);
167
-		return $gmap;
168
-	}
169
-
170
-
171
-	/**
172
-	 * Sanitize a string of HTML content for safe inclusion in the JavaScript
173
-	 * for a Google Map
174
-	 *
175
-	 * @return string
176
-	 */
177
-	public static function sanitize($content) {
178
-		return addslashes(str_replace(array("\n", "\r", "\t"), '', $content));
179
-	}
180
-
181
-
182
-	/**
183
-	 * Creates a new {@link GoogleMapsAPI} object loaded with the default settings
184
-	 * and places all of the items in a {@link SS_List}
185
-	 * e.g. {@link DataList} or {@link ArrayList} on the map
186
-	 *
187
-	 * @param SS_List list of objects to display on a map
188
-	 * @param  array $infowindowtemplateparams Optional array of extra parameters to pass to the map info window
189
-	 * @return MapAPI
190
-	 */
191
-	public static function get_map(SS_List $list, $infowindowtemplateparams) {
192
-		$gmap = self::instance();
193
-		if ($list) {
194
-			foreach ($list as $mappable) {
195
-				if (self::ChooseToAddDataobject($mappable))
196
-					$gmap->addMarkerAsObject($mappable, $infowindowtemplateparams);
197
-			}
198
-		}
199
-		return $gmap;
200
-	}
201
-
202
-	/**
203
-	 * Determines if the current DataObject should be included to the map
204
-	 * Checks if it has Mappable interface implemented
205
-	 * If it has MapExtension included, the value of MapPinEdited is also checked
206
-	 *
207
-	 * @param DataObject $do
208
-	 * @return bool
209
-	 */
210
-	private static function ChooseToAddDataobject(DataObject $do) {
211
-		$isMappable = $do->is_a('Mappable');
212
-
213
-		foreach ($do->getExtensionInstances() as $extension) {
214
-			$isMappable = $isMappable || $extension instanceof Mappable;
215
-		}
216
-
217
-		$filterMapPinEdited = $do->hasExtension('MapExtension')
218
-			? $do->MapPinEdited
219
-			: true;
220
-
221
-		return $isMappable && $filterMapPinEdited;
222
-	}
6
+    /**
7
+     * @var string The Google Maps API key
8
+     */
9
+    protected static $api_key;
10
+
11
+    /**
12
+     * @var int Number of active {@see GoogleMapsAPI} instances (for the HTML ID)
13
+     */
14
+    protected static $instances = 0;
15
+
16
+    /**
17
+     * @var int The default width of a Google Map
18
+     */
19
+    public static $map_width = '100%';
20
+
21
+    /**
22
+     * @var int The default height of a Google Map
23
+     */
24
+    public static $map_height = '400px';
25
+
26
+    /**
27
+     * @var int Prefix for the div ID of the map
28
+     */
29
+    public static $div_id = "google_map";
30
+
31
+    /**
32
+     * @var boolean Automatic center/zoom for the map
33
+     */
34
+    public static $automatic_center = true;
35
+
36
+    /**
37
+     * @var boolean Show the marker fields on the map
38
+     */
39
+    public static $hide_marker = false;
40
+
41
+    /**
42
+     * @var boolean Show the marker fields on the map
43
+     */
44
+    public static $map_type = 'google.maps.MapTypeId.ROADMAP';
45
+
46
+    /**
47
+     * @var string $center Center of map (adress)
48
+     */
49
+    public static $center = 'Paris, France';
50
+
51
+    /* Signals whether at least one map has already been rendered */
52
+    private static $map_already_rendered = false;
53
+
54
+    /* Whether or not to allow full screen */
55
+    private static $allow_full_screen = null;
56
+
57
+
58
+    public static function reset() {
59
+        self::$api_key = null;
60
+        self::$instances = 0;
61
+        self::$map_width = '100%';
62
+        self::$map_height = '400px';
63
+        self::$div_id = "google_map";
64
+        self::$automatic_center = true;
65
+        self::$hide_marker = false;
66
+        self::$map_type = 'google.maps.MapTypeId.ROADMAP';
67
+        self::$center = 'Paris, France';
68
+        self::$map_already_rendered = false;
69
+        self::$allow_full_screen = null;
70
+        Config::inst()->update('Mappable', 'language', 'en');
71
+    }
72
+
73
+    /**
74
+     * Set the API key for Google Maps
75
+     *
76
+     * @param string $key
77
+     */
78
+    public static function set_api_key($key) {
79
+        self::$api_key = $key;
80
+    }
81
+
82
+    /**
83
+     * @param boolean $new_map_already_rendered
84
+     */
85
+    public static function set_map_already_rendered($new_map_already_rendered) {
86
+        self::$map_already_rendered = $new_map_already_rendered;
87
+    }
88
+
89
+    public static function get_map_already_rendered() {
90
+        return self::$map_already_rendered;
91
+    }
92
+
93
+    /**
94
+     * Set the default size of the map
95
+     *
96
+     * @param int $width
97
+     * @param int $height
98
+     */
99
+    public static function set_map_size($width, $height) {
100
+        self:: $map_width = $width;
101
+        self::$map_height = $height;
102
+    }
103
+
104
+    /**
105
+     * FIXME - NOT USED?
106
+     * Set the type of the gmap
107
+     *
108
+     * @param string $mapType (can be 'google.maps.MapTypeId.ROADMAP', 'G_SATELLITE_MAP',
109
+     * 'G_HYBRID_MAP', 'G_PHYSICAL_MAP')
110
+     *
111
+     * @return void
112
+     */
113
+    public static function set_map_type($mapType) {
114
+        self::$map_type = $mapType;
115
+    }
116
+
117
+    /**
118
+     * Set the center of the gmap (an address, using text geocoder query)
119
+     *
120
+     * @param string $center GoogleMap  center (an address)
121
+     *
122
+     * @return void
123
+     */
124
+    public static function set_center($center)
125
+    {
126
+        self::$center = $center;
127
+    }
128
+
129
+    /**
130
+     * Get a new GoogleMapAPI object and load it with the default settings
131
+     *
132
+     * @return MapAPI
133
+     */
134
+    public static function instance()
135
+    {
136
+        self::$instances++;
137
+
138
+        if (self::$allow_full_screen == null) {
139
+            self::$allow_full_screen = Config::inst()->get('Mappable', 'allow_full_screen');
140
+        }
141
+
142
+        $url = Director::absoluteBaseURL();
143
+
144
+        // remove http and https
145
+        $url = str_replace('http://', '', $url);
146
+        $url = str_replace('https://', '', $url);
147
+        $parts = explode('/', $url);
148
+        $host = $parts[0];
149
+
150
+        $key = self::$api_key;
151
+
152
+        // if an array, get the key by an array keyed by host
153
+        if (is_array($key)) {
154
+            $key = $key[$host];
155
+        }
156
+
157
+        $gmap = new MapAPI($key);
158
+        $gmap->setDivId(self::$div_id."_".self::$instances);
159
+        $gmap->setEnableAutomaticCenterZoom(self::$automatic_center);
160
+        $gmap->setSize(self::$map_width, self::$map_height);
161
+        $gmap->setDefaultHideMarker(self::$hide_marker);
162
+        $gmap->setMapType(self::$map_type);
163
+        $gmap->setCenter(self::$center);
164
+        $gmap->setAllowFullScreen(self::$allow_full_screen);
165
+        $language = Config::inst()->get('Mappable', 'language');
166
+        $gmap->setLang($language);
167
+        return $gmap;
168
+    }
169
+
170
+
171
+    /**
172
+     * Sanitize a string of HTML content for safe inclusion in the JavaScript
173
+     * for a Google Map
174
+     *
175
+     * @return string
176
+     */
177
+    public static function sanitize($content) {
178
+        return addslashes(str_replace(array("\n", "\r", "\t"), '', $content));
179
+    }
180
+
181
+
182
+    /**
183
+     * Creates a new {@link GoogleMapsAPI} object loaded with the default settings
184
+     * and places all of the items in a {@link SS_List}
185
+     * e.g. {@link DataList} or {@link ArrayList} on the map
186
+     *
187
+     * @param SS_List list of objects to display on a map
188
+     * @param  array $infowindowtemplateparams Optional array of extra parameters to pass to the map info window
189
+     * @return MapAPI
190
+     */
191
+    public static function get_map(SS_List $list, $infowindowtemplateparams) {
192
+        $gmap = self::instance();
193
+        if ($list) {
194
+            foreach ($list as $mappable) {
195
+                if (self::ChooseToAddDataobject($mappable))
196
+                    $gmap->addMarkerAsObject($mappable, $infowindowtemplateparams);
197
+            }
198
+        }
199
+        return $gmap;
200
+    }
201
+
202
+    /**
203
+     * Determines if the current DataObject should be included to the map
204
+     * Checks if it has Mappable interface implemented
205
+     * If it has MapExtension included, the value of MapPinEdited is also checked
206
+     *
207
+     * @param DataObject $do
208
+     * @return bool
209
+     */
210
+    private static function ChooseToAddDataobject(DataObject $do) {
211
+        $isMappable = $do->is_a('Mappable');
212
+
213
+        foreach ($do->getExtensionInstances() as $extension) {
214
+            $isMappable = $isMappable || $extension instanceof Mappable;
215
+        }
216
+
217
+        $filterMapPinEdited = $do->hasExtension('MapExtension')
218
+            ? $do->MapPinEdited
219
+            : true;
220
+
221
+        return $isMappable && $filterMapPinEdited;
222
+    }
223 223
 }
Please login to merge, or discard this patch.
tests/MapExtensionTest.php 2 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -256,6 +256,10 @@  discard block
 block discarded – undo
256 256
 	/*
257 257
 	Add a map layer to an existing instance
258 258
 	 */
259
+
260
+	/**
261
+	 * @param Member $instance
262
+	 */
259 263
 	private function addLayerToInstance(&$instance) {
260 264
 		// Create a layer
261 265
 		$kmlFile = new File(array('Name' => 'example.kml', 'Filename' => 'mappable/tests/kml/example.kml'));
@@ -269,6 +273,9 @@  discard block
 block discarded – undo
269 273
 		$layers->add($layer);
270 274
 	}
271 275
 
276
+	/**
277
+	 * @param Member $instance
278
+	 */
272 279
 	private function addMapPinToInstance(&$instance) {
273 280
 		// Create a pin
274 281
 		$imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'mappable/tests/images/mapicontest.png'));
Please login to merge, or discard this patch.
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -1,294 +1,294 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class MapExtensionTest extends SapphireTest {
4
-	protected static $fixture_file = 'mappable/tests/mapextensions.yml';
4
+    protected static $fixture_file = 'mappable/tests/mapextensions.yml';
5 5
 
6
-	public function setUpOnce() {
7
-		$this->requiredExtensions = array(
8
-			'Member' => array('MapExtension', 'MapLayerExtension')
9
-		);
10
-		parent::setupOnce();
11
-	}
6
+    public function setUpOnce() {
7
+        $this->requiredExtensions = array(
8
+            'Member' => array('MapExtension', 'MapLayerExtension')
9
+        );
10
+        parent::setupOnce();
11
+    }
12 12
 
13 13
 
14
-	public function testUpdateCMSFields() {
14
+    public function testUpdateCMSFields() {
15 15
 
16
-	}
16
+    }
17 17
 
18 18
 
19
-	public function testGetMappableLatitude() {
20
-		$instance = $this->getInstance();
21
-		$instance->Lat = 42.1;
22
-		$instance->write();
23
-		$this->assertEquals(
24
-			42.1,
25
-			$instance->getMappableLatitude()
26
-		);
27
-	}
19
+    public function testGetMappableLatitude() {
20
+        $instance = $this->getInstance();
21
+        $instance->Lat = 42.1;
22
+        $instance->write();
23
+        $this->assertEquals(
24
+            42.1,
25
+            $instance->getMappableLatitude()
26
+        );
27
+    }
28 28
 
29 29
 
30
-	public function testGetMappableLongitude() {
31
-		$instance = $this->getInstance();
32
-		$instance->Lon = 42.1;
33
-		$this->assertEquals(
34
-			42.1,
35
-			$instance->getMappableLongitude()
36
-		);
37
-	}
30
+    public function testGetMappableLongitude() {
31
+        $instance = $this->getInstance();
32
+        $instance->Lon = 42.1;
33
+        $this->assertEquals(
34
+            42.1,
35
+            $instance->getMappableLongitude()
36
+        );
37
+    }
38 38
 
39 39
 
40
-	public function testgetMappableMapContent() {
40
+    public function testgetMappableMapContent() {
41 41
 
42
-	}
42
+    }
43 43
 
44 44
 
45
-	public function testonBeforeWriteMapPinNotEdited() {
46
-		$instance = $this->getInstance();
47
-		$this->Lat = 0;
48
-		$this->Lon = 0;
49
-		$instance->write();
50
-		$this->assertFalse($instance->MapPinEdited);
51
-	}
45
+    public function testonBeforeWriteMapPinNotEdited() {
46
+        $instance = $this->getInstance();
47
+        $this->Lat = 0;
48
+        $this->Lon = 0;
49
+        $instance->write();
50
+        $this->assertFalse($instance->MapPinEdited);
51
+    }
52 52
 
53
-	public function testonBeforeWriteMapPinEdited() {
54
-		$instance = $this->getInstance();
53
+    public function testonBeforeWriteMapPinEdited() {
54
+        $instance = $this->getInstance();
55 55
 
56
-		// north
57
-		$this->showMapPinEdited($instance, 10, 0);
56
+        // north
57
+        $this->showMapPinEdited($instance, 10, 0);
58 58
 
59
-		// north west
60
-		$this->showMapPinEdited($instance, 10, -10);
59
+        // north west
60
+        $this->showMapPinEdited($instance, 10, -10);
61 61
 
62
-		// west
63
-		$this->showMapPinEdited($instance, 0, -10);
62
+        // west
63
+        $this->showMapPinEdited($instance, 0, -10);
64 64
 
65
-		// south west
66
-		$this->showMapPinEdited($instance, -10, -10);
65
+        // south west
66
+        $this->showMapPinEdited($instance, -10, -10);
67 67
 
68
-		// south
69
-		$this->showMapPinEdited($instance, -10, 0);
68
+        // south
69
+        $this->showMapPinEdited($instance, -10, 0);
70 70
 
71
-		// south east
72
-		$this->showMapPinEdited($instance, -10, 10);
71
+        // south east
72
+        $this->showMapPinEdited($instance, -10, 10);
73 73
 
74
-		// east
75
-		$this->showMapPinEdited($instance, 0, 10);
74
+        // east
75
+        $this->showMapPinEdited($instance, 0, 10);
76 76
 
77
-		// north east
78
-		$this->showMapPinEdited($instance, 10, 10);
77
+        // north east
78
+        $this->showMapPinEdited($instance, 10, 10);
79 79
 
80
-	}
80
+    }
81 81
 
82 82
 
83
-	// FIXME - use an actual file here
84
-	public function testGetMappableMapPin() {
85
-		$instance = $this->getInstance();
83
+    // FIXME - use an actual file here
84
+    public function testGetMappableMapPin() {
85
+        $instance = $this->getInstance();
86 86
 
87
-		// no icon, so return false
88
-		$this->assertFalse($instance->getMappableMapPin());
87
+        // no icon, so return false
88
+        $this->assertFalse($instance->getMappableMapPin());
89 89
 
90
-		// add a default map icon
91
-		$this->addMapPinToInstance($instance);
90
+        // add a default map icon
91
+        $this->addMapPinToInstance($instance);
92 92
 
93
-		$pin1 = $instance->getMappableMapPin();
94
-		$this->assertStringEndsWith('assets/mapicontest.png', $pin1);
93
+        $pin1 = $instance->getMappableMapPin();
94
+        $this->assertStringEndsWith('assets/mapicontest.png', $pin1);
95 95
 
96
-		// Test the cached pin - this is the case of a layer providing a cached pin
97
-		// so that repeated calls are not made to load the same icon
98
-		$iconURL =
99
-			'https://cdn3.iconfinder.com/data/icons/iconic-1/32/map_pin_fill-512.png';
96
+        // Test the cached pin - this is the case of a layer providing a cached pin
97
+        // so that repeated calls are not made to load the same icon
98
+        $iconURL =
99
+            'https://cdn3.iconfinder.com/data/icons/iconic-1/32/map_pin_fill-512.png';
100 100
 
101
-		// Set mappable as having no icon, use the cached one instead
102
-		// This simulates using a common icon to avoid DB queries
103
-		$instance->MapPinIconID = 0;
104
-		$instance->write();
105
-		$instance->CachedMapPinURL = $iconURL;
106
-		$pin2 = $instance->getMappableMapPin();
107
-		$this->assertEquals($iconURL, $pin2);
108
-	}
101
+        // Set mappable as having no icon, use the cached one instead
102
+        // This simulates using a common icon to avoid DB queries
103
+        $instance->MapPinIconID = 0;
104
+        $instance->write();
105
+        $instance->CachedMapPinURL = $iconURL;
106
+        $pin2 = $instance->getMappableMapPin();
107
+        $this->assertEquals($iconURL, $pin2);
108
+    }
109 109
 
110 110
 
111 111
 
112 112
 
113 113
 
114
-	public function testHasGeoWest() {
115
-		$instance = $this->getInstance();
116
-		$instance->Lon = -20;
117
-		$this->assertTrue($instance->HasGeo());
118
-	}
119
-
120
-	public function testHasGeoEast() {
121
-		$instance = $this->getInstance();
122
-		$instance->Lon = 20;
123
-		$this->assertTrue($instance->HasGeo());
124
-	}
125
-
126
-	public function testHasGeoNorth() {
127
-		$instance = $this->getInstance();
128
-		$instance->Lat = 20;
129
-		$this->assertTrue($instance->HasGeo());
130
-	}
131
-
132
-	public function testHasGeoNorthWest() {
133
-		$instance = $this->getInstance();
134
-		$instance->Lat = 20;
135
-		$instance->Lon = -20;
136
-		$this->assertTrue($instance->HasGeo());
137
-	}
138
-
139
-	public function testHasGeoNortEast() {
140
-		$instance = $this->getInstance();
141
-		$instance->Lat = 20;
142
-		$instance->Lon = 20;
143
-		$this->assertTrue($instance->HasGeo());
144
-	}
145
-
146
-	public function testHasGeoSouth() {
147
-		$instance = $this->getInstance();
148
-		$instance->Lat = -20;
149
-		$this->assertTrue($instance->HasGeo());
150
-	}
151
-
152
-	public function testHasGeoSouthWest() {
153
-		$instance = $this->getInstance();
154
-		$instance->Lat = -20;
155
-		$instance->Lon = -20;
156
-		$this->assertTrue($instance->HasGeo());
157
-	}
158
-
159
-	public function testHasGeoSouthEast() {
160
-		$instance = $this->getInstance();
161
-		$instance->Lat = -20;
162
-		$instance->Lon = 20;
163
-		$this->assertTrue($instance->HasGeo());
164
-	}
165
-
166
-	public function testHasGeoOrigin() {
167
-		$instance = $this->getInstance();
168
-		$instance->Lat = 0;
169
-		$instance->Lon = 0;
170
-		$this->assertFalse($instance->HasGeo());
171
-	}
172
-
173
-	public function testHasGeoOriginMapLayerExtension() {
174
-		$instance = $this->getInstance();
175
-
176
-		// assert that origin has no geo (until layers added)
177
-		$instance->Lat = 0;
178
-		$instance->Lon = 0;
179
-		$this->assertFalse($instance->HasGeo());
180
-
181
-		$this->addLayerToInstance($instance);
182
-
183
-		// assert has geo even when at the origin of 0,0
184
-		$this->assertTrue($instance->HasGeo());
185
-	}
186
-
187
-	public function testBasicMap() {
188
-		$instance = $this->getInstance();
189
-		$instance->Lat = 37.1;
190
-		$instance->Lon = 28;
191
-		$instance->Zoom = 12;
192
-		$instance->MapPinEdited = true;
193
-		$html = $instance->BasicMap()->forTemplate();
194
-
195
-		$expected = "data-centre='{\"lat\":37.1,\"lng\":28}'";
196
-		$this->assertContains($expected, $html);
197
-		$expected = "data-mapmarkers='[{\"latitude\":37.1,\"longitude\":28,\"html\":\"MEMBER: \",\"category\":\"default\",\"icon\":false}]'";
198
-		$this->assertContains($expected, $html);
199
-
200
-		// This is only set automatically with layers
201
-		$expected = 'data-enableautocentrezoom=false';
202
-		$this->assertContains($expected, $html);
203
-	}
204
-
205
-	public function testBasicMapWithLayer() {
206
-		$instance = $this->getInstance();
207
-		$instance->Lat = 37.1;
208
-		$instance->Lon = 28;
209
-		$instance->Zoom = 12;
210
-		$instance->MapPinEdited = true;
211
-		$instance->write();
212
-		$this->addLayerToInstance($instance);
213
-		$html = $instance->BasicMap()->forTemplate();
214
-
215
-		$expected = "data-centre='{\"lat\":37.1,\"lng\":28}'";
216
-		$this->assertContains($expected, $html);
217
-		$expected = "data-mapmarkers='[{\"latitude\":37.1,\"longitude\":28,\"html\":\"MEMBER: \",\"category\":\"default\",\"icon\":false}]'";
218
-		$this->assertContains($expected, $html);
219
-
220
-		// This is only set automatically with layers
221
-		$expected = 'data-enableautocentrezoom=1';
222
-		$this->assertContains($expected, $html);
223
-	}
224
-
225
-
226
-	public function testGetMapField() {
227
-		$instance = $this->getInstance();
228
-		$this->Lat = 37.1;
229
-		$this->Lon = 28;
230
-		$this->Zoom = 12;
231
-		$mapField  = $instance->getMapField();
232
-		$this->assertInstanceOf('LatLongField', $mapField);
233
-	}
234
-
235
-
236
-	public function testUseCompressedAssets() {
237
-		$original = Config::inst()->get('Mappable', 'use_compressed_assets');
238
-
239
-		$instance = $this->getInstance();
240
-		Config::inst()->update('Mappable', 'use_compressed_assets', false);
241
-		$this->assertFalse($instance->UseCompressedAssets());
242
-
243
-		$instance = $this->getInstance();
244
-		Config::inst()->update('Mappable', 'use_compressed_assets', true);
245
-		$this->assertTrue($instance->UseCompressedAssets());
246
-
247
-		Config::inst()->update('Mappable', 'use_compressed_assets', $original);
248
-	}
249
-
250
-
251
-	private function getInstance() {
252
-		$instance = new Member();
253
-		return $instance;
254
-	}
255
-
256
-	/*
114
+    public function testHasGeoWest() {
115
+        $instance = $this->getInstance();
116
+        $instance->Lon = -20;
117
+        $this->assertTrue($instance->HasGeo());
118
+    }
119
+
120
+    public function testHasGeoEast() {
121
+        $instance = $this->getInstance();
122
+        $instance->Lon = 20;
123
+        $this->assertTrue($instance->HasGeo());
124
+    }
125
+
126
+    public function testHasGeoNorth() {
127
+        $instance = $this->getInstance();
128
+        $instance->Lat = 20;
129
+        $this->assertTrue($instance->HasGeo());
130
+    }
131
+
132
+    public function testHasGeoNorthWest() {
133
+        $instance = $this->getInstance();
134
+        $instance->Lat = 20;
135
+        $instance->Lon = -20;
136
+        $this->assertTrue($instance->HasGeo());
137
+    }
138
+
139
+    public function testHasGeoNortEast() {
140
+        $instance = $this->getInstance();
141
+        $instance->Lat = 20;
142
+        $instance->Lon = 20;
143
+        $this->assertTrue($instance->HasGeo());
144
+    }
145
+
146
+    public function testHasGeoSouth() {
147
+        $instance = $this->getInstance();
148
+        $instance->Lat = -20;
149
+        $this->assertTrue($instance->HasGeo());
150
+    }
151
+
152
+    public function testHasGeoSouthWest() {
153
+        $instance = $this->getInstance();
154
+        $instance->Lat = -20;
155
+        $instance->Lon = -20;
156
+        $this->assertTrue($instance->HasGeo());
157
+    }
158
+
159
+    public function testHasGeoSouthEast() {
160
+        $instance = $this->getInstance();
161
+        $instance->Lat = -20;
162
+        $instance->Lon = 20;
163
+        $this->assertTrue($instance->HasGeo());
164
+    }
165
+
166
+    public function testHasGeoOrigin() {
167
+        $instance = $this->getInstance();
168
+        $instance->Lat = 0;
169
+        $instance->Lon = 0;
170
+        $this->assertFalse($instance->HasGeo());
171
+    }
172
+
173
+    public function testHasGeoOriginMapLayerExtension() {
174
+        $instance = $this->getInstance();
175
+
176
+        // assert that origin has no geo (until layers added)
177
+        $instance->Lat = 0;
178
+        $instance->Lon = 0;
179
+        $this->assertFalse($instance->HasGeo());
180
+
181
+        $this->addLayerToInstance($instance);
182
+
183
+        // assert has geo even when at the origin of 0,0
184
+        $this->assertTrue($instance->HasGeo());
185
+    }
186
+
187
+    public function testBasicMap() {
188
+        $instance = $this->getInstance();
189
+        $instance->Lat = 37.1;
190
+        $instance->Lon = 28;
191
+        $instance->Zoom = 12;
192
+        $instance->MapPinEdited = true;
193
+        $html = $instance->BasicMap()->forTemplate();
194
+
195
+        $expected = "data-centre='{\"lat\":37.1,\"lng\":28}'";
196
+        $this->assertContains($expected, $html);
197
+        $expected = "data-mapmarkers='[{\"latitude\":37.1,\"longitude\":28,\"html\":\"MEMBER: \",\"category\":\"default\",\"icon\":false}]'";
198
+        $this->assertContains($expected, $html);
199
+
200
+        // This is only set automatically with layers
201
+        $expected = 'data-enableautocentrezoom=false';
202
+        $this->assertContains($expected, $html);
203
+    }
204
+
205
+    public function testBasicMapWithLayer() {
206
+        $instance = $this->getInstance();
207
+        $instance->Lat = 37.1;
208
+        $instance->Lon = 28;
209
+        $instance->Zoom = 12;
210
+        $instance->MapPinEdited = true;
211
+        $instance->write();
212
+        $this->addLayerToInstance($instance);
213
+        $html = $instance->BasicMap()->forTemplate();
214
+
215
+        $expected = "data-centre='{\"lat\":37.1,\"lng\":28}'";
216
+        $this->assertContains($expected, $html);
217
+        $expected = "data-mapmarkers='[{\"latitude\":37.1,\"longitude\":28,\"html\":\"MEMBER: \",\"category\":\"default\",\"icon\":false}]'";
218
+        $this->assertContains($expected, $html);
219
+
220
+        // This is only set automatically with layers
221
+        $expected = 'data-enableautocentrezoom=1';
222
+        $this->assertContains($expected, $html);
223
+    }
224
+
225
+
226
+    public function testGetMapField() {
227
+        $instance = $this->getInstance();
228
+        $this->Lat = 37.1;
229
+        $this->Lon = 28;
230
+        $this->Zoom = 12;
231
+        $mapField  = $instance->getMapField();
232
+        $this->assertInstanceOf('LatLongField', $mapField);
233
+    }
234
+
235
+
236
+    public function testUseCompressedAssets() {
237
+        $original = Config::inst()->get('Mappable', 'use_compressed_assets');
238
+
239
+        $instance = $this->getInstance();
240
+        Config::inst()->update('Mappable', 'use_compressed_assets', false);
241
+        $this->assertFalse($instance->UseCompressedAssets());
242
+
243
+        $instance = $this->getInstance();
244
+        Config::inst()->update('Mappable', 'use_compressed_assets', true);
245
+        $this->assertTrue($instance->UseCompressedAssets());
246
+
247
+        Config::inst()->update('Mappable', 'use_compressed_assets', $original);
248
+    }
249
+
250
+
251
+    private function getInstance() {
252
+        $instance = new Member();
253
+        return $instance;
254
+    }
255
+
256
+    /*
257 257
 	Add a map layer to an existing instance
258 258
 	 */
259
-	private function addLayerToInstance(&$instance) {
260
-		// Create a layer
261
-		$kmlFile = new File(array('Name' => 'example.kml', 'Filename' => 'mappable/tests/kml/example.kml'));
262
-		$layer = new MapLayer();
263
-		$layer->Title = 'Example KML Layer';
264
-		$layer->KmlFile = $kmlFile;
265
-		$layer->write();
266
-
267
-		// add the layer to the Member object
268
-		$layers = $instance->MapLayers();
269
-		$layers->add($layer);
270
-	}
271
-
272
-	private function addMapPinToInstance(&$instance) {
273
-		// Create a pin
274
-		$copied = copy('mappable/tests/images/mapicontest.png', 'assets/mapicontest.png');
275
-		$this->assertTrue($copied);
276
-		$imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'assets/mapicontest.png'));
277
-		$imageFile->write();
278
-		$instance->MapPinIconID = $imageFile->ID;
279
-		$instance->write();
280
-	}
281
-
282
-	/**
283
-	 * @param integer $lat
284
-	 * @param integer $lon
285
-	 */
286
-	private function showMapPinEdited(&$instance, $lat, $lon) {
287
-		$instance->Lat = $lat;
288
-		$instance->Long = $lon;
289
-		$instance->write();
290
-		$this->assertTrue($instance->MapPinEdited);
291
-	}
259
+    private function addLayerToInstance(&$instance) {
260
+        // Create a layer
261
+        $kmlFile = new File(array('Name' => 'example.kml', 'Filename' => 'mappable/tests/kml/example.kml'));
262
+        $layer = new MapLayer();
263
+        $layer->Title = 'Example KML Layer';
264
+        $layer->KmlFile = $kmlFile;
265
+        $layer->write();
266
+
267
+        // add the layer to the Member object
268
+        $layers = $instance->MapLayers();
269
+        $layers->add($layer);
270
+    }
271
+
272
+    private function addMapPinToInstance(&$instance) {
273
+        // Create a pin
274
+        $copied = copy('mappable/tests/images/mapicontest.png', 'assets/mapicontest.png');
275
+        $this->assertTrue($copied);
276
+        $imageFile = new Image(array('Name' => 'mapicontest.png', 'Filename' => 'assets/mapicontest.png'));
277
+        $imageFile->write();
278
+        $instance->MapPinIconID = $imageFile->ID;
279
+        $instance->write();
280
+    }
281
+
282
+    /**
283
+     * @param integer $lat
284
+     * @param integer $lon
285
+     */
286
+    private function showMapPinEdited(&$instance, $lat, $lon) {
287
+        $instance->Lat = $lat;
288
+        $instance->Long = $lon;
289
+        $instance->write();
290
+        $this->assertTrue($instance->MapPinEdited);
291
+    }
292 292
 
293 293
 
294 294
 
Please login to merge, or discard this patch.
code/MapField.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,19 +19,19 @@  discard block
 block discarded – undo
19 19
 			// legacy handling for old parameters: $title, $heading, ...
20 20
 			// instead of new handling: $name, $title, $heading, ...
21 21
 			$args = func_get_args();
22
-			if(!isset($args[1]) || is_numeric($args[1])) {
22
+			if (!isset($args[1]) || is_numeric($args[1])) {
23 23
 					$title = (isset($args[0])) ? $args[0] : null;
24 24
 					// Use "HeaderField(title)" as the default field name for a HeaderField;
25 25
 					// if it's just set to title then we risk causing accidental duplicate-field creation.
26 26
 
27 27
 					// this means i18nized fields won't be easily accessible through fieldByName()
28
-					$name = 'MapField' . $title;
28
+					$name = 'MapField'.$title;
29 29
 					$headingLevel = (isset($args[1])) ? $args[1] : null;
30 30
 					$allowHTML = (isset($args[2])) ? $args[2] : null;
31 31
 					$form = (isset($args[3])) ? $args[3] : null;
32 32
 			}
33 33
 
34
-			if($headingLevel) $this->headingLevel = $headingLevel;
34
+			if ($headingLevel) $this->headingLevel = $headingLevel;
35 35
 			$this->allowHTML = $allowHTML;
36 36
 			parent::__construct($name, $title, null, $allowHTML, $form);
37 37
 		}
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 
48 48
 				Requirements::css('mappable/css/mapField.css');
49 49
 
50
-				return '<div class="editableMap">' . $this->createTag(
50
+				return '<div class="editableMap">'.$this->createTag(
51 51
 						"div",
52 52
 						$attributes
53
-				) . '</div>';
53
+				).'</div>';
54 54
 		}
55 55
 }
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -4,52 +4,52 @@
 block discarded – undo
4 4
  */
5 5
 class MapField extends DatalessField {
6 6
 
7
-		/**
8
-		 * @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
9
-		 */
10
-		protected $headingLevel = 2;
11
-		private $divId;
7
+        /**
8
+         * @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2
9
+         */
10
+        protected $headingLevel = 2;
11
+        private $divId;
12 12
 
13
-		/**
14
-		 * @param string $name
15
-		 * @param string $title
16
-		 */
17
-		function __construct($name, $title = null, $headingLevel = 2, $allowHTML = false, $form = null) {
18
-			$this->divId = $name;
19
-			// legacy handling for old parameters: $title, $heading, ...
20
-			// instead of new handling: $name, $title, $heading, ...
21
-			$args = func_get_args();
22
-			if(!isset($args[1]) || is_numeric($args[1])) {
23
-					$title = (isset($args[0])) ? $args[0] : null;
24
-					// Use "HeaderField(title)" as the default field name for a HeaderField;
25
-					// if it's just set to title then we risk causing accidental duplicate-field creation.
13
+        /**
14
+         * @param string $name
15
+         * @param string $title
16
+         */
17
+        function __construct($name, $title = null, $headingLevel = 2, $allowHTML = false, $form = null) {
18
+            $this->divId = $name;
19
+            // legacy handling for old parameters: $title, $heading, ...
20
+            // instead of new handling: $name, $title, $heading, ...
21
+            $args = func_get_args();
22
+            if(!isset($args[1]) || is_numeric($args[1])) {
23
+                    $title = (isset($args[0])) ? $args[0] : null;
24
+                    // Use "HeaderField(title)" as the default field name for a HeaderField;
25
+                    // if it's just set to title then we risk causing accidental duplicate-field creation.
26 26
 
27
-					// this means i18nized fields won't be easily accessible through fieldByName()
28
-					$name = 'MapField' . $title;
29
-					$headingLevel = (isset($args[1])) ? $args[1] : null;
30
-					$allowHTML = (isset($args[2])) ? $args[2] : null;
31
-					$form = (isset($args[3])) ? $args[3] : null;
32
-			}
27
+                    // this means i18nized fields won't be easily accessible through fieldByName()
28
+                    $name = 'MapField' . $title;
29
+                    $headingLevel = (isset($args[1])) ? $args[1] : null;
30
+                    $allowHTML = (isset($args[2])) ? $args[2] : null;
31
+                    $form = (isset($args[3])) ? $args[3] : null;
32
+            }
33 33
 
34
-			if($headingLevel) $this->headingLevel = $headingLevel;
35
-			$this->allowHTML = $allowHTML;
36
-			parent::__construct($name, $title, null, $allowHTML, $form);
37
-		}
34
+            if($headingLevel) $this->headingLevel = $headingLevel;
35
+            $this->allowHTML = $allowHTML;
36
+            parent::__construct($name, $title, null, $allowHTML, $form);
37
+        }
38 38
 
39
-		function Field($properties = array()) {
40
-				Requirements::javascript('framework/thirdparty/jquery/jquery.js');
41
-				Requirements::javascript('framework/thirdparty/jquery-livequery/jquery.livequery.js');
42
-				$attributes = array(
43
-						'class' => 'middleColumn',
44
-						'id' => $this->divId,
45
-						'style' => "width:100%;height:300px;margin:5px 0px 5px 5px;position:relative;"
46
-				);
39
+        function Field($properties = array()) {
40
+                Requirements::javascript('framework/thirdparty/jquery/jquery.js');
41
+                Requirements::javascript('framework/thirdparty/jquery-livequery/jquery.livequery.js');
42
+                $attributes = array(
43
+                        'class' => 'middleColumn',
44
+                        'id' => $this->divId,
45
+                        'style' => "width:100%;height:300px;margin:5px 0px 5px 5px;position:relative;"
46
+                );
47 47
 
48
-				Requirements::css('mappable/css/mapField.css');
48
+                Requirements::css('mappable/css/mapField.css');
49 49
 
50
-				return '<div class="editableMap">' . $this->createTag(
51
-						"div",
52
-						$attributes
53
-				) . '</div>';
54
-		}
50
+                return '<div class="editableMap">' . $this->createTag(
51
+                        "div",
52
+                        $attributes
53
+                ) . '</div>';
54
+        }
55 55
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,9 @@
 block discarded – undo
31 31
 					$form = (isset($args[3])) ? $args[3] : null;
32 32
 			}
33 33
 
34
-			if($headingLevel) $this->headingLevel = $headingLevel;
34
+			if($headingLevel) {
35
+			    $this->headingLevel = $headingLevel;
36
+			}
35 37
 			$this->allowHTML = $allowHTML;
36 38
 			parent::__construct($name, $title, null, $allowHTML, $form);
37 39
 		}
Please login to merge, or discard this patch.
code/Mappable.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -9,58 +9,58 @@
 block discarded – undo
9 9
  */
10 10
 interface Mappable {
11 11
 
12
-	/**
13
-	 * An accessor method for the latitude field.
14
-	 * @example
15
-	 * <code>
16
-	 * 	return $this->Lat;
17
-	 * </code>
18
-	 *
19
-	 * @return string
20
-	 */
21
-	public function getMappableLatitude();
12
+    /**
13
+     * An accessor method for the latitude field.
14
+     * @example
15
+     * <code>
16
+     * 	return $this->Lat;
17
+     * </code>
18
+     *
19
+     * @return string
20
+     */
21
+    public function getMappableLatitude();
22 22
 
23 23
 
24
-	/**
25
-	 * An accessor method for the longitude field.
26
-	 * @example
27
-	 * <code>
28
-	 * 	return $this->Long;
29
-	 * </code>
30
-	 *
31
-	 * @return string
32
-	 */
33
-	public function getMappableLongitude();
24
+    /**
25
+     * An accessor method for the longitude field.
26
+     * @example
27
+     * <code>
28
+     * 	return $this->Long;
29
+     * </code>
30
+     *
31
+     * @return string
32
+     */
33
+    public function getMappableLongitude();
34 34
 
35 35
 
36
-	/**
37
-	 * An accessor method for the path to the marker pin for this point on the map.
38
-	 * If null or false, use the default Google Maps icon.
39
-	 * @example
40
-	 * <code>
41
-	 * return "mysite/images/map_icon.png";
42
-	 * </code>
43
-	 *
44
-	 * @return string
45
-	 */
46
-	public function getMappableMapPin();
36
+    /**
37
+     * An accessor method for the path to the marker pin for this point on the map.
38
+     * If null or false, use the default Google Maps icon.
39
+     * @example
40
+     * <code>
41
+     * return "mysite/images/map_icon.png";
42
+     * </code>
43
+     *
44
+     * @return string
45
+     */
46
+    public function getMappableMapPin();
47 47
 
48 48
 
49
-	/**
50
-	 * An accessor method that returns the content for the map bubble popup.
51
-	 * It is best to use the {@see ViewableData::renderWith()} method to take advantaging
52
-	 * of templating syntax when rendering the object's content.
53
-	 *
54
-	 * Note: it is critical that the content be sanitized for safe inclusino in the rendered
55
-	 * JavaScript code for the map. {@see GoogleMapsUtil::sanitize()}
56
-	 *
57
-	 * @example
58
-	 * <code>
59
-	 * return GoogleMapsUtil::sanitize($this->renderWith('MapBubble'));
60
-	 * </code>
61
-	 *
62
-	 * @return string
63
-	 */
64
-	public function getMappableMapContent();
49
+    /**
50
+     * An accessor method that returns the content for the map bubble popup.
51
+     * It is best to use the {@see ViewableData::renderWith()} method to take advantaging
52
+     * of templating syntax when rendering the object's content.
53
+     *
54
+     * Note: it is critical that the content be sanitized for safe inclusino in the rendered
55
+     * JavaScript code for the map. {@see GoogleMapsUtil::sanitize()}
56
+     *
57
+     * @example
58
+     * <code>
59
+     * return GoogleMapsUtil::sanitize($this->renderWith('MapBubble'));
60
+     * </code>
61
+     *
62
+     * @return string
63
+     */
64
+    public function getMappableMapContent();
65 65
 
66 66
 }
Please login to merge, or discard this patch.