1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Additions to Site Tree |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
class GoogleMapLocationsDOD extends SiteTreeExtension |
12
|
|
|
{ |
13
|
|
|
private static $db = array( |
14
|
|
|
"HasGeoInfo" => "Boolean" |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
private static $has_many = array( |
18
|
|
|
"GeoPoints" => "GoogleMapLocationsObject" |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* list of pages types without a map |
23
|
|
|
* @var Array |
24
|
|
|
*/ |
25
|
|
|
private static $page_classes_without_map = array(); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* list of pages types with a map |
29
|
|
|
* @var Array |
30
|
|
|
*/ |
31
|
|
|
private static $page_classes_with_map = array(); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param FieldList |
35
|
|
|
*/ |
36
|
|
|
public function updateCMSFields(FieldList $fields) |
37
|
|
|
{ |
38
|
|
|
if ($this->classHasGoogleMap()) { |
39
|
|
|
$fields->addFieldToTab("Root", new Tab("Map")); |
40
|
|
|
$fields->addFieldToTab( |
41
|
|
|
"Root.Map", |
42
|
|
|
$hasGeoInfoBox = CheckboxField::create( |
43
|
|
|
"HasGeoInfo", |
44
|
|
|
_t("GoogleMapLocationsDOD.HAS_ADDRESSES", "Has Address(es)?") |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
if (!$this->owner->HasGeoInfo) { |
48
|
|
|
$hasGeoInfoBox->setDescription( |
49
|
|
|
_t("GoogleMap.HasGeoInfoSTART", "tick and save this page to start data-entry ...") |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
if ($this->owner->HasGeoInfo) { |
53
|
|
|
$dataObject = new GoogleMapLocationsObject(); |
|
|
|
|
54
|
|
|
$source = $this->owner->GeoPoints(); |
55
|
|
|
$GeoPointsField = new GridField( |
56
|
|
|
"GeoPoints", |
57
|
|
|
"Locations", |
58
|
|
|
$source, |
59
|
|
|
GridFieldConfig_RelationEditor::create() |
60
|
|
|
); |
61
|
|
|
$fields->addFieldToTab("Root.Map", $GeoPointsField); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
return $fields; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* returns the HTML for a info window on a map for this page. |
69
|
|
|
* @return String (HTML) |
70
|
|
|
*/ |
71
|
|
|
public function AjaxInfoWindowLink() |
72
|
|
|
{ |
73
|
|
|
if ($this->owner->hasMethod("CustomAjaxInfoWindow")) { |
74
|
|
|
return $this->owner->CustomAjaxInfoWindow(); |
75
|
|
|
} |
76
|
|
|
if ($this->owner->hasMethod("ajaxinfowindowreturn")) { |
77
|
|
|
return '
|
78
|
|
|
<div class="viewMoreInformationHolder">
|
79
|
|
|
<a href="'.$this->owner->Link().'" onclick="return !loadAjaxInfoWindow(this,\''.$this->owner->Link().'ajaxinfowindowreturn/\');">'. Config::inst()->get("GoogleMap", "ajax_info_window_text") .'</a>
|
80
|
|
|
<div class="loadAjaxInfoWindowSpan"></div>
|
81
|
|
|
</div>'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Page Type has a Google Map |
87
|
|
|
* @return Boolean |
88
|
|
|
*/ |
89
|
|
|
public function ClassHasGoogleMap() |
90
|
|
|
{ |
91
|
|
|
//assumptions: |
92
|
|
|
//1. in general YES |
93
|
|
|
//2. if list of WITH is shown then it must be in that |
94
|
|
|
//3. otherwise check if it is specifically excluded (WITHOUT) |
95
|
|
|
$result = true; |
96
|
|
|
$inc = Config::inst()->get("GoogleMapLocationsDOD", "page_classes_with_map"); |
97
|
|
|
$exc = Config::inst()->get("GoogleMapLocationsDOD", "page_classes_without_map"); |
98
|
|
|
if (is_array($inc) && count($inc)) { |
99
|
|
|
$result = false; |
100
|
|
|
if (in_array($this->owner->ClassName, $inc)) { |
101
|
|
|
$result = true; |
102
|
|
|
} |
103
|
|
|
} elseif (is_array($exc) && count($exc) && in_array($this->owner->ClassName, $exc)) { |
104
|
|
|
$result = false; |
105
|
|
|
} |
106
|
|
|
return $result; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Recursively search children of current page to find a particular classtype |
111
|
|
|
* |
112
|
|
|
* @param $parentPage DataObject The Object of which you want to find the children |
113
|
|
|
* @param $classType String The text string to match `ClassName` field |
114
|
|
|
* |
115
|
|
|
* @return ArrayList of items if Class $classType |
116
|
|
|
*/ |
117
|
|
|
public function getChildrenOfType($parentPage, $classType = null) |
118
|
|
|
{ |
119
|
|
|
$children = $parentPage->AllChildren(); |
120
|
|
|
if (!isset($childrenOfType)) { |
|
|
|
|
121
|
|
|
$childrenOfType = new ArrayList(); |
122
|
|
|
} |
123
|
|
|
if ($children) { |
124
|
|
|
foreach ($children as $item) { |
125
|
|
|
$childrenOfType->merge($this->getChildrenOfType($item, $classType)); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
if ((isset($classType) && $CurrentPage->ClassName == $classType) || (!isset($classType))) { |
|
|
|
|
129
|
|
|
if ($parentPage->HasGeoInfo) { |
130
|
|
|
$childrenOfType->push($parentPage); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
return ($childrenOfType) ? $childrenOfType : new ArrayList(); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.