1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
*@author nicolaas[at] sunnysideup.co.nz |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
**/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class GoogleMapBasic extends SiteTreeExtension |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
private static $db = array( |
|
|
|
|
13
|
|
|
'ShowMap' => 'Boolean', |
14
|
|
|
'StaticMap' => 'Boolean', |
15
|
|
|
'Address' => 'Text', |
16
|
|
|
'Lat' => 'Decimal(12,9)', |
17
|
|
|
'Lng' => 'Decimal(12,9)', |
18
|
|
|
'ZoomLevel' => 'Int', |
19
|
|
|
'InfoWindowContent' => 'HTMLText' |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
private static $include_in_classes = array(); |
|
|
|
|
24
|
|
|
|
25
|
|
|
private static $exclude_from_classes = array(); |
|
|
|
|
26
|
|
|
|
27
|
|
|
public function updateCMSFields(FieldList $fields) |
28
|
|
|
{ |
29
|
|
|
if ($this->canHaveMap()) { |
30
|
|
|
$reloadMessage = " "; |
31
|
|
|
if (!$this->owner->ShowMap) { |
|
|
|
|
32
|
|
|
$reloadMessage = " (save (and publish) to see additional options)"; |
33
|
|
|
} |
34
|
|
|
$fields->addFieldToTab("Root.Map", new CheckboxField("ShowMap", "Show map $reloadMessage")); |
35
|
|
|
if ($this->owner->ShowMap) { |
36
|
|
|
$fields->addFieldsToTab( |
37
|
|
|
"Root.Map", |
38
|
|
|
[ |
39
|
|
|
CheckboxField::create("StaticMap", "Show map as picture only"), |
40
|
|
|
TextField::create("Address"), |
41
|
|
|
NumericField::create("ZoomLevel", "Zoom (1 = world, 20 = too close)"), |
42
|
|
|
NumericField::create("Lat", "Latitude") |
43
|
|
|
->setRightTitle('Optional, use in conjunction with Longitude if address is not accurate enough.'), |
44
|
|
|
NumericField::create("Lng", "Longitude") |
45
|
|
|
->setRightTitle('Optional, use in conjunction with Latitude if address is not accurate enough.'), |
46
|
|
|
HtmlEditorField::create("InfoWindowContent", "Info Window Content")->setRows(5) |
47
|
|
|
] |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function canHaveMap() |
54
|
|
|
{ |
55
|
|
|
$include = Config::inst()->get("GoogleMapBasic", "include_in_classes"); |
56
|
|
|
$exclude = Config::inst()->get("GoogleMapBasic", "exclude_from_classes"); |
57
|
|
|
if (!is_array($exclude) || !is_array($include)) { |
58
|
|
|
user_error("include or exclude classes is NOT an array", E_USER_NOTICE); |
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
if (!count($include) && !count($exclude)) { |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
if (count($include) && in_array($this->owner->ClassName, $include)) { |
|
|
|
|
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
if (count($exclude) && !in_array($this->owner->ClassName, $exclude)) { |
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.