@@ -2,146 +2,146 @@ discard block |
||
2 | 2 | |
3 | 3 | class Locator extends Page |
4 | 4 | { |
5 | - private static $db = array( |
|
6 | - 'AutoGeocode' => 'Boolean', |
|
7 | - 'ModalWindow' => 'Boolean', |
|
8 | - 'Unit' => 'Enum("m,km","m")', |
|
9 | - ); |
|
10 | - |
|
11 | - private static $many_many = array( |
|
12 | - 'Categories' => 'LocationCategory', |
|
13 | - ); |
|
14 | - |
|
15 | - private static $defaults = array( |
|
16 | - 'AutoGeocode' => true, |
|
17 | - ); |
|
18 | - |
|
19 | - private static $singular_name = 'Locator'; |
|
20 | - private static $plural_name = 'Locators'; |
|
21 | - private static $description = 'Find locations on a map'; |
|
22 | - |
|
23 | - public function getCMSFields() |
|
24 | - { |
|
25 | - $fields = parent::getCMSFields(); |
|
26 | - |
|
27 | - // Settings |
|
28 | - $fields->addFieldsToTab('Root.Settings', array( |
|
29 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
30 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
31 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
32 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
33 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
34 | - )); |
|
35 | - |
|
36 | - // Filter categories |
|
37 | - $config = GridFieldConfig_RelationEditor::create(); |
|
38 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
39 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
40 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
41 | - } |
|
42 | - $categories = $this->Categories(); |
|
43 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
44 | - ->setDescription('only show locations from the selected category'); |
|
45 | - |
|
46 | - // Filter |
|
47 | - $fields->addFieldsToTab('Root.Filter', array( |
|
48 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
49 | - $categoriesField, |
|
50 | - )); |
|
51 | - |
|
52 | - $this->extend('updateCMSFields', $fields); |
|
53 | - |
|
54 | - return $fields; |
|
55 | - } |
|
56 | - |
|
57 | - public static function getLocations($filter = array(), $exclude = array(), $filterAny = array()) |
|
58 | - { |
|
59 | - $filter['ShowInLocator'] = true; |
|
60 | - $exclude['Lat'] = 0; |
|
61 | - |
|
62 | - $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny); |
|
63 | - |
|
64 | - return $Locations; |
|
65 | - } |
|
66 | - |
|
67 | - public function getAreLocations() |
|
68 | - { |
|
69 | - return self::getLocations(); |
|
70 | - } |
|
71 | - |
|
72 | - public function getAllCategories() |
|
73 | - { |
|
74 | - return LocationCategory::get(); |
|
75 | - } |
|
76 | - |
|
77 | - public static function getPageCategories($id = null) |
|
78 | - { |
|
79 | - if ($id) { |
|
80 | - if ($locator = self::get()->byID($id)) { |
|
81 | - return $locator->Categories(); |
|
82 | - } |
|
83 | - |
|
84 | - return false; |
|
85 | - } |
|
86 | - |
|
87 | - return false; |
|
88 | - } |
|
5 | + private static $db = array( |
|
6 | + 'AutoGeocode' => 'Boolean', |
|
7 | + 'ModalWindow' => 'Boolean', |
|
8 | + 'Unit' => 'Enum("m,km","m")', |
|
9 | + ); |
|
10 | + |
|
11 | + private static $many_many = array( |
|
12 | + 'Categories' => 'LocationCategory', |
|
13 | + ); |
|
14 | + |
|
15 | + private static $defaults = array( |
|
16 | + 'AutoGeocode' => true, |
|
17 | + ); |
|
18 | + |
|
19 | + private static $singular_name = 'Locator'; |
|
20 | + private static $plural_name = 'Locators'; |
|
21 | + private static $description = 'Find locations on a map'; |
|
22 | + |
|
23 | + public function getCMSFields() |
|
24 | + { |
|
25 | + $fields = parent::getCMSFields(); |
|
26 | + |
|
27 | + // Settings |
|
28 | + $fields->addFieldsToTab('Root.Settings', array( |
|
29 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
30 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
31 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
32 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
33 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
34 | + )); |
|
35 | + |
|
36 | + // Filter categories |
|
37 | + $config = GridFieldConfig_RelationEditor::create(); |
|
38 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
39 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
40 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
41 | + } |
|
42 | + $categories = $this->Categories(); |
|
43 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
44 | + ->setDescription('only show locations from the selected category'); |
|
45 | + |
|
46 | + // Filter |
|
47 | + $fields->addFieldsToTab('Root.Filter', array( |
|
48 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
49 | + $categoriesField, |
|
50 | + )); |
|
51 | + |
|
52 | + $this->extend('updateCMSFields', $fields); |
|
53 | + |
|
54 | + return $fields; |
|
55 | + } |
|
56 | + |
|
57 | + public static function getLocations($filter = array(), $exclude = array(), $filterAny = array()) |
|
58 | + { |
|
59 | + $filter['ShowInLocator'] = true; |
|
60 | + $exclude['Lat'] = 0; |
|
61 | + |
|
62 | + $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny); |
|
63 | + |
|
64 | + return $Locations; |
|
65 | + } |
|
66 | + |
|
67 | + public function getAreLocations() |
|
68 | + { |
|
69 | + return self::getLocations(); |
|
70 | + } |
|
71 | + |
|
72 | + public function getAllCategories() |
|
73 | + { |
|
74 | + return LocationCategory::get(); |
|
75 | + } |
|
76 | + |
|
77 | + public static function getPageCategories($id = null) |
|
78 | + { |
|
79 | + if ($id) { |
|
80 | + if ($locator = self::get()->byID($id)) { |
|
81 | + return $locator->Categories(); |
|
82 | + } |
|
83 | + |
|
84 | + return false; |
|
85 | + } |
|
86 | + |
|
87 | + return false; |
|
88 | + } |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | class Locator_Controller extends Page_Controller |
92 | 92 | { |
93 | - // allowed actions |
|
94 | - private static $allowed_actions = array('xml'); |
|
93 | + // allowed actions |
|
94 | + private static $allowed_actions = array('xml'); |
|
95 | 95 | |
96 | - // Set Requirements based on input from CMS |
|
97 | - public function init() |
|
98 | - { |
|
99 | - parent::init(); |
|
96 | + // Set Requirements based on input from CMS |
|
97 | + public function init() |
|
98 | + { |
|
99 | + parent::init(); |
|
100 | 100 | |
101 | - $themeDir = SSViewer::get_theme_folder(); |
|
101 | + $themeDir = SSViewer::get_theme_folder(); |
|
102 | 102 | |
103 | - // google maps api key |
|
104 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
103 | + // google maps api key |
|
104 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
105 | 105 | |
106 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
107 | - if (Locator::getLocations()) { |
|
108 | - Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
109 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
110 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
111 | - } |
|
106 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
107 | + if (Locator::getLocations()) { |
|
108 | + Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
109 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
110 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
111 | + } |
|
112 | 112 | |
113 | - Requirements::css('locator/css/map.css'); |
|
113 | + Requirements::css('locator/css/map.css'); |
|
114 | 114 | |
115 | - $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
|
116 | - 'featuredLocations: true' : |
|
117 | - 'featuredLocations: false'; |
|
115 | + $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
|
116 | + 'featuredLocations: true' : |
|
117 | + 'featuredLocations: false'; |
|
118 | 118 | |
119 | - // map config based on user input in Settings tab |
|
120 | - // AutoGeocode or Full Map |
|
121 | - $load = ($this->data()->AutoGeocode) ? |
|
122 | - 'autoGeocode: true, fullMapStart: false,' : |
|
123 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
119 | + // map config based on user input in Settings tab |
|
120 | + // AutoGeocode or Full Map |
|
121 | + $load = ($this->data()->AutoGeocode) ? |
|
122 | + 'autoGeocode: true, fullMapStart: false,' : |
|
123 | + 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
124 | 124 | |
125 | - $base = Director::baseFolder(); |
|
126 | - $themePath = $base.'/'.$themeDir; |
|
125 | + $base = Director::baseFolder(); |
|
126 | + $themePath = $base.'/'.$themeDir; |
|
127 | 127 | |
128 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
129 | - $themeDir.'/templates/location-list-description.html' : |
|
130 | - 'locator/templates/location-list-description.html'; |
|
131 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
132 | - $themeDir.'/templates/infowindow-description.html' : |
|
133 | - 'locator/templates/infowindow-description.html'; |
|
128 | + $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
129 | + $themeDir.'/templates/location-list-description.html' : |
|
130 | + 'locator/templates/location-list-description.html'; |
|
131 | + $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
132 | + $themeDir.'/templates/infowindow-description.html' : |
|
133 | + 'locator/templates/infowindow-description.html'; |
|
134 | 134 | |
135 | - // in page or modal |
|
136 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
135 | + // in page or modal |
|
136 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
137 | 137 | |
138 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
138 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
139 | 139 | |
140 | - $link = $this->Link().'xml.xml'; |
|
140 | + $link = $this->Link().'xml.xml'; |
|
141 | 141 | |
142 | - // init map |
|
143 | - if (Locator::getLocations()) { |
|
144 | - Requirements::customScript(" |
|
142 | + // init map |
|
143 | + if (Locator::getLocations()) { |
|
144 | + Requirements::customScript(" |
|
145 | 145 | $(function($) { |
146 | 146 | $('#map-container').storeLocator({ |
147 | 147 | ".$load." |
@@ -162,73 +162,73 @@ discard block |
||
162 | 162 | }); |
163 | 163 | }); |
164 | 164 | '); |
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Find all locations for map. |
|
170 | - * |
|
171 | - * Will return a XML feed of all locations marked "show in locator". |
|
172 | - * |
|
173 | - * @return XML file |
|
174 | - * |
|
175 | - * @todo rename/refactor to allow for json/xml |
|
176 | - * @todo allow $filter to run off of getVars key/val pair |
|
177 | - */ |
|
178 | - public function xml(SS_HTTPRequest $request) |
|
179 | - { |
|
180 | - $filter = array(); |
|
181 | - $exclude = array(); |
|
182 | - $filterAny = array(); |
|
183 | - |
|
184 | - //if a category filter selected |
|
185 | - if ($this->Categories()->exists()) { |
|
186 | - $categories = $this->Categories(); |
|
187 | - foreach ($categories as $category) { |
|
188 | - $filterAny['CategoryID'] = $category->ID; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - $Locations = Locator::getLocations($filter, $exclude, $filterAny); |
|
193 | - |
|
194 | - return $this->customise(array( |
|
195 | - 'Locations' => $Locations, |
|
196 | - ))->renderWith('LocationXML'); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * LocationSearch form. |
|
201 | - * |
|
202 | - * Search form for locations, updates map and results list via AJAX |
|
203 | - * |
|
204 | - * @return Form |
|
205 | - */ |
|
206 | - public function LocationSearch() |
|
207 | - { |
|
208 | - $fields = FieldList::create( |
|
209 | - $address = TextField::create('address', '') |
|
210 | - ); |
|
211 | - $address->setAttribute('placeholder', 'address or zip code'); |
|
212 | - |
|
213 | - $locatorCategories = Locator::getPageCategories($this->ID); |
|
214 | - |
|
215 | - if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) { |
|
216 | - $categories = LocationCategory::get(); |
|
217 | - |
|
218 | - if ($categories->count() > 0) { |
|
219 | - $fields->push( |
|
220 | - DropdownField::create( |
|
221 | - 'category', |
|
222 | - '', |
|
223 | - $categories->map('Title', 'Title') |
|
224 | - )->setEmptyString('Select Category')); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - $actions = FieldList::create( |
|
229 | - FormAction::create('', 'Search') |
|
230 | - ); |
|
231 | - |
|
232 | - return Form::create($this, 'LocationSearch', $fields, $actions); |
|
233 | - } |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Find all locations for map. |
|
170 | + * |
|
171 | + * Will return a XML feed of all locations marked "show in locator". |
|
172 | + * |
|
173 | + * @return XML file |
|
174 | + * |
|
175 | + * @todo rename/refactor to allow for json/xml |
|
176 | + * @todo allow $filter to run off of getVars key/val pair |
|
177 | + */ |
|
178 | + public function xml(SS_HTTPRequest $request) |
|
179 | + { |
|
180 | + $filter = array(); |
|
181 | + $exclude = array(); |
|
182 | + $filterAny = array(); |
|
183 | + |
|
184 | + //if a category filter selected |
|
185 | + if ($this->Categories()->exists()) { |
|
186 | + $categories = $this->Categories(); |
|
187 | + foreach ($categories as $category) { |
|
188 | + $filterAny['CategoryID'] = $category->ID; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + $Locations = Locator::getLocations($filter, $exclude, $filterAny); |
|
193 | + |
|
194 | + return $this->customise(array( |
|
195 | + 'Locations' => $Locations, |
|
196 | + ))->renderWith('LocationXML'); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * LocationSearch form. |
|
201 | + * |
|
202 | + * Search form for locations, updates map and results list via AJAX |
|
203 | + * |
|
204 | + * @return Form |
|
205 | + */ |
|
206 | + public function LocationSearch() |
|
207 | + { |
|
208 | + $fields = FieldList::create( |
|
209 | + $address = TextField::create('address', '') |
|
210 | + ); |
|
211 | + $address->setAttribute('placeholder', 'address or zip code'); |
|
212 | + |
|
213 | + $locatorCategories = Locator::getPageCategories($this->ID); |
|
214 | + |
|
215 | + if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) { |
|
216 | + $categories = LocationCategory::get(); |
|
217 | + |
|
218 | + if ($categories->count() > 0) { |
|
219 | + $fields->push( |
|
220 | + DropdownField::create( |
|
221 | + 'category', |
|
222 | + '', |
|
223 | + $categories->map('Title', 'Title') |
|
224 | + )->setEmptyString('Select Category')); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + $actions = FieldList::create( |
|
229 | + FormAction::create('', 'Search') |
|
230 | + ); |
|
231 | + |
|
232 | + return Form::create($this, 'LocationSearch', $fields, $actions); |
|
233 | + } |
|
234 | 234 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
107 | 107 | if (Locator::getLocations()) { |
108 | - Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
108 | + Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
109 | 109 | Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
110 | 110 | Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
111 | 111 | } |
@@ -113,44 +113,40 @@ discard block |
||
113 | 113 | Requirements::css('locator/css/map.css'); |
114 | 114 | |
115 | 115 | $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
116 | - 'featuredLocations: true' : |
|
117 | - 'featuredLocations: false'; |
|
116 | + 'featuredLocations: true' : 'featuredLocations: false'; |
|
118 | 117 | |
119 | 118 | // map config based on user input in Settings tab |
120 | 119 | // AutoGeocode or Full Map |
121 | 120 | $load = ($this->data()->AutoGeocode) ? |
122 | - 'autoGeocode: true, fullMapStart: false,' : |
|
123 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
121 | + 'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
124 | 122 | |
125 | 123 | $base = Director::baseFolder(); |
126 | - $themePath = $base.'/'.$themeDir; |
|
124 | + $themePath = $base . '/' . $themeDir; |
|
127 | 125 | |
128 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
129 | - $themeDir.'/templates/location-list-description.html' : |
|
130 | - 'locator/templates/location-list-description.html'; |
|
131 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
132 | - $themeDir.'/templates/infowindow-description.html' : |
|
133 | - 'locator/templates/infowindow-description.html'; |
|
126 | + $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
127 | + $themeDir . '/templates/location-list-description.html' : 'locator/templates/location-list-description.html'; |
|
128 | + $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
129 | + $themeDir . '/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html'; |
|
134 | 130 | |
135 | 131 | // in page or modal |
136 | 132 | $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
137 | 133 | |
138 | 134 | $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
139 | 135 | |
140 | - $link = $this->Link().'xml.xml'; |
|
136 | + $link = $this->Link() . 'xml.xml'; |
|
141 | 137 | |
142 | 138 | // init map |
143 | 139 | if (Locator::getLocations()) { |
144 | 140 | Requirements::customScript(" |
145 | 141 | $(function($) { |
146 | 142 | $('#map-container').storeLocator({ |
147 | - ".$load." |
|
148 | - dataLocation: '".$link."', |
|
149 | - listTemplatePath: '".$listTemplatePath."', |
|
150 | - infowindowTemplatePath: '".$infowindowTemplatePath."', |
|
143 | + ".$load . " |
|
144 | + dataLocation: '".$link . "', |
|
145 | + listTemplatePath: '".$listTemplatePath . "', |
|
146 | + infowindowTemplatePath: '".$infowindowTemplatePath . "', |
|
151 | 147 | originMarker: true, |
152 | - ".$modal.', |
|
153 | - '.$featured.", |
|
148 | + ".$modal . ', |
|
149 | + '.$featured . ", |
|
154 | 150 | slideMap: false, |
155 | 151 | zoomLevel: 0, |
156 | 152 | distanceAlert: 120, |
@@ -158,7 +154,7 @@ discard block |
||
158 | 154 | inputID: 'Form_LocationSearch_address', |
159 | 155 | categoryID: 'Form_LocationSearch_category', |
160 | 156 | distanceAlert: -1, |
161 | - ".$kilometer.' |
|
157 | + ".$kilometer . ' |
|
162 | 158 | }); |
163 | 159 | }); |
164 | 160 | '); |