Passed
Pull Request — master (#208)
by Matthew
05:58
created
src/pages/LocatorController.php 2 patches
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -18,131 +18,131 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class LocatorController extends \PageController
20 20
 {
21
-    /**
22
-     * @var array
23
-     */
24
-    private static $allowed_actions = [
25
-        'xml',
26
-        'json',
27
-    ];
28
-
29
-    /**
30
-     * @var array
31
-     */
32
-    private static $base_filter = [];
33
-
34
-    /**
35
-     * @var array
36
-     */
37
-    private static $base_exclude = [
38
-        'Lat' => 0,
39
-        'Lng' => 0,
40
-    ];
41
-
42
-    /**
43
-     * @var array
44
-     */
45
-    private static $base_filter_any = [];
46
-
47
-    /**
48
-     * @var bool
49
-     */
50
-    private static $bootstrapify = true;
51
-
52
-    /**
53
-     * ID of map container
54
-     *
55
-     * @var string
56
-     */
57
-    private static $map_container = 'map';
58
-
59
-    /**
60
-     * class of location list container
61
-     *
62
-     * @var string
63
-     */
64
-    private static $list_container = 'loc-list';
65
-
66
-    /**
67
-     * GET variable which, if isset, will trigger storeLocator init and return XML
68
-     *
69
-     * @var string
70
-     */
71
-    private static $query_trigger = 'action_doFilterLocations';
72
-
73
-    /**
74
-     * @var DataList|ArrayList
75
-     */
76
-    protected $locations;
77
-
78
-    /**
79
-     * Set Requirements based on input from CMS
80
-     */
81
-    public function init()
82
-    {
83
-        parent::init();
84
-        // google maps api key
85
-        $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
86
-        Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
87
-
88
-        // prevent init of map if no query
89
-        $request = Controller::curr()->getRequest();
90
-
91
-        if ($this->getTrigger($request)) {
92
-            $locations = $this->getLocations();
93
-
94
-            if ($locations) {
95
-                $featuredInList = ($locations->filter('Featured', true)->count() > 0);
96
-                $defaultCoords = $this->getAddressSearchCoords() ?
97
-                    $this->getAddressSearchCoords() :
98
-                    new ArrayData([
99
-                        "Lat" => 0,
100
-                        "Lng" => 0,
101
-                    ]);
102
-
103
-                $featured = $featuredInList
104
-                    ? 'featuredLocations: true'
105
-                    : 'featuredLocations: false';
106
-
107
-                // map config based on user input in Settings tab
108
-                $limit = Config::inst()->get(LocatorController::class, 'limit');
109
-                if ($limit < 1) {
110
-                    $limit = -1;
111
-                }
112
-                $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,';
113
-
114
-                $listTemplatePath = $this->getListTemplate();
115
-                $infowindowTemplatePath = $this->getInfoWindowTemplate();
116
-
117
-                $kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'";
118
-
119
-                // pass GET variables to xml action
120
-                $vars = $this->request->getVars();
121
-                unset($vars['url']);
122
-                $url = '';
123
-                if (count($vars)) {
124
-                    $url .= '?' . http_build_query($vars);
125
-                }
126
-                $link = Controller::join_links($this->Link(), 'xml.xml', $url);
127
-
128
-                // containers
129
-                $map_id = Config::inst()->get(LocatorController::class, 'map_container');
130
-                $list_class = Config::inst()->get(LocatorController::class, 'list_container');
131
-
132
-                $mapStyle = '';
133
-                if ($stylePath = $this->getMapStyleJSONPath()) {
134
-                    if ($style = file_get_contents($stylePath)) {
135
-                        $mapStyle = "styles: {$style},";
136
-                    }
137
-                };
138
-
139
-                $markerImage = '';
140
-                if ($imagePath = $this->getMarkerIcon()) {
141
-                    $markerImage = "markerImg: '{$imagePath}',";
142
-                }
143
-
144
-                // init map
145
-                Requirements::customScript("
21
+	/**
22
+	 * @var array
23
+	 */
24
+	private static $allowed_actions = [
25
+		'xml',
26
+		'json',
27
+	];
28
+
29
+	/**
30
+	 * @var array
31
+	 */
32
+	private static $base_filter = [];
33
+
34
+	/**
35
+	 * @var array
36
+	 */
37
+	private static $base_exclude = [
38
+		'Lat' => 0,
39
+		'Lng' => 0,
40
+	];
41
+
42
+	/**
43
+	 * @var array
44
+	 */
45
+	private static $base_filter_any = [];
46
+
47
+	/**
48
+	 * @var bool
49
+	 */
50
+	private static $bootstrapify = true;
51
+
52
+	/**
53
+	 * ID of map container
54
+	 *
55
+	 * @var string
56
+	 */
57
+	private static $map_container = 'map';
58
+
59
+	/**
60
+	 * class of location list container
61
+	 *
62
+	 * @var string
63
+	 */
64
+	private static $list_container = 'loc-list';
65
+
66
+	/**
67
+	 * GET variable which, if isset, will trigger storeLocator init and return XML
68
+	 *
69
+	 * @var string
70
+	 */
71
+	private static $query_trigger = 'action_doFilterLocations';
72
+
73
+	/**
74
+	 * @var DataList|ArrayList
75
+	 */
76
+	protected $locations;
77
+
78
+	/**
79
+	 * Set Requirements based on input from CMS
80
+	 */
81
+	public function init()
82
+	{
83
+		parent::init();
84
+		// google maps api key
85
+		$key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
86
+		Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
87
+
88
+		// prevent init of map if no query
89
+		$request = Controller::curr()->getRequest();
90
+
91
+		if ($this->getTrigger($request)) {
92
+			$locations = $this->getLocations();
93
+
94
+			if ($locations) {
95
+				$featuredInList = ($locations->filter('Featured', true)->count() > 0);
96
+				$defaultCoords = $this->getAddressSearchCoords() ?
97
+					$this->getAddressSearchCoords() :
98
+					new ArrayData([
99
+						"Lat" => 0,
100
+						"Lng" => 0,
101
+					]);
102
+
103
+				$featured = $featuredInList
104
+					? 'featuredLocations: true'
105
+					: 'featuredLocations: false';
106
+
107
+				// map config based on user input in Settings tab
108
+				$limit = Config::inst()->get(LocatorController::class, 'limit');
109
+				if ($limit < 1) {
110
+					$limit = -1;
111
+				}
112
+				$load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,';
113
+
114
+				$listTemplatePath = $this->getListTemplate();
115
+				$infowindowTemplatePath = $this->getInfoWindowTemplate();
116
+
117
+				$kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'";
118
+
119
+				// pass GET variables to xml action
120
+				$vars = $this->request->getVars();
121
+				unset($vars['url']);
122
+				$url = '';
123
+				if (count($vars)) {
124
+					$url .= '?' . http_build_query($vars);
125
+				}
126
+				$link = Controller::join_links($this->Link(), 'xml.xml', $url);
127
+
128
+				// containers
129
+				$map_id = Config::inst()->get(LocatorController::class, 'map_container');
130
+				$list_class = Config::inst()->get(LocatorController::class, 'list_container');
131
+
132
+				$mapStyle = '';
133
+				if ($stylePath = $this->getMapStyleJSONPath()) {
134
+					if ($style = file_get_contents($stylePath)) {
135
+						$mapStyle = "styles: {$style},";
136
+					}
137
+				};
138
+
139
+				$markerImage = '';
140
+				if ($imagePath = $this->getMarkerIcon()) {
141
+					$markerImage = "markerImg: '{$imagePath}',";
142
+				}
143
+
144
+				// init map
145
+				Requirements::customScript("
146 146
                 $(function(){
147 147
                     $('#map-container').storeLocator({
148 148
                         {$load}
@@ -171,194 +171,194 @@  discard block
 block discarded – undo
171 171
                     });
172 172
                 });
173 173
             ", 'jquery-locator');
174
-            }
175
-        }
176
-    }
177
-
178
-    /**
179
-     * @param HTTPRequest $request
180
-     *
181
-     * @return bool
182
-     */
183
-    public function getTrigger(HTTPRequest $request = null)
184
-    {
185
-        if ($request === null) {
186
-            $request = $this->getRequest();
187
-        }
188
-        $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));
189
-
190
-        return isset($trigger);
191
-    }
192
-
193
-    /**
194
-     * @return ArrayList|DataList
195
-     */
196
-    public function getLocations()
197
-    {
198
-        if (!$this->locations) {
199
-            $this->setLocations($this->request);
200
-        }
201
-
202
-        return $this->locations;
203
-    }
204
-
205
-    /**
206
-     * @param HTTPRequest|null $request
207
-     *
208
-     * @return $this
209
-     */
210
-    public function setLocations(HTTPRequest $request = null)
211
-    {
212
-
213
-        if ($request === null) {
214
-            $request = $this->request;
215
-        }
216
-        $filter = $this->config()->get('base_filter');
217
-
218
-        $categoryVar = Config::inst()->get(Locator::class, 'category_var');
219
-        if ($request->getVar($categoryVar)) {
220
-            $filter['Categories.ID'] = $request->getVar($categoryVar);
221
-        } else {
222
-            if ($this->getPageCategories()->exists()) {
223
-                foreach ($this->getPageCategories() as $category) {
224
-                    $filter['Categories.ID'][] = $category->ID;
225
-                }
226
-            }
227
-        }
228
-
229
-        $this->extend('updateLocatorFilter', $filter, $request);
230
-
231
-        $filterAny = $this->config()->get('base_filter_any');
232
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
233
-
234
-        $exclude = $this->config()->get('base_exclude');
235
-        $this->extend('updateLocatorExclude', $exclude, $request);
236
-
237
-        $locations = Locator::get_locations($filter, $filterAny, $exclude);
238
-        $locations = DataToArrayListHelper::to_array_list($locations);
239
-
240
-        //allow for adjusting list post possible distance calculation
241
-        $this->extend('updateLocationList', $locations);
242
-
243
-        if ($locations->canSortBy('Distance')) {
244
-            $locations = $locations->sort('Distance');
245
-        }
246
-
247
-        if ($this->getShowRadius()) {
248
-            $radiusVar = Config::inst()->get(Locator::class, 'radius_var');
249
-
250
-            if ($radius = (int)$request->getVar($radiusVar)) {
251
-                $locations = $locations->filterByCallback(function ($location) use (&$radius) {
252
-                    return $location->Distance <= $radius;
253
-                });
254
-            }
255
-        }
256
-
257
-        //allow for returning list to be set as
258
-        $this->extend('updateListType', $locations);
259
-
260
-        $limit = $this->getLimit();
261
-        if ($limit > 0) {
262
-            $locations = $locations->limit($limit);
263
-        }
264
-
265
-        $this->locations = $locations;
266
-
267
-        return $this;
268
-    }
269
-
270
-    /**
271
-     * @return ArrayData|boolean
272
-     */
273
-    public function getAddressSearchCoords()
274
-    {
275
-        $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var');
276
-        if (!$this->request->getVar($addressVar)) {
277
-            return false;
278
-        }
279
-        if (class_exists(GoogleGeocoder::class)) {
280
-            $geocoder = new GoogleGeocoder($this->request->getVar($addressVar));
281
-            $response = $geocoder->getResult();
282
-            $lat = $response->getLatitude();
283
-            $lng = $response->getLongitude();
284
-
285
-            return new ArrayData([
286
-                "Lat" => $lat,
287
-                "Lng" => $lng,
288
-            ]);
289
-        }
290
-    }
291
-
292
-    /**
293
-     * @param HTTPRequest $request
294
-     *
295
-     * @return \SilverStripe\View\ViewableData_Customised
296
-     */
297
-    public function index(HTTPRequest $request)
298
-    {
299
-        if ($this->getTrigger($request)) {
300
-            $locations = $this->getLocations();
301
-        } else {
302
-            $locations = ArrayList::create();
303
-        }
304
-
305
-        return $this->customise(array(
306
-            'Locations' => $locations,
307
-        ));
308
-    }
309
-
310
-    /**
311
-     * Renders locations in xml format
312
-     *
313
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
314
-     */
315
-    public function xml()
316
-    {
317
-        $this->getResponse()->addHeader("Content-Type", "application/xml");
318
-        $data = new ArrayData(array(
319
-            "Locations" => $this->getLocations(),
320
-            "AddressCoords" => $this->getAddressSearchCoords(),
321
-        ));
322
-
323
-        return $data->renderWith('Dynamic/Locator/Data/XML');
324
-    }
325
-
326
-    /**
327
-     * Renders locations in json format
328
-     *
329
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
330
-     */
331
-    public function json()
332
-    {
333
-        $this->getResponse()->addHeader("Content-Type", "application/json");
334
-        $data = new ArrayData(array(
335
-            "Locations" => $this->getLocations(),
336
-            "AddressCoords" => $this->getAddressSearchCoords(),
337
-        ));
338
-
339
-        return $data->renderWith('Dynamic/Locator/Data/JSON');
340
-    }
341
-
342
-    /**
343
-     * LocationSearch form.
344
-     *
345
-     * Search form for locations, updates map and results list via AJAX
346
-     *
347
-     * @return \SilverStripe\Forms\Form
348
-     */
349
-    public function LocationSearch()
350
-    {
351
-
352
-        $form = LocatorForm::create($this, 'LocationSearch');
353
-        if (class_exists(BootstrapForm::class) && $this->config()->get('bootstrapify')) {
354
-            $form->Fields()->bootstrapify();
355
-            $form->Actions()->bootstrapify();
356
-        }
357
-
358
-        return $form
359
-            ->setFormMethod('GET')
360
-            ->setFormAction($this->Link())
361
-            ->disableSecurityToken()
362
-            ->loadDataFrom($this->request->getVars());
363
-    }
174
+			}
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * @param HTTPRequest $request
180
+	 *
181
+	 * @return bool
182
+	 */
183
+	public function getTrigger(HTTPRequest $request = null)
184
+	{
185
+		if ($request === null) {
186
+			$request = $this->getRequest();
187
+		}
188
+		$trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));
189
+
190
+		return isset($trigger);
191
+	}
192
+
193
+	/**
194
+	 * @return ArrayList|DataList
195
+	 */
196
+	public function getLocations()
197
+	{
198
+		if (!$this->locations) {
199
+			$this->setLocations($this->request);
200
+		}
201
+
202
+		return $this->locations;
203
+	}
204
+
205
+	/**
206
+	 * @param HTTPRequest|null $request
207
+	 *
208
+	 * @return $this
209
+	 */
210
+	public function setLocations(HTTPRequest $request = null)
211
+	{
212
+
213
+		if ($request === null) {
214
+			$request = $this->request;
215
+		}
216
+		$filter = $this->config()->get('base_filter');
217
+
218
+		$categoryVar = Config::inst()->get(Locator::class, 'category_var');
219
+		if ($request->getVar($categoryVar)) {
220
+			$filter['Categories.ID'] = $request->getVar($categoryVar);
221
+		} else {
222
+			if ($this->getPageCategories()->exists()) {
223
+				foreach ($this->getPageCategories() as $category) {
224
+					$filter['Categories.ID'][] = $category->ID;
225
+				}
226
+			}
227
+		}
228
+
229
+		$this->extend('updateLocatorFilter', $filter, $request);
230
+
231
+		$filterAny = $this->config()->get('base_filter_any');
232
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
233
+
234
+		$exclude = $this->config()->get('base_exclude');
235
+		$this->extend('updateLocatorExclude', $exclude, $request);
236
+
237
+		$locations = Locator::get_locations($filter, $filterAny, $exclude);
238
+		$locations = DataToArrayListHelper::to_array_list($locations);
239
+
240
+		//allow for adjusting list post possible distance calculation
241
+		$this->extend('updateLocationList', $locations);
242
+
243
+		if ($locations->canSortBy('Distance')) {
244
+			$locations = $locations->sort('Distance');
245
+		}
246
+
247
+		if ($this->getShowRadius()) {
248
+			$radiusVar = Config::inst()->get(Locator::class, 'radius_var');
249
+
250
+			if ($radius = (int)$request->getVar($radiusVar)) {
251
+				$locations = $locations->filterByCallback(function ($location) use (&$radius) {
252
+					return $location->Distance <= $radius;
253
+				});
254
+			}
255
+		}
256
+
257
+		//allow for returning list to be set as
258
+		$this->extend('updateListType', $locations);
259
+
260
+		$limit = $this->getLimit();
261
+		if ($limit > 0) {
262
+			$locations = $locations->limit($limit);
263
+		}
264
+
265
+		$this->locations = $locations;
266
+
267
+		return $this;
268
+	}
269
+
270
+	/**
271
+	 * @return ArrayData|boolean
272
+	 */
273
+	public function getAddressSearchCoords()
274
+	{
275
+		$addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var');
276
+		if (!$this->request->getVar($addressVar)) {
277
+			return false;
278
+		}
279
+		if (class_exists(GoogleGeocoder::class)) {
280
+			$geocoder = new GoogleGeocoder($this->request->getVar($addressVar));
281
+			$response = $geocoder->getResult();
282
+			$lat = $response->getLatitude();
283
+			$lng = $response->getLongitude();
284
+
285
+			return new ArrayData([
286
+				"Lat" => $lat,
287
+				"Lng" => $lng,
288
+			]);
289
+		}
290
+	}
291
+
292
+	/**
293
+	 * @param HTTPRequest $request
294
+	 *
295
+	 * @return \SilverStripe\View\ViewableData_Customised
296
+	 */
297
+	public function index(HTTPRequest $request)
298
+	{
299
+		if ($this->getTrigger($request)) {
300
+			$locations = $this->getLocations();
301
+		} else {
302
+			$locations = ArrayList::create();
303
+		}
304
+
305
+		return $this->customise(array(
306
+			'Locations' => $locations,
307
+		));
308
+	}
309
+
310
+	/**
311
+	 * Renders locations in xml format
312
+	 *
313
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
314
+	 */
315
+	public function xml()
316
+	{
317
+		$this->getResponse()->addHeader("Content-Type", "application/xml");
318
+		$data = new ArrayData(array(
319
+			"Locations" => $this->getLocations(),
320
+			"AddressCoords" => $this->getAddressSearchCoords(),
321
+		));
322
+
323
+		return $data->renderWith('Dynamic/Locator/Data/XML');
324
+	}
325
+
326
+	/**
327
+	 * Renders locations in json format
328
+	 *
329
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
330
+	 */
331
+	public function json()
332
+	{
333
+		$this->getResponse()->addHeader("Content-Type", "application/json");
334
+		$data = new ArrayData(array(
335
+			"Locations" => $this->getLocations(),
336
+			"AddressCoords" => $this->getAddressSearchCoords(),
337
+		));
338
+
339
+		return $data->renderWith('Dynamic/Locator/Data/JSON');
340
+	}
341
+
342
+	/**
343
+	 * LocationSearch form.
344
+	 *
345
+	 * Search form for locations, updates map and results list via AJAX
346
+	 *
347
+	 * @return \SilverStripe\Forms\Form
348
+	 */
349
+	public function LocationSearch()
350
+	{
351
+
352
+		$form = LocatorForm::create($this, 'LocationSearch');
353
+		if (class_exists(BootstrapForm::class) && $this->config()->get('bootstrapify')) {
354
+			$form->Fields()->bootstrapify();
355
+			$form->Actions()->bootstrapify();
356
+		}
357
+
358
+		return $form
359
+			->setFormMethod('GET')
360
+			->setFormAction($this->Link())
361
+			->disableSecurityToken()
362
+			->loadDataFrom($this->request->getVars());
363
+	}
364 364
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         parent::init();
84 84
         // google maps api key
85 85
         $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
86
-        Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
86
+        Requirements::javascript('https://maps.google.com/maps/api/js?key='.$key);
87 87
 
88 88
         // prevent init of map if no query
89 89
         $request = Controller::curr()->getRequest();
@@ -94,8 +94,7 @@  discard block
 block discarded – undo
94 94
             if ($locations) {
95 95
                 $featuredInList = ($locations->filter('Featured', true)->count() > 0);
96 96
                 $defaultCoords = $this->getAddressSearchCoords() ?
97
-                    $this->getAddressSearchCoords() :
98
-                    new ArrayData([
97
+                    $this->getAddressSearchCoords() : new ArrayData([
99 98
                         "Lat" => 0,
100 99
                         "Lng" => 0,
101 100
                     ]);
@@ -109,7 +108,7 @@  discard block
 block discarded – undo
109 108
                 if ($limit < 1) {
110 109
                     $limit = -1;
111 110
                 }
112
-                $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,';
111
+                $load = 'fullMapStart: true, storeLimit: '.$limit.', maxDistance: true,';
113 112
 
114 113
                 $listTemplatePath = $this->getListTemplate();
115 114
                 $infowindowTemplatePath = $this->getInfoWindowTemplate();
@@ -121,7 +120,7 @@  discard block
 block discarded – undo
121 120
                 unset($vars['url']);
122 121
                 $url = '';
123 122
                 if (count($vars)) {
124
-                    $url .= '?' . http_build_query($vars);
123
+                    $url .= '?'.http_build_query($vars);
125 124
                 }
126 125
                 $link = Controller::join_links($this->Link(), 'xml.xml', $url);
127 126
 
@@ -247,8 +246,8 @@  discard block
 block discarded – undo
247 246
         if ($this->getShowRadius()) {
248 247
             $radiusVar = Config::inst()->get(Locator::class, 'radius_var');
249 248
 
250
-            if ($radius = (int)$request->getVar($radiusVar)) {
251
-                $locations = $locations->filterByCallback(function ($location) use (&$radius) {
249
+            if ($radius = (int) $request->getVar($radiusVar)) {
250
+                $locations = $locations->filterByCallback(function($location) use (&$radius) {
252 251
                     return $location->Distance <= $radius;
253 252
                 });
254 253
             }
Please login to merge, or discard this patch.
src/form/LocatorForm.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -19,88 +19,88 @@
 block discarded – undo
19 19
 class LocatorForm extends Form
20 20
 {
21 21
 
22
-    /**
23
-     * LocatorForm constructor.
24
-     * @param Controller $controller
25
-     * @param string $name
26
-     */
27
-    public function __construct(Controller $controller, $name)
28
-    {
22
+	/**
23
+	 * LocatorForm constructor.
24
+	 * @param Controller $controller
25
+	 * @param string $name
26
+	 */
27
+	public function __construct(Controller $controller, $name)
28
+	{
29 29
 
30
-        $fields = FieldList::create(
31
-            TextField::create('Address')
32
-                ->setTitle('')
33
-                ->setAttribute('placeholder', 'address or zip code')
34
-        );
30
+		$fields = FieldList::create(
31
+			TextField::create('Address')
32
+				->setTitle('')
33
+				->setAttribute('placeholder', 'address or zip code')
34
+		);
35 35
 
36
-        $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
37
-        if ($pageCategories && $pageCategories->count() > 0) {
38
-            $categories = false;
39
-        } else {
40
-            $categories = Locator::get_all_categories();
41
-            if ($categories->count() < 1) {
42
-                $categories = false;
43
-            }
44
-        }
36
+		$pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
37
+		if ($pageCategories && $pageCategories->count() > 0) {
38
+			$categories = false;
39
+		} else {
40
+			$categories = Locator::get_all_categories();
41
+			if ($categories->count() < 1) {
42
+				$categories = false;
43
+			}
44
+		}
45 45
 
46
-        if ($categories) {
47
-            $categoriesField = DropdownField::create('CategoryID')
48
-                ->setTitle('')
49
-                ->setEmptyString('all categories')
50
-                ->setSource($categories->map());
51
-            $fields->push($categoriesField);
52
-        }
46
+		if ($categories) {
47
+			$categoriesField = DropdownField::create('CategoryID')
48
+				->setTitle('')
49
+				->setEmptyString('all categories')
50
+				->setSource($categories->map());
51
+			$fields->push($categoriesField);
52
+		}
53 53
 
54
-        if ($controller->getShowRadius()) {
55
-            $radiusArray = array_values($controller->getRadii());
56
-            $this->extend('overrideRadiusArray', $radiusArray);
57
-            $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
58
-                ->setEmptyString('radius'));
59
-        }
54
+		if ($controller->getShowRadius()) {
55
+			$radiusArray = array_values($controller->getRadii());
56
+			$this->extend('overrideRadiusArray', $radiusArray);
57
+			$fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
58
+				->setEmptyString('radius'));
59
+		}
60 60
 
61
-        $actions = FieldList::create(
62
-            FormAction::create('doFilterLocations')
63
-                ->setTitle('Search')
64
-        );
61
+		$actions = FieldList::create(
62
+			FormAction::create('doFilterLocations')
63
+				->setTitle('Search')
64
+		);
65 65
 
66
-        $validator = $this->getValidator();
66
+		$validator = $this->getValidator();
67 67
 
68
-        parent::__construct($controller, $name, $fields, $actions, $validator);
69
-    }
68
+		parent::__construct($controller, $name, $fields, $actions, $validator);
69
+	}
70 70
 
71
-    /**
72
-     * @return null|RequiredFields|\SilverStripe\Forms\Validator
73
-     */
74
-    public function getValidator()
75
-    {
76
-        $validator = parent::getValidator();
77
-        if (empty($validator)) {
78
-            if (!$this->validator instanceof RequiredFields) {
79
-                $this->setValidator(RequiredFields::create('Address'));
80
-            }
81
-            $validator = $this->validator;
82
-        }
83
-        $this->extend('updateRequiredFields', $validator);
84
-        return $validator;
85
-    }
71
+	/**
72
+	 * @return null|RequiredFields|\SilverStripe\Forms\Validator
73
+	 */
74
+	public function getValidator()
75
+	{
76
+		$validator = parent::getValidator();
77
+		if (empty($validator)) {
78
+			if (!$this->validator instanceof RequiredFields) {
79
+				$this->setValidator(RequiredFields::create('Address'));
80
+			}
81
+			$validator = $this->validator;
82
+		}
83
+		$this->extend('updateRequiredFields', $validator);
84
+		return $validator;
85
+	}
86 86
 
87
-    /**
88
-     * @return FieldList
89
-     */
90
-    public function Fields()
91
-    {
92
-        $fields = parent::Fields();
93
-        $this->extend('updateLocatorFormFields', $fields);
94
-        return $fields;
95
-    }
87
+	/**
88
+	 * @return FieldList
89
+	 */
90
+	public function Fields()
91
+	{
92
+		$fields = parent::Fields();
93
+		$this->extend('updateLocatorFormFields', $fields);
94
+		return $fields;
95
+	}
96 96
 
97
-    /**
98
-     * @return \SilverStripe\Forms\FieldList
99
-     */
100
-    public function Actions()
101
-    {
102
-        $actions = parent::Actions();
103
-        $this->extend('updateLocatorActions', $actions);
104
-        return $actions;
105
-    }
97
+	/**
98
+	 * @return \SilverStripe\Forms\FieldList
99
+	 */
100
+	public function Actions()
101
+	{
102
+		$actions = parent::Actions();
103
+		$this->extend('updateLocatorActions', $actions);
104
+		return $actions;
105
+	}
106 106
 }
Please login to merge, or discard this patch.