|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The way the map works is that you open a page, which loads the initial page |
|
5
|
|
|
* with the map points being loaded as a separate XML doc. |
|
6
|
|
|
* |
|
7
|
|
|
* This controller returns the Google Map data XML sheet |
|
8
|
|
|
* You can show one point by adding ?i=123 |
|
9
|
|
|
* Where 123 is the ID of a GoogleMapLocationsObject |
|
10
|
|
|
* |
|
11
|
|
|
* Here are other return options for the Map .... * |
|
12
|
|
|
* |
|
13
|
|
|
* 'index' / 'showemptymap' => map without anything on it, fallback |
|
14
|
|
|
* |
|
15
|
|
|
* 'showpagepointsmapxml' => show points from the current page |
|
16
|
|
|
* |
|
17
|
|
|
* 'showchildpointsmapxml' => show points from the child pages (all child pages) |
|
18
|
|
|
* |
|
19
|
|
|
* 'showdirectchildren' => show points from the child pages (direct ones only) |
|
20
|
|
|
* |
|
21
|
|
|
* 'showsearchpoint' => |
|
22
|
|
|
* |
|
23
|
|
|
* 'showcustompagesmapxml' => these are sitetree elements loaded by session |
|
24
|
|
|
* |
|
25
|
|
|
* 'showcustomdosmapxml' => |
|
26
|
|
|
* |
|
27
|
|
|
* 'showdataobjects' => |
|
28
|
|
|
* |
|
29
|
|
|
* 'updatemexml' => |
|
30
|
|
|
* |
|
31
|
|
|
* 'showaroundmexml' => |
|
32
|
|
|
* |
|
33
|
|
|
* 'showpointbyid' => can also be more than one ID |
|
34
|
|
|
* |
|
35
|
|
|
*/ |
|
36
|
|
|
|
|
37
|
|
|
class GoogleMapDataResponse extends Controller |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
private static $session_var_prefix = "addCustomGoogleMap"; |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* set searches in show around me to a specific max radius |
|
43
|
|
|
* @var int |
|
44
|
|
|
*/ |
|
45
|
|
|
private static $max_radius_for_show_around_me = 20000; |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Default URL handlers - (Action)/(ID)/(OtherID) |
|
49
|
|
|
*/ |
|
50
|
|
|
private static $url_handlers = array( |
|
|
|
|
|
|
51
|
|
|
'/$Action//$OwnerID/$Title/$Longitude/$Latitude/$FilterCode/$SecondFilterCode' => 'handleAction', |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
################# |
|
59
|
|
|
# SESSION MANAGEMENT |
|
60
|
|
|
################# |
|
61
|
|
|
|
|
62
|
|
|
protected static function session_var_name($filterCode = "") |
|
63
|
|
|
{ |
|
64
|
|
|
return Config::inst()->get("GoogleMapDataResponse", "session_var_prefix")."_".$filterCode; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param Array $addCustomGoogleMapArrayNEW |
|
69
|
|
|
* @param string $filterCode |
|
70
|
|
|
* |
|
71
|
|
|
*/ |
|
72
|
|
|
public static function add_custom_google_map_session_data($addCustomGoogleMapArrayNEW, $filterCode = "") |
|
73
|
|
|
{ |
|
74
|
|
|
$addCustomGoogleMapArrayOLD = Session::get(self::session_var_name($filterCode)); |
|
75
|
|
|
$addCustomGoogleMapArrayNEW = array_merge($addCustomGoogleMapArrayOLD, $addCustomGoogleMapArrayNEW); |
|
76
|
|
|
Session::set(Session::get(self::session_var_name($filterCode), serialize($addCustomGoogleMapArrayNEW))); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* |
|
81
|
|
|
* |
|
82
|
|
|
* @param Array $addCustomGoogleMapArray |
|
83
|
|
|
* @param string $filterCode |
|
84
|
|
|
* |
|
85
|
|
|
*/ |
|
86
|
|
|
public static function set_custom_google_map_session_data($addCustomGoogleMapArray, $filterCode = "") |
|
87
|
|
|
{ |
|
88
|
|
|
if (!is_array($addCustomGoogleMapArray)) { |
|
89
|
|
|
user_error("addCustomGoogleMapArray should be an array!"); |
|
90
|
|
|
} |
|
91
|
|
|
Session::set(self::session_var_name($filterCode), serialize($addCustomGoogleMapArray)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $filterCode |
|
96
|
|
|
* |
|
97
|
|
|
* @return Array |
|
98
|
|
|
*/ |
|
99
|
|
|
public static function get_custom_google_map_session_data($filterCode = "") |
|
100
|
|
|
{ |
|
101
|
|
|
$data = Session::get(self::session_var_name($filterCode)); |
|
102
|
|
|
if (is_array($data)) { |
|
103
|
|
|
$addCustomGoogleMapArray = $data; |
|
104
|
|
|
} else { |
|
105
|
|
|
try { |
|
106
|
|
|
$addCustomGoogleMapArray = unserialize($data); |
|
107
|
|
|
} catch (Exception $e) { |
|
108
|
|
|
$addCustomGoogleMapArray = array(); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
return $addCustomGoogleMapArray; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $filterCode |
|
117
|
|
|
*/ |
|
118
|
|
|
public static function clear_custom_google_map_session_data($filterCode = "") |
|
119
|
|
|
{ |
|
120
|
|
|
Session::clear(self::session_var_name($filterCode)); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
################# |
|
130
|
|
|
# BASICS |
|
131
|
|
|
################# |
|
132
|
|
|
/** |
|
133
|
|
|
* @inherited |
|
134
|
|
|
*/ |
|
135
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
136
|
|
|
'showemptymap' => true, |
|
137
|
|
|
'showpagepointsmapxml' => true, |
|
138
|
|
|
'showchildpointsmapxml' => true, |
|
139
|
|
|
'showdirectchildren' => true, |
|
140
|
|
|
'showsearchpoint' => true, |
|
141
|
|
|
'showcustompagesmapxml' => true, |
|
142
|
|
|
'showcustomdosmapxml' => true, |
|
143
|
|
|
'showdataobjects' => true, |
|
144
|
|
|
'updatemexml' => 'ADMIN', |
|
145
|
|
|
'showaroundmexml' => true, |
|
146
|
|
|
'showpointbyid' => true |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @var Array |
|
151
|
|
|
*/ |
|
152
|
|
|
private static $actions_without_owner = array( |
|
153
|
|
|
'showemptymap' |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* The Page that is displaying the |
|
158
|
|
|
* @var SiteTree |
|
159
|
|
|
*/ |
|
160
|
|
|
protected $owner = null; |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @var Float |
|
164
|
|
|
*/ |
|
165
|
|
|
protected $lng = 0; |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @var Float |
|
169
|
|
|
*/ |
|
170
|
|
|
protected $lat = 0; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @var String |
|
174
|
|
|
*/ |
|
175
|
|
|
protected $title = ""; |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @var String |
|
179
|
|
|
*/ |
|
180
|
|
|
protected $filterCode = ""; |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @var String |
|
184
|
|
|
*/ |
|
185
|
|
|
protected $secondFilterCode = ""; |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @var GoogleMap |
|
189
|
|
|
*/ |
|
190
|
|
|
protected $map = null; |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
################# |
|
203
|
|
|
# SET AND GET VARIABLES |
|
204
|
|
|
################# |
|
205
|
|
|
|
|
206
|
|
|
public function init() |
|
|
|
|
|
|
207
|
|
|
{ |
|
208
|
|
|
parent::init(); |
|
209
|
|
|
$id = 0; |
|
210
|
|
|
if ($this->request->param("OwnerID")) { |
|
211
|
|
|
$id = intval($this->request->param("OwnerID")); |
|
212
|
|
|
} elseif (isset($_GET["i"])) { |
|
213
|
|
|
$i = intval($_GET["i"]); |
|
214
|
|
|
$point = GoogleMapLocationsObject::get()->byID($i); |
|
215
|
|
|
if (!$point) { |
|
|
|
|
|
|
216
|
|
|
//New POINT |
|
217
|
|
|
} else { |
|
218
|
|
|
$id = $point->ParentID; |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
if ($id) { |
|
222
|
|
|
$this->owner = SiteTree::get()->byID($id); |
|
|
|
|
|
|
223
|
|
|
} |
|
224
|
|
|
//HACK |
|
225
|
|
|
elseif (!$this->owner) { |
|
226
|
|
|
$this->owner = DataObject::get_one( |
|
227
|
|
|
'SiteTree', |
|
228
|
|
|
array("Title" => Convert::raw2sql($this->request->param("Title"))) |
|
229
|
|
|
); |
|
230
|
|
|
} |
|
231
|
|
|
if ($this->owner || in_array($this->request->param("Action"), self::$actions_without_owner)) { |
|
|
|
|
|
|
232
|
|
|
//all ok |
|
233
|
|
|
} elseif (in_array($this->request->param("Action"), self::$actions_without_owner)) { |
|
234
|
|
|
//ok too |
|
235
|
|
|
$this->owner = DataObject::get_one('SiteTree'); |
|
236
|
|
|
} else { |
|
237
|
|
|
user_error("no owner has been identified for GoogleMapDataResponse", E_USER_NOTICE); |
|
238
|
|
|
} |
|
239
|
|
|
//END HACK |
|
240
|
|
|
$this->title = urldecode($this->request->param("Title")); |
|
241
|
|
|
$this->lng = floatval($this->request->param("Longitude")); |
|
242
|
|
|
$this->lat = floatval($this->request->param("Latitude")); |
|
243
|
|
|
$this->filterCode = urldecode($this->request->param("FilterCode")); |
|
244
|
|
|
$this->secondFilterCode = urldecode($this->request->param("SecondFilterCode")); |
|
245
|
|
|
if (!$this->title && $this->owner) { |
|
246
|
|
|
$this->title = $this->owner->Title; |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @param object $owner |
|
252
|
|
|
*/ |
|
253
|
|
|
public function setOwner($owner) |
|
254
|
|
|
{ |
|
255
|
|
|
$this->owner = $owner; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @param String $title |
|
260
|
|
|
*/ |
|
261
|
|
|
public function setTitle($title) |
|
262
|
|
|
{ |
|
263
|
|
|
$this->title = $title; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @param float $lng |
|
268
|
|
|
*/ |
|
269
|
|
|
public function setLng($lng) |
|
270
|
|
|
{ |
|
271
|
|
|
$this->lng = $lng; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* @param Float $lat |
|
276
|
|
|
*/ |
|
277
|
|
|
public function setLat($lat) |
|
278
|
|
|
{ |
|
279
|
|
|
$this->lat = $lat; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @param string $filterCode |
|
284
|
|
|
*/ |
|
285
|
|
|
public function setFilterCode($filterCode) |
|
286
|
|
|
{ |
|
287
|
|
|
$this->filterCode = $filterCode; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
|
|
298
|
|
|
|
|
299
|
|
|
|
|
300
|
|
|
################# |
|
301
|
|
|
# ACTIONS |
|
302
|
|
|
################# |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* @param SS_HTTPRequest |
|
306
|
|
|
* |
|
307
|
|
|
* @return String (XML) |
|
308
|
|
|
*/ |
|
309
|
|
|
public function index($request) |
|
310
|
|
|
{ |
|
311
|
|
|
return $this->showemptymap($request); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @param SS_HTTPRequest |
|
316
|
|
|
* |
|
317
|
|
|
* @return String (XML) |
|
318
|
|
|
*/ |
|
319
|
|
|
public function showemptymap($request) |
|
|
|
|
|
|
320
|
|
|
{ |
|
321
|
|
|
return $this->makeXMLData(null, null, $this->title, $this->title." "._t("GoogleMap.MAP", "map")); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/** |
|
325
|
|
|
* @param SS_HTTPRequest |
|
326
|
|
|
* |
|
327
|
|
|
* @return String (XML) |
|
328
|
|
|
*/ |
|
329
|
|
View Code Duplication |
public function showpagepointsmapxml($request) |
|
|
|
|
|
|
330
|
|
|
{ |
|
331
|
|
|
$data = GoogleMapLocationsObject::get()->filter(array("ParentID" => $this->owner->ID)); |
|
332
|
|
|
if ($data->count()) { |
|
333
|
|
|
return $this->makeXMLData(null, $data, $this->title, $this->title." "._t("GoogleMap.MAP", "map")); |
|
334
|
|
|
} |
|
335
|
|
|
return $this->showemptymap($request); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* @param SS_HTTPRequest |
|
340
|
|
|
* |
|
341
|
|
|
* @return String (XML) |
|
342
|
|
|
*/ |
|
343
|
|
View Code Duplication |
public function showchildpointsmapxml($request) |
|
|
|
|
|
|
344
|
|
|
{ |
|
345
|
|
|
if ($children = $this->owner->getChildrenOfType($this->owner, null)) { |
|
346
|
|
|
return $this->makeXMLData($children, null, $this->title, $this->title." "._t("GoogleMap.MAP", "map")); |
|
347
|
|
|
} |
|
348
|
|
|
return $this->showemptymap($request); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @param SS_HTTPRequest |
|
353
|
|
|
* |
|
354
|
|
|
* @return String (XML) |
|
355
|
|
|
*/ |
|
356
|
|
|
public function showdirectchildren($request) |
|
357
|
|
|
{ |
|
358
|
|
|
if ($children = Provider::get()) { |
|
359
|
|
|
return $this->makeXMLData($children, null, $this->title, $this->title." "._t("GoogleMap.MAP", "map")); |
|
360
|
|
|
} |
|
361
|
|
|
return $this->showemptymap($request); |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
/** |
|
365
|
|
|
* @param SS_HTTPRequest |
|
366
|
|
|
* |
|
367
|
|
|
* @return String (XML) |
|
|
|
|
|
|
368
|
|
|
*/ |
|
369
|
|
|
public function showsearchpoint($request) |
|
370
|
|
|
{ |
|
371
|
|
|
if ($this->lat && $this->lng) { |
|
372
|
|
|
$point = GoogleMapLocationsObject::create(); |
|
373
|
|
|
$point->ParentID = $this->owner->ID; |
|
|
|
|
|
|
374
|
|
|
$point->Latitude = $this->lat; |
|
|
|
|
|
|
375
|
|
|
$point->Longitude = $this->lng; |
|
|
|
|
|
|
376
|
|
|
$point->CustomPopUpWindowTitle = $this->title; |
|
|
|
|
|
|
377
|
|
|
if ($this->address) { |
|
|
|
|
|
|
378
|
|
|
die("get address to do"); |
|
|
|
|
|
|
379
|
|
|
$point->CustomPopUpWindowInfo = $this->address; |
|
|
|
|
|
|
380
|
|
|
} |
|
381
|
|
|
if ($point) { |
|
382
|
|
|
$data = new ArrayList(); |
|
383
|
|
|
$data->push($point); |
|
384
|
|
|
return $this->makeXMLData(null, $data, $this->title, $this->title); |
|
|
|
|
|
|
385
|
|
|
} |
|
386
|
|
|
} |
|
387
|
|
|
return $this->showemptymap($request); |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* @param SS_HTTPRequest |
|
392
|
|
|
* |
|
393
|
|
|
* @return String (XML) |
|
394
|
|
|
*/ |
|
395
|
|
|
public function showpointbyid($request) |
|
396
|
|
|
{ |
|
397
|
|
|
$id = $request->param("FilterCode"); |
|
398
|
|
|
$ids = explode(',', $id); |
|
399
|
|
|
foreach ($ids as $key => $id) { |
|
400
|
|
|
$ids[$key] = intval($id); |
|
401
|
|
|
} |
|
402
|
|
|
$className = Convert::raw2sql($request->param("SecondFilterCode")); |
|
403
|
|
|
$direct = false; |
|
404
|
|
|
if (! $className) { |
|
405
|
|
|
$direct = true; |
|
406
|
|
|
} elseif (! class_exists($className)) { |
|
407
|
|
|
$direct = true; |
|
408
|
|
|
} |
|
409
|
|
|
if ($direct) { |
|
410
|
|
|
$className = "GoogleMapLocationsObject"; |
|
411
|
|
|
} |
|
412
|
|
|
$objects = $className::get()->filter(array("ID" => $ids)); |
|
413
|
|
|
if ($direct) { |
|
414
|
|
|
return $this->makeXMLData(null, $objects, $this->title, $this->title); |
|
415
|
|
|
} else { |
|
416
|
|
|
return $this->makeXMLData($objects, null, $this->title, $this->title); |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* load data from session |
|
423
|
|
|
* |
|
424
|
|
|
* @param SS_HTTPRequest |
|
425
|
|
|
* |
|
426
|
|
|
* @return String (XML) |
|
427
|
|
|
*/ |
|
428
|
|
|
public function showcustompagesmapxml($request) |
|
|
|
|
|
|
429
|
|
|
{ |
|
430
|
|
|
$addCustomGoogleMapArray = GoogleMapDataResponse::get_custom_google_map_session_data($this->filterCode); |
|
431
|
|
|
$pages = SiteTree::get()->filter(array("ID" => $addCustomGoogleMapArray)); |
|
432
|
|
|
return $this->makeXMLData($pages, null, $this->title, $this->title); |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
/** |
|
436
|
|
|
* load a custom set of GoogleMapLocationsObjects |
|
437
|
|
|
* |
|
438
|
|
|
* @param SS_HTTPRequest |
|
439
|
|
|
* |
|
440
|
|
|
* @return String (XML) |
|
441
|
|
|
*/ |
|
442
|
|
|
public function showcustomdosmapxml($request) |
|
|
|
|
|
|
443
|
|
|
{ |
|
444
|
|
|
$array = GoogleMapDataResponse::get_custom_google_map_session_data($this->filterCode); |
|
445
|
|
|
$googleMapLocationsObjects = GoogleMapLocationsObject::get()->filter(array("ID" => $array)); |
|
446
|
|
|
return $this->makeXMLData(null, $googleMapLocationsObjects, $this->title, $this->title); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* Show what is around my points |
|
451
|
|
|
* |
|
452
|
|
|
* @param SS_HTTPRequest |
|
453
|
|
|
* |
|
454
|
|
|
* @return String (XML) |
|
455
|
|
|
*/ |
|
456
|
|
|
public function showaroundmexml($request) |
|
|
|
|
|
|
457
|
|
|
{ |
|
458
|
|
|
$lng = 0; |
|
459
|
|
|
$lat = 0; |
|
460
|
|
|
$maxRadius = intval($this->Config()->get('max_radius_for_show_around_me')) - 0; |
|
461
|
|
|
if (isset($_GET['maxradius'])) { |
|
462
|
|
|
$maxRadius = intval($_GET['maxradius']); |
|
463
|
|
|
} |
|
464
|
|
|
$excludeIDList = array(); |
|
465
|
|
|
$stage = ''; |
|
466
|
|
|
if (Versioned::current_stage() == "Live") { |
|
467
|
|
|
$stage = "_Live"; |
|
468
|
|
|
} |
|
469
|
|
|
if ($this->lng && $this->lat) { |
|
470
|
|
|
$lng = $this->lng; |
|
471
|
|
|
$lat = $this->lat; |
|
472
|
|
|
} elseif ($this->owner->ID) { |
|
473
|
|
|
//find the average! |
|
474
|
|
|
$objects = GoogleMapLocationsObject::get()->filter(array("ParentID" => $this->owner->ID)); |
|
475
|
|
|
if ($count = $objects->count()) { |
|
476
|
|
|
foreach ($objects as $point) { |
|
477
|
|
|
$lng += $point->Longitude; |
|
478
|
|
|
$lat += $point->Latitude; |
|
479
|
|
|
} |
|
480
|
|
|
$lng = $lng / $count; |
|
481
|
|
|
$lat = $lat / $count; |
|
482
|
|
|
} |
|
483
|
|
|
} |
|
484
|
|
|
$classNameForParent = ''; |
|
485
|
|
|
if ($otherClass = $this->filterCode) { |
|
486
|
|
|
$classNameForParent = $otherClass; |
|
487
|
|
|
} |
|
488
|
|
|
if ($this->title) { |
|
489
|
|
|
$title = $this->title; |
|
490
|
|
|
} else { |
|
491
|
|
|
$title = _t("GoogleMap.CLOSES_TO_ME", "Closest to me"); |
|
492
|
|
|
} |
|
493
|
|
|
if ($lng && $lat) { |
|
494
|
|
|
$orderByRadius = GoogleMapLocationsObject::radius_definition($lng, $lat); |
|
495
|
|
|
$where = "(".$orderByRadius.") > 0 (".$orderByRadius.") < ".$maxRadius." AND \"GoogleMapLocationsObject\".\"Latitude\" <> 0 AND \"GoogleMapLocationsObject\".\"Longitude\" <> 0"; |
|
496
|
|
|
if ($classNameForParent && !is_object($classNameForParent)) { |
|
497
|
|
|
$where .= " AND \"SiteTree".$stage."\".\"ClassName\" = '".$classNameForParent."'"; |
|
498
|
|
|
} |
|
499
|
|
|
if (count($excludeIDList)) { |
|
500
|
|
|
$where .= " AND \"GoogleMapLocationsObject\".\"ID\" NOT IN (".implode(",", $excludeIDList).") "; |
|
501
|
|
|
} |
|
502
|
|
|
$objects = GoogleMapLocationsObject::get() |
|
503
|
|
|
->where($where) |
|
504
|
|
|
->sort($orderByRadius) |
|
505
|
|
|
->leftJoin("SiteTree".$stage."", "SiteTree".$stage.".ID = GoogleMapLocationsObject.ParentID") |
|
506
|
|
|
->limit(Config::inst()->get("GoogleMap", "number_shown_in_around_me")); |
|
507
|
|
|
if ($objects->count()) { |
|
508
|
|
|
return $this->makeXMLData( |
|
509
|
|
|
null, |
|
510
|
|
|
$objects, |
|
511
|
|
|
$title, |
|
512
|
|
|
Config::inst()->get("GoogleMap", "number_shown_in_around_me") . " "._t("GoogleMap.CLOSEST_POINTS", "closest points") |
|
513
|
|
|
); |
|
514
|
|
|
} |
|
515
|
|
|
} |
|
516
|
|
|
return $this->showemptymap($request); |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
/** |
|
520
|
|
|
* URL must contain for GET variables |
|
521
|
|
|
* i - ID of owner |
|
522
|
|
|
* a - action |
|
523
|
|
|
* x - lng |
|
524
|
|
|
* y - lat |
|
525
|
|
|
* |
|
526
|
|
|
* actions are: |
|
527
|
|
|
* - add |
|
528
|
|
|
* - move |
|
529
|
|
|
* - remove |
|
530
|
|
|
* |
|
531
|
|
|
* @param SS_HTTPRequest |
|
532
|
|
|
* |
|
533
|
|
|
* @return String (message) |
|
|
|
|
|
|
534
|
|
|
*/ |
|
535
|
|
|
public function updatemexml($request) |
|
|
|
|
|
|
536
|
|
|
{ |
|
537
|
|
|
//we use request here, because the data comes from javascript! |
|
538
|
|
|
if ($this->owner->canEdit()) { |
|
539
|
|
|
if (isset($_REQUEST["x"]) && isset($_REQUEST["y"]) && isset($_REQUEST["i"]) && isset($_REQUEST["a"])) { |
|
540
|
|
|
$lng = floatval($_REQUEST["x"]); |
|
541
|
|
|
$lat = floatval($_REQUEST["y"]); |
|
542
|
|
|
$id = intval($_REQUEST["i"]); |
|
543
|
|
|
$action = $_REQUEST["a"]; |
|
544
|
|
|
if ($lng && $lat) { |
|
545
|
|
|
if (0 == $id && "add" == $action) { |
|
546
|
|
|
$point = new GoogleMapLocationsObject; |
|
547
|
|
|
$point->ParentID = $this->owner->ID; |
|
|
|
|
|
|
548
|
|
|
$point->Longitude = $lng; |
|
|
|
|
|
|
549
|
|
|
$point->Latitude = $lat; |
|
|
|
|
|
|
550
|
|
|
$point->write(); |
|
551
|
|
|
return $point->ID; |
|
552
|
|
|
} elseif ($id > 0 && "move" == $action) { |
|
553
|
|
|
$point = GoogleMapLocationsObject::get()->byID($id); |
|
554
|
|
|
if ($point) { |
|
555
|
|
|
if ($point->ParentID == $this->owner->ID) { |
|
556
|
|
|
$point->Longitude = $lng; |
|
557
|
|
|
$point->Latitude = $lat; |
|
558
|
|
|
$point->Address = ""; |
|
559
|
|
|
$point->FullAddress = ""; |
|
560
|
|
|
$point->write(); |
|
561
|
|
|
return _t("GoogleMap.LOCATION_UPDATED", "location updated"); |
|
562
|
|
|
} else { |
|
563
|
|
|
return _t("GoogleMap.NO_PERMISSION_TO_UPDATE", "you dont have permission to update that location"); |
|
564
|
|
|
} |
|
565
|
|
|
} else { |
|
566
|
|
|
return _t("GoogleMap.COULD_NOT_FIND_LOCATION", "could not find location"); |
|
567
|
|
|
} |
|
568
|
|
|
} elseif ($id && "remove" == $action) { |
|
569
|
|
|
$point = GoogleMapLocationsObject::get()->byID($id); |
|
570
|
|
|
if ($point) { |
|
571
|
|
|
if ($point->ParentID == $this->owner->ID) { |
|
572
|
|
|
$point->delete(); |
|
573
|
|
|
$point = null; |
|
|
|
|
|
|
574
|
|
|
return _t("GoogleMap.LOCATION_DELETED", "location deleted"); |
|
575
|
|
|
} else { |
|
576
|
|
|
return _t("GoogleMap.NO_DELETE_PERMISSION", "you dont have permission to delete that location"); |
|
577
|
|
|
} |
|
578
|
|
|
} else { |
|
579
|
|
|
return _t("GoogleMap.COULD_NOT_FIND_LOCATION", "could not find location."); |
|
580
|
|
|
} |
|
581
|
|
|
} |
|
582
|
|
|
} else { |
|
583
|
|
|
return _t("GoogleMap.LOCATION_NOT_DEFINED", "point not defined."); |
|
584
|
|
|
} |
|
585
|
|
|
} else { |
|
586
|
|
|
return _t("GoogleMap.MISSING_VARIABLES", "not enough information was provided."); |
|
587
|
|
|
} |
|
588
|
|
|
} |
|
589
|
|
|
return _t("GoogleMap.POINT_NOT_UPDATED", "You do not have permission to change the map."); |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
|
|
593
|
|
|
|
|
594
|
|
|
|
|
595
|
|
|
|
|
596
|
|
|
|
|
597
|
|
|
|
|
598
|
|
|
################# |
|
599
|
|
|
# TEMPLATE METHODS |
|
600
|
|
|
################# |
|
601
|
|
|
/** |
|
602
|
|
|
* |
|
603
|
|
|
* @return GoogleMap |
|
604
|
|
|
*/ |
|
605
|
|
|
public function GoogleMapController() |
|
606
|
|
|
{ |
|
607
|
|
|
if (!$this->map) { |
|
608
|
|
|
user_error("No map has been created"); |
|
609
|
|
|
} |
|
610
|
|
|
return $this->map; |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
|
|
614
|
|
|
|
|
615
|
|
|
|
|
616
|
|
|
|
|
617
|
|
|
|
|
618
|
|
|
|
|
619
|
|
|
|
|
620
|
|
|
################# |
|
621
|
|
|
# PRIVATE PARTY |
|
622
|
|
|
################# |
|
623
|
|
|
|
|
624
|
|
|
/** |
|
625
|
|
|
* @param DataList $pages |
|
|
|
|
|
|
626
|
|
|
* @param DataList $dataPoints |
|
|
|
|
|
|
627
|
|
|
* @param string $title |
|
628
|
|
|
* @param string $selectionStatement |
|
629
|
|
|
* |
|
630
|
|
|
* @return String (XML) |
|
631
|
|
|
*/ |
|
632
|
|
|
protected function makeXMLData( |
|
633
|
|
|
$pages = null, |
|
634
|
|
|
$dataPoints = null, |
|
635
|
|
|
$title = '', |
|
636
|
|
|
$selectionStatement = '' |
|
|
|
|
|
|
637
|
|
|
) { |
|
638
|
|
|
$this->response->addHeader("Content-Type", "text/xml; charset=\"utf-8\""); |
|
639
|
|
|
return self::xml_sheet( |
|
640
|
|
|
$pages, |
|
641
|
|
|
$dataPoints, |
|
642
|
|
|
$title, |
|
643
|
|
|
$selectionStatement = '' |
|
644
|
|
|
); |
|
645
|
|
|
} |
|
646
|
|
|
|
|
647
|
|
|
|
|
648
|
|
|
|
|
649
|
|
|
################################ |
|
650
|
|
|
# STATIC METHODS |
|
651
|
|
|
################################ |
|
652
|
|
|
|
|
653
|
|
|
public static function xml_sheet( |
|
|
|
|
|
|
654
|
|
|
$pages = null, |
|
655
|
|
|
$dataPoints = null, |
|
656
|
|
|
$title = '', |
|
657
|
|
|
$selectionStatement = '' |
|
658
|
|
|
) { |
|
659
|
|
|
$map = Injector::inst()->get("GoogleMap"); |
|
660
|
|
|
$map->setTitleOfMap($title); |
|
661
|
|
|
$map->setWhereStatementDescription($selectionStatement ? $selectionStatement : $title); |
|
662
|
|
|
if ($pages) { |
|
663
|
|
|
$map->setPageDataObjectSet($pages); |
|
664
|
|
|
} elseif ($dataPoints) { |
|
665
|
|
|
$map->setPoints($dataPoints); |
|
666
|
|
|
} |
|
667
|
|
|
$map->createDataPoints(); |
|
668
|
|
|
return $map->renderWith("GoogleMapXml"); |
|
669
|
|
|
} |
|
670
|
|
|
|
|
671
|
|
|
|
|
672
|
|
|
|
|
673
|
|
|
/** |
|
674
|
|
|
* var arrayOfLatitudeAndLongitude: Array (Latitude" => 123, "Longitude" => 123, "Marker" => "red1"); |
|
675
|
|
|
* Marker is optional |
|
676
|
|
|
* @param Array arrayOfLatitudeAndLongitude |
|
677
|
|
|
* @param String title |
|
678
|
|
|
* |
|
679
|
|
|
* @return String (HTML - img tag) |
|
680
|
|
|
*/ |
|
681
|
|
|
|
|
682
|
|
|
public static function quick_static_map($arrayOfLatitudeAndLongitude, $title) |
|
683
|
|
|
{ |
|
684
|
|
|
$staticMapURL = ''; |
|
|
|
|
|
|
685
|
|
|
$count = 0; |
|
686
|
|
|
//width |
|
687
|
|
|
$staticMapWidth = Config::inst()->get("GoogleMap", "google_map_width"); |
|
688
|
|
|
if ($staticMapWidth > 512) { |
|
689
|
|
|
$staticMapWidth = 512; |
|
690
|
|
|
} |
|
691
|
|
|
//height |
|
692
|
|
|
$staticMapHeight = Config::inst()->get("GoogleMap", "google_map_height"); |
|
693
|
|
|
if ($staticMapHeight > 512) { |
|
694
|
|
|
$staticMapHeight = 512; |
|
695
|
|
|
} |
|
696
|
|
|
$staticMapURL = "size=".$staticMapWidth."x".$staticMapHeight; |
|
697
|
|
|
if (count($arrayOfLatitudeAndLongitude)) { |
|
698
|
|
|
//http://maps.google.com/maps/api/staticmap?sensor=true&maptype=map&size=209x310& |
|
699
|
|
|
//markers=color:green%7Clabel:A%7C-45.0302,168.663 |
|
700
|
|
|
//&markers=color:red%7Clabel:Q%7C-36.8667,174.767 |
|
|
|
|
|
|
701
|
|
|
foreach ($arrayOfLatitudeAndLongitude as $row) { |
|
702
|
|
|
$staticMapURL .= '&markers=color:'.$row["Colour"].'%7Clabel:'.$row["Label"].'%7C'; |
|
703
|
|
|
$staticMapURL .= round($row["Latitude"], 6).",".round($row["Longitude"], 6); |
|
704
|
|
|
$count++; |
|
705
|
|
|
} |
|
706
|
|
|
if ($count == 1) { |
|
707
|
|
|
$staticMapURL .= '&center='.$defaultCenter.'&zoom='. Config::inst()->get("GoogleMap", "default_zoom"); |
|
|
|
|
|
|
708
|
|
|
} |
|
709
|
|
|
} |
|
710
|
|
|
return self::make_static_map_url_into_image($staticMapURL, $title); |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
|
|
/** |
|
714
|
|
|
* @param String $staticMapURL |
|
715
|
|
|
* @param String $title |
|
716
|
|
|
* |
|
717
|
|
|
* @return String (HTML - img tag) |
|
718
|
|
|
*/ |
|
719
|
|
|
protected static function make_static_map_url_into_image($staticMapURL, $title) |
|
720
|
|
|
{ |
|
721
|
|
|
$fullStaticMapURL = |
|
722
|
|
|
'http://maps.google.com/maps/api/staticmap?' |
|
723
|
|
|
.Config::inst()->get("GoogleMap", "static_map_settings").'&' |
|
724
|
|
|
.$staticMapURL.'&' |
|
725
|
|
|
.'key='.Config::inst()->get("GoogleMap", "google_map_api_key"); |
|
726
|
|
|
if (Config::inst()->get("GoogleMap", "save_static_map_locally")) { |
|
727
|
|
|
$fileName = str_replace(array('&', '|', ',', '=', ';'), array('', '', '', '', ''), $staticMapURL); |
|
728
|
|
|
$length = strlen($fileName); |
|
729
|
|
|
$fileName = "_sGMap".substr(hash("md5", $fileName), 0, 35)."_".$length.".gif"; |
|
730
|
|
|
$fullStaticMapURL = StaticMapSaverForHTTPS::convert_to_local_file(str_replace('&', '&', $fullStaticMapURL), $fileName); |
|
731
|
|
|
} |
|
732
|
|
|
return '<img class="staticGoogleMap" src="'.$fullStaticMapURL.'" alt="map: '.Convert::raw2att($title).'" />'; |
|
733
|
|
|
} |
|
734
|
|
|
} |
|
735
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.