|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Adds functions to a Page_Controller |
|
5
|
|
|
* to action a map. |
|
6
|
|
|
* |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
class GoogleMapLocationsDOD_Controller extends Extension |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
##################### |
|
18
|
|
|
# INITS |
|
19
|
|
|
##################### |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @inherited |
|
23
|
|
|
*/ |
|
24
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
25
|
|
|
"AddressFinderForm", |
|
26
|
|
|
"doAddressFinderForm", |
|
27
|
|
|
"SearchByAddressForm", |
|
28
|
|
|
"loadmap" |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var GoogleMap |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $googleMap = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var String |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $googleMapAddress = ""; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* look for address |
|
43
|
|
|
* |
|
44
|
|
|
*/ |
|
45
|
|
|
public function onAfterInit() |
|
46
|
|
|
{ |
|
47
|
|
|
if (!$this->googleMapAddress && isset($_REQUEST["address"])) { |
|
48
|
|
|
$this->googleMapAddress = urldecode($_REQUEST["address"]); |
|
49
|
|
|
} |
|
50
|
|
|
if ($this->googleMapAddress) { |
|
51
|
|
|
$this->MyGoogleMap()->setAddress($this->googleMapAddress); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* initialise GoogleMap |
|
58
|
|
|
* @return GoogleMap |
|
59
|
|
|
*/ |
|
60
|
|
|
public function MyGoogleMap() |
|
61
|
|
|
{ |
|
62
|
|
|
if (!$this->googleMap) { |
|
63
|
|
|
$this->googleMap = Injector::inst()->get("GoogleMap"); |
|
64
|
|
|
} |
|
65
|
|
|
return $this->googleMap; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
##################### |
|
75
|
|
|
# ACTIONS |
|
76
|
|
|
##################### |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* provides a link to any map you like. |
|
81
|
|
|
* e.g. mysite.com/mypage/mysub-page/loadmap/optionsHereURLEncoded/ |
|
82
|
|
|
* optionsHereURLEncoded are basically the link to the map. |
|
83
|
|
|
* you can use this to link through to a page and provide a specific map |
|
84
|
|
|
* |
|
85
|
|
|
* @param HTTPRequest |
|
86
|
|
|
*/ |
|
87
|
|
|
public function loadmap($request) |
|
88
|
|
|
{ |
|
89
|
|
|
$link = urldecode($request->param("ID")); |
|
90
|
|
|
$options = explode("/", $link); |
|
91
|
|
|
$title = $options[3]; |
|
92
|
|
|
$this->owner->addMapUsingRawLink($title, $link); |
|
93
|
|
|
return array(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* returns encoded link for the loadmap function |
|
98
|
|
|
* |
|
99
|
|
|
* @param SiteTree $page |
|
|
|
|
|
|
100
|
|
|
* @param String $action |
|
101
|
|
|
* @param String $title |
|
102
|
|
|
* @param Int $lng |
|
103
|
|
|
* @param Int $lat |
|
104
|
|
|
* @param String $filterCode |
|
105
|
|
|
* |
|
106
|
|
|
* @return String |
|
107
|
|
|
*/ |
|
108
|
|
|
public function LoadmapLink($page = null, $action = "", $title = "", $lng = 0, $lat = 0, $filterCode = "") |
|
109
|
|
|
{ |
|
110
|
|
|
if (!$page) { |
|
111
|
|
|
$page = $this->owner->dataRecord; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
//todo: why not Convert::raw2js |
|
115
|
|
|
return urlencode($this->getLinkForData($page->ID, $action, $title, $lng, $lat, $filterCode)); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
##################### |
|
125
|
|
|
# TEMPLATE METHODS |
|
126
|
|
|
##################### |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return GoogleMap |
|
131
|
|
|
*/ |
|
132
|
|
|
public function GoogleMapController() |
|
133
|
|
|
{ |
|
134
|
|
|
$obj = $this->MyGoogleMap()->loadGoogleMap(); |
|
135
|
|
|
return $obj; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return Boolean |
|
140
|
|
|
*/ |
|
141
|
|
|
public function HasGoogleMap() |
|
142
|
|
|
{ |
|
143
|
|
|
if ($this->MyGoogleMap() && $this->owner->classHasGoogleMap()) { |
|
|
|
|
|
|
144
|
|
|
return true; |
|
145
|
|
|
} else { |
|
146
|
|
|
return false; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param array (optional) $classNamesSearchedFor e.g. StockistPage |
|
153
|
|
|
* |
|
154
|
|
|
* @return Form |
|
155
|
|
|
*/ |
|
156
|
|
|
public function AddressFinderForm($classNamesSearchedFor = array()) |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->SearchByAddressForm($classNamesSearchedFor); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function doAddressFinderForm($data, $form) |
|
|
|
|
|
|
162
|
|
|
{ |
|
163
|
|
|
return $this->redirect($this->owner->link('addresssearch').'?searchterm='.$data['searchterm']); |
|
|
|
|
|
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @param array (optional) $classNamesSearchedFor e.g. StockistPage |
|
169
|
|
|
* |
|
170
|
|
|
* @return Form |
|
171
|
|
|
*/ |
|
172
|
|
|
public function SearchByAddressForm($classNamesSearchedFor = array()) |
|
173
|
|
|
{ |
|
174
|
|
|
return SearchByAddressForm::create( |
|
175
|
|
|
$this->owner, |
|
176
|
|
|
"SearchByAddressForm", |
|
177
|
|
|
$this->googleMapAddress, |
|
178
|
|
|
$classNamesSearchedFor |
|
179
|
|
|
); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @param array (optional) $classNamesSearchedFor e.g. StockistPage |
|
184
|
|
|
* |
|
185
|
|
|
* @return Form |
|
|
|
|
|
|
186
|
|
|
*/ |
|
187
|
|
|
public function AddAddressFinder() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->MyGoogleMap()->AddAddressFinder(); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
##################### |
|
196
|
|
|
# CREATE MAPS |
|
197
|
|
|
##################### |
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* add a layer to a Google Map |
|
202
|
|
|
* |
|
203
|
|
|
* @param String $action - see GoogleMapDataResponse::allowed_actions to get a list of actions |
|
204
|
|
|
* @param String $title |
|
205
|
|
|
* @param float $lng - default LATITUDE |
|
|
|
|
|
|
206
|
|
|
* @param float $lat - default LONGITUDE |
|
|
|
|
|
|
207
|
|
|
* @param String $filterCode - can be a SiteTree class name, e.g. "ProductPage" |
|
208
|
|
|
* filter depends on the type of action |
|
209
|
|
|
* |
|
210
|
|
|
*/ |
|
211
|
|
|
public function addMap($action = "", $title = "", $lng = 0, $lat = 0, $filterCode = "") |
|
212
|
|
|
{ |
|
213
|
|
|
if (!$title) { |
|
214
|
|
|
$title = $this->owner->Title; |
|
215
|
|
|
} |
|
216
|
|
|
$allowedActions = Config::inst()->get("GoogleMapDataResponse", "allowed_actions"); |
|
217
|
|
|
if (isset($allowedActions[$action]) || in_array($action, $allowedActions)) { |
|
218
|
|
|
$title = str_replace('/', '', $title); |
|
219
|
|
|
$linkForData = $this->getLinkForData($this->owner->ID, $action, $title, $lng, $lat, $filterCode); |
|
220
|
|
|
//where the magic happens... |
|
221
|
|
|
$this->MyGoogleMap()->addLayer($linkForData, $title); |
|
222
|
|
|
} else { |
|
223
|
|
|
user_error("Could not find $action action in GoogleMapDataResponse", E_USER_NOTICE); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* add a layer to a Google Map |
|
229
|
|
|
* |
|
230
|
|
|
* @param String $action - see GoogleMapDataResponse::allowed_actions to get a list of actions |
|
|
|
|
|
|
231
|
|
|
* @param String $title |
|
232
|
|
|
* @param String $filterCode - can be a SiteTree class name, e.g. "ProductPage" |
|
233
|
|
|
* filter depends on the type of action |
|
234
|
|
|
* |
|
235
|
|
|
*/ |
|
236
|
|
|
public function addMapUsingRawLink($link = "", $title = "", $filterCode = "") |
|
|
|
|
|
|
237
|
|
|
{ |
|
238
|
|
|
if (!$title) { |
|
239
|
|
|
$title = $this->owner->Title; |
|
240
|
|
|
} |
|
241
|
|
|
$this->MyGoogleMap()->addLayer($link, $title); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* add an additional layer to an existing map |
|
246
|
|
|
* |
|
247
|
|
|
* @param String $action |
|
248
|
|
|
* @param String $title |
|
249
|
|
|
* @param Int $lng |
|
250
|
|
|
* @param Int $lat |
|
251
|
|
|
* @param String $filter |
|
252
|
|
|
*/ |
|
253
|
|
|
public function addExtraLayer($action = "", $title = "", $lng = 0, $lat = 0, $filter = "") |
|
254
|
|
|
{ |
|
255
|
|
|
$linkForData = $this->getLinkForData($this->owner->ID, $action, $title, $lng, $lat, $filter); |
|
256
|
|
|
$this->owner->addExtraLayersUsingRawLink($title, $linkForData); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Make up your own link and add this as a layer |
|
261
|
|
|
* |
|
262
|
|
|
* @param String $title |
|
263
|
|
|
* @param String $link |
|
264
|
|
|
*/ |
|
265
|
|
|
public function addExtraLayerUsingRawLink($title, $link) |
|
266
|
|
|
{ |
|
267
|
|
|
$this->MyGoogleMap()->addExtraLayer($title, $link); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* add an address to the map |
|
273
|
|
|
* |
|
274
|
|
|
* @param String $address |
|
275
|
|
|
* @param Boolean $addShowAroundAdress |
|
276
|
|
|
* @param String $filter - usually a SiteTree ClassName (e.g. ProductPage) |
|
277
|
|
|
* @param array $params - params for the Google Server |
|
278
|
|
|
*/ |
|
279
|
|
|
public function addAddress($address, $addShowAroundAdress = false, $filter = "", $params = []) |
|
280
|
|
|
{ |
|
281
|
|
|
if ($addShowAroundAdress) { |
|
282
|
|
|
$pointArray = GetLatLngFromGoogleUsingAddress::get_placemark_as_array($address, false, $params); |
|
283
|
|
|
if ($pointArray) { |
|
|
|
|
|
|
284
|
|
|
$title = $pointArray["FullAddress"]; |
|
285
|
|
|
$lng = $pointArray["Longitude"]; |
|
286
|
|
|
$lat = $pointArray["Latitude"]; |
|
287
|
|
|
$this->owner->addMap("showaroundmexml", $title, $lng, $lat, $filter); |
|
288
|
|
|
} |
|
289
|
|
|
} else { |
|
290
|
|
|
$this->owner->MyGoogleMap(); |
|
291
|
|
|
$this->googleMapAddress = $address; |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* @param DataList $pagesOrGoogleMapLocationsObjects |
|
299
|
|
|
* @param Boolean $retainOldSessionData |
|
300
|
|
|
* @param string $title |
|
301
|
|
|
* @param string $filterCode |
|
302
|
|
|
* |
|
303
|
|
|
* @param String $title |
|
304
|
|
|
*/ |
|
305
|
|
|
public function addCustomMap($pagesOrGoogleMapLocationsObjects, $retainOldSessionData = false, $title = '', $filterCode = "") |
|
306
|
|
|
{ |
|
307
|
|
|
$isGoogleMapLocationsObject = $pagesOrGoogleMapLocationsObjects->DataClass() == "GoogleMapLocationsObject" ? true : false; |
|
308
|
|
|
if (!$filterCode) { |
|
309
|
|
|
$filterCode = "" |
|
310
|
|
|
.$this->owner->ID."_" |
|
311
|
|
|
.($this->owner->request->param("Action") ? $this->owner->request->param("Action") : "index") |
|
312
|
|
|
.($this->owner->request->param("ID") ? $this->owner->request->param("ID") : 0); |
|
313
|
|
|
} |
|
314
|
|
|
if ($pagesOrGoogleMapLocationsObjects) { |
|
315
|
|
|
if (!$retainOldSessionData) { |
|
316
|
|
|
$addCustomGoogleMapArray = array(); |
|
317
|
|
|
$this->owner->clearCustomMaps($filterCode); |
|
318
|
|
|
} else { |
|
319
|
|
|
$addCustomGoogleMapArray = GoogleMapDataResponse::get_custom_google_map_session_data($filterCode); |
|
320
|
|
|
} |
|
321
|
|
|
foreach ($pagesOrGoogleMapLocationsObjects as $obj) { |
|
322
|
|
|
if (!$obj->ID) { |
|
323
|
|
|
user_error("Page provided to addCustomMap that does not have an ID", E_USER_ERROR); |
|
324
|
|
|
} |
|
325
|
|
|
$addCustomGoogleMapArray[$obj->ID] = $obj->ID; |
|
326
|
|
|
} |
|
327
|
|
|
} |
|
328
|
|
|
GoogleMapDataResponse::set_custom_google_map_session_data($addCustomGoogleMapArray, $filterCode); |
|
|
|
|
|
|
329
|
|
|
Session::save(); |
|
330
|
|
|
if ($isGoogleMapLocationsObject) { |
|
331
|
|
|
$fn = "showcustomdosmapxml"; |
|
332
|
|
|
} else { |
|
333
|
|
|
$fn = "showcustompagesmapxml"; |
|
334
|
|
|
} |
|
335
|
|
|
$this->owner->addMap($fn, $title, $lng = 0, $lat = 0, $filterCode); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
|
|
343
|
|
|
|
|
344
|
|
|
|
|
345
|
|
|
|
|
346
|
|
|
##################### |
|
347
|
|
|
# MAP SETTINGS |
|
348
|
|
|
##################### |
|
349
|
|
|
|
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @param String $updateServerUrlAddPoint |
|
353
|
|
|
*/ |
|
354
|
|
|
public function addUpdateServerUrlAddressSearchPoint($updateServerUrlAddPoint = "/googlemap/showaroundmexml/") |
|
355
|
|
|
{ |
|
356
|
|
|
$link = Controller::join_links($updateServerUrlAddPoint, $this->owner->ID); |
|
357
|
|
|
$this->MyGoogleMap()->setUpdateServerUrlAddressSearchPoint($link); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
/** |
|
361
|
|
|
* @param String $updateServerUrlDragend |
|
362
|
|
|
*/ |
|
363
|
|
|
public function addUpdateServerUrlDragend($updateServerUrlDragend = "googlemap/updatemexml/") |
|
|
|
|
|
|
364
|
|
|
{ |
|
365
|
|
|
$link = Controller::join_links($UpdateServerUrlDragend, $this->owner->ID); |
|
|
|
|
|
|
366
|
|
|
$this->MyGoogleMap()->setUpdateServerUrlDragend($link); |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* make the map editable |
|
371
|
|
|
*/ |
|
372
|
|
|
public function addAllowAddingAndDeletingPoints() |
|
373
|
|
|
{ |
|
374
|
|
|
$this->MyGoogleMap()->AllowAddPointsToMap(); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* removes user settings for map |
|
379
|
|
|
* a custom map is a bunch of points that are customised via a session |
|
380
|
|
|
* |
|
381
|
|
|
* @param string $filterCode |
|
382
|
|
|
*/ |
|
383
|
|
|
public function clearCustomMaps($filterCode = "") |
|
384
|
|
|
{ |
|
385
|
|
|
GoogleMapDataResponse::clear_custom_google_map_session_data($filterCode); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
|
|
389
|
|
|
/** |
|
390
|
|
|
* @param String $action |
|
391
|
|
|
* @param String $title |
|
392
|
|
|
* @param Int $lng |
|
393
|
|
|
* @param Int $lat |
|
394
|
|
|
* @param String $filter |
|
|
|
|
|
|
395
|
|
|
* |
|
396
|
|
|
* @return String |
|
397
|
|
|
*/ |
|
398
|
|
|
protected function getLinkForData($pageID = 0, $action = "", $title = "", $lng = 0, $lat = 0, $filterCode = "") |
|
399
|
|
|
{ |
|
400
|
|
|
if (!$pageID) { |
|
401
|
|
|
$pageID = $this->owner->ID; |
|
402
|
|
|
} |
|
403
|
|
|
$linkForData = "googlemap/".$action."/".$pageID."/".urlencode($title)."/"; |
|
404
|
|
|
if (($lng && $lat) || $filterCode) { |
|
405
|
|
|
$linkForData .= $lng."/".$lat."/"; |
|
406
|
|
|
} |
|
407
|
|
|
if ($filterCode) { |
|
408
|
|
|
$linkForData .= '?filtercode='.$filterCode; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
return $linkForData; |
|
412
|
|
|
} |
|
413
|
|
|
} |
|
414
|
|
|
|