Passed
Push — master ( 4e09b0...c54da7 )
by Jason
02:26
created
src/Page/LocatorController.php 1 patch
Indentation   +337 added lines, -337 removed lines patch added patch discarded remove patch
@@ -21,345 +21,345 @@
 block discarded – undo
21 21
  */
22 22
 class LocatorController extends \PageController
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    private static $allowed_actions = [
28
-        'xml',
29
-        'json',
30
-    ];
31
-
32
-    /**
33
-     * @var array
34
-     */
35
-    private static $base_filter = [];
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $base_exclude = [
41
-        'Lat' => 0,
42
-        'Lng' => 0,
43
-    ];
44
-
45
-    /**
46
-     * @var array
47
-     */
48
-    private static $base_filter_any = [];
49
-
50
-    /**
51
-     * @var bool
52
-     */
53
-    private static $bootstrapify = true;
54
-
55
-    /**
56
-     * ID of map container
57
-     *
58
-     * @var string
59
-     */
60
-    private static $map_container = 'map';
61
-
62
-    /**
63
-     * class of location list container
64
-     *
65
-     * @var string
66
-     */
67
-    private static $list_container = 'loc-list';
68
-
69
-    /**
70
-     * GET variable which, if isset, will trigger storeLocator init and return XML
71
-     *
72
-     * @var string
73
-     */
74
-    private static $query_trigger = 'action_doFilterLocations';
75
-
76
-    /**
77
-     * @var DataList|ArrayList
78
-     */
79
-    protected $locations;
80
-
81
-    /**
82
-     * Set Requirements based on input from CMS
83
-     */
84
-    public function init()
85
-    {
86
-        parent::init();
87
-
88
-        // prevent init of map if no query
89
-        $request = Controller::curr()->getRequest();
90
-        if (!$this->getTrigger($request)) {
91
-            return;
92
-        }
93
-
94
-        $locations = $this->getLocations();
95
-
96
-        // prevent init of map if there are no locations
97
-        if (!$locations) {
98
-            return;
99
-        }
100
-
101
-        // google maps api key
102
-        $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
103
-        Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
104
-
105
-        $mapSettings = [
106
-            'fullMapStart' => true,
107
-            'maxDistance' => true,
108
-            'storeLimit' => -1,
109
-            'originMarker' => true,
110
-            'slideMap' => false,
111
-            'distanceAlert' => -1,
112
-            'featuredLocations' => false,
113
-            'defaultLat' => 0,
114
-            'defaultLng' => 0,
115
-            'mapSettings' => [
116
-                'zoom' => 12,
117
-                'mapTypeId' => 'google.maps.MapTypeId.ROADMAP',
118
-                'disableDoubleClickZoom' => true,
119
-                'scrollwheel' => false,
120
-                'navigationControl' => false,
121
-                'draggable' => false,
122
-            ],
123
-        ];
124
-
125
-        $mapSettings['listTemplatePath'] = $this->getListTemplate();
126
-        $mapSettings['infowindowTemplatePath'] = $this->getInfoWindowTemplate();
127
-        $mapSettings['lengthUnit'] = $this->data()->Unit == 'km' ? 'km' : 'm';
128
-        $mapSettings['mapID'] = Config::inst()->get(LocatorController::class, 'map_container');
129
-        $mapSettings['locationList'] = Config::inst()->get(LocatorController::class, 'list_container');
130
-
131
-        if ($locations->filter('Featured', true)->count() > 0) {
132
-            $mapSettings['featuredLocations'] = true;
133
-        }
134
-
135
-        // map config based on user input in Settings tab
136
-        $limit = Config::inst()->get(LocatorController::class, 'limit');
137
-        if (0 < $limit) {
138
-            $mapSettings['storeLimit'] = $limit;
139
-        }
140
-
141
-        if ($coords = $this->getAddressSearchCoords()) {
142
-            $mapSettings['defaultLat'] = $coords->getField("Lat");
143
-            $mapSettings['defaultLat'] = $coords->getField("Lng");
144
-        }
145
-
146
-        // pass GET variables to xml action
147
-        $vars = $this->request->getVars();
148
-        unset($vars['url']);
149
-        $url = '';
150
-        if (count($vars)) {
151
-            $url .= '?' . http_build_query($vars);
152
-        }
153
-        $mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url);
154
-
155
-        if ($stylePath = $this->getMapStyleJSONPath()) {
156
-            if ($style = file_get_contents($stylePath)) {
157
-                $mapSettings['mapSettings']['styles'] = json_decode($style);
158
-            }
159
-        }
160
-
161
-        if ($imagePath = $this->getMarkerIcon()) {
162
-            $mapSettings['markerImg'] = $imagePath;
163
-        }
164
-
165
-        $this->extend('modifyMapSettings', $mapSettings);
166
-
167
-        $encoded = json_encode($mapSettings, JSON_UNESCAPED_SLASHES);
168
-        // mapTypeId is a javascript object
169
-        $encoded = preg_replace('/("mapTypeId"\s*:\s*)"(.+?)"/i', '$1$2', $encoded);
170
-
171
-        $this->extend('modifyMapSettingsEncoded', $encoded);
172
-        // init map
173
-        Requirements::customScript("
24
+	/**
25
+	 * @var array
26
+	 */
27
+	private static $allowed_actions = [
28
+		'xml',
29
+		'json',
30
+	];
31
+
32
+	/**
33
+	 * @var array
34
+	 */
35
+	private static $base_filter = [];
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $base_exclude = [
41
+		'Lat' => 0,
42
+		'Lng' => 0,
43
+	];
44
+
45
+	/**
46
+	 * @var array
47
+	 */
48
+	private static $base_filter_any = [];
49
+
50
+	/**
51
+	 * @var bool
52
+	 */
53
+	private static $bootstrapify = true;
54
+
55
+	/**
56
+	 * ID of map container
57
+	 *
58
+	 * @var string
59
+	 */
60
+	private static $map_container = 'map';
61
+
62
+	/**
63
+	 * class of location list container
64
+	 *
65
+	 * @var string
66
+	 */
67
+	private static $list_container = 'loc-list';
68
+
69
+	/**
70
+	 * GET variable which, if isset, will trigger storeLocator init and return XML
71
+	 *
72
+	 * @var string
73
+	 */
74
+	private static $query_trigger = 'action_doFilterLocations';
75
+
76
+	/**
77
+	 * @var DataList|ArrayList
78
+	 */
79
+	protected $locations;
80
+
81
+	/**
82
+	 * Set Requirements based on input from CMS
83
+	 */
84
+	public function init()
85
+	{
86
+		parent::init();
87
+
88
+		// prevent init of map if no query
89
+		$request = Controller::curr()->getRequest();
90
+		if (!$this->getTrigger($request)) {
91
+			return;
92
+		}
93
+
94
+		$locations = $this->getLocations();
95
+
96
+		// prevent init of map if there are no locations
97
+		if (!$locations) {
98
+			return;
99
+		}
100
+
101
+		// google maps api key
102
+		$key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
103
+		Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
104
+
105
+		$mapSettings = [
106
+			'fullMapStart' => true,
107
+			'maxDistance' => true,
108
+			'storeLimit' => -1,
109
+			'originMarker' => true,
110
+			'slideMap' => false,
111
+			'distanceAlert' => -1,
112
+			'featuredLocations' => false,
113
+			'defaultLat' => 0,
114
+			'defaultLng' => 0,
115
+			'mapSettings' => [
116
+				'zoom' => 12,
117
+				'mapTypeId' => 'google.maps.MapTypeId.ROADMAP',
118
+				'disableDoubleClickZoom' => true,
119
+				'scrollwheel' => false,
120
+				'navigationControl' => false,
121
+				'draggable' => false,
122
+			],
123
+		];
124
+
125
+		$mapSettings['listTemplatePath'] = $this->getListTemplate();
126
+		$mapSettings['infowindowTemplatePath'] = $this->getInfoWindowTemplate();
127
+		$mapSettings['lengthUnit'] = $this->data()->Unit == 'km' ? 'km' : 'm';
128
+		$mapSettings['mapID'] = Config::inst()->get(LocatorController::class, 'map_container');
129
+		$mapSettings['locationList'] = Config::inst()->get(LocatorController::class, 'list_container');
130
+
131
+		if ($locations->filter('Featured', true)->count() > 0) {
132
+			$mapSettings['featuredLocations'] = true;
133
+		}
134
+
135
+		// map config based on user input in Settings tab
136
+		$limit = Config::inst()->get(LocatorController::class, 'limit');
137
+		if (0 < $limit) {
138
+			$mapSettings['storeLimit'] = $limit;
139
+		}
140
+
141
+		if ($coords = $this->getAddressSearchCoords()) {
142
+			$mapSettings['defaultLat'] = $coords->getField("Lat");
143
+			$mapSettings['defaultLat'] = $coords->getField("Lng");
144
+		}
145
+
146
+		// pass GET variables to xml action
147
+		$vars = $this->request->getVars();
148
+		unset($vars['url']);
149
+		$url = '';
150
+		if (count($vars)) {
151
+			$url .= '?' . http_build_query($vars);
152
+		}
153
+		$mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url);
154
+
155
+		if ($stylePath = $this->getMapStyleJSONPath()) {
156
+			if ($style = file_get_contents($stylePath)) {
157
+				$mapSettings['mapSettings']['styles'] = json_decode($style);
158
+			}
159
+		}
160
+
161
+		if ($imagePath = $this->getMarkerIcon()) {
162
+			$mapSettings['markerImg'] = $imagePath;
163
+		}
164
+
165
+		$this->extend('modifyMapSettings', $mapSettings);
166
+
167
+		$encoded = json_encode($mapSettings, JSON_UNESCAPED_SLASHES);
168
+		// mapTypeId is a javascript object
169
+		$encoded = preg_replace('/("mapTypeId"\s*:\s*)"(.+?)"/i', '$1$2', $encoded);
170
+
171
+		$this->extend('modifyMapSettingsEncoded', $encoded);
172
+		// init map
173
+		Requirements::customScript("
174 174
                 $(function(){
175 175
                     $('#map-container').storeLocator({$encoded});
176 176
                 });
177 177
             ", 'jquery-locator');
178
-    }
179
-
180
-    /**
181
-     * @param HTTPRequest $request
182
-     *
183
-     * @return bool
184
-     */
185
-    public function getTrigger(HTTPRequest $request = null)
186
-    {
187
-        if ($request === null) {
188
-            $request = $this->getRequest();
189
-        }
190
-        $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));
191
-
192
-        return isset($trigger);
193
-    }
194
-
195
-    /**
196
-     * @return ArrayList|DataList
197
-     */
198
-    public function getLocations()
199
-    {
200
-        if (!$this->locations) {
201
-            $this->setLocations($this->request);
202
-        }
203
-
204
-        return $this->locations;
205
-    }
206
-
207
-    /**
208
-     * @param HTTPRequest|null $request
209
-     *
210
-     * @return $this
211
-     */
212
-    public function setLocations(HTTPRequest $request = null)
213
-    {
214
-
215
-        if ($request === null) {
216
-            $request = $this->request;
217
-        }
218
-        $filter = $this->config()->get('base_filter');
219
-
220
-        $categoryVar = $this->data()->config()->get('category_var');
221
-        if ($request->getVar($categoryVar)) {
222
-            $filter['Categories.ID'] = $request->getVar($categoryVar);
223
-        } else {
224
-            if ($this->getPageCategories()->exists()) {
225
-                foreach ($this->getPageCategories() as $category) {
226
-                    $filter['Categories.ID'][] = $category->ID;
227
-                }
228
-            }
229
-        }
230
-
231
-        $this->extend('updateLocatorFilter', $filter, $request);
232
-
233
-        $filterAny = $this->config()->get('base_filter_any');
234
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
235
-
236
-        $exclude = $this->config()->get('base_exclude');
237
-        $this->extend('updateLocatorExclude', $exclude, $request);
238
-
239
-        $class = $this->data()->ClassName;
240
-        $locations = $class::get_locations($filter, $filterAny, $exclude);
241
-        $locations = DataToArrayListHelper::to_array_list($locations);
242
-
243
-        //allow for adjusting list post possible distance calculation
244
-        $this->extend('updateLocationList', $locations);
245
-
246
-        if ($locations->canSortBy('Distance')) {
247
-            $locations = $locations->sort('Distance');
248
-        }
249
-
250
-        if ($this->getShowRadius()) {
251
-            $radiusVar = $this->data()->config()->get('radius_var');
252
-
253
-            if ($radius = (int)$request->getVar($radiusVar)) {
254
-                $locations = $locations->filterByCallback(function ($location) use (&$radius) {
255
-                    return $location->Distance <= $radius;
256
-                });
257
-            }
258
-        }
259
-
260
-        //allow for returning list to be set as
261
-        $this->extend('updateListType', $locations);
262
-
263
-        $limit = $this->getLimit();
264
-        if ($limit > 0) {
265
-            $locations = $locations->limit($limit);
266
-        }
267
-
268
-        $this->locations = $locations;
269
-
270
-        return $this;
271
-    }
272
-
273
-    /**
274
-     * @return ArrayData|boolean
275
-     */
276
-    public function getAddressSearchCoords()
277
-    {
278
-        $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var');
279
-        if (!$this->request->getVar($addressVar)) {
280
-            return false;
281
-        }
282
-        if (class_exists(GoogleGeocoder::class)) {
283
-            $geocoder = new GoogleGeocoder($this->request->getVar($addressVar));
284
-            $response = $geocoder->getResult();
285
-            $lat = $response->getLatitude();
286
-            $lng = $response->getLongitude();
287
-
288
-            return new ArrayData([
289
-                "Lat" => $lat,
290
-                "Lng" => $lng,
291
-            ]);
292
-        }
293
-    }
294
-
295
-    /**
296
-     * @param HTTPRequest $request
297
-     *
298
-     * @return \SilverStripe\View\ViewableData_Customised
299
-     */
300
-    public function index(HTTPRequest $request)
301
-    {
302
-        if ($this->getTrigger($request)) {
303
-            $locations = $this->getLocations();
304
-        } else {
305
-            $locations = ArrayList::create();
306
-        }
307
-
308
-        return $this->customise([
309
-            'Locations' => $locations,
310
-        ]);
311
-    }
312
-
313
-    /**
314
-     * Renders locations in xml format
315
-     *
316
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
317
-     */
318
-    public function xml()
319
-    {
320
-        $this->getResponse()->addHeader("Content-Type", "application/xml");
321
-        $data = new ArrayData([
322
-            "Locations" => $this->getLocations(),
323
-            "AddressCoords" => $this->getAddressSearchCoords(),
324
-        ]);
325
-
326
-        return $data->renderWith('Dynamic/Locator/Data/XML');
327
-    }
328
-
329
-    /**
330
-     * Renders locations in json format
331
-     *
332
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
333
-     */
334
-    public function json()
335
-    {
336
-        $this->getResponse()->addHeader("Content-Type", "application/json");
337
-        $data = new ArrayData([
338
-            "Locations" => $this->getLocations(),
339
-            "AddressCoords" => $this->getAddressSearchCoords(),
340
-        ]);
341
-
342
-        return $data->renderWith('Dynamic/Locator/Data/JSON');
343
-    }
344
-
345
-    /**
346
-     * LocationSearch form.
347
-     *
348
-     * Search form for locations, updates map and results list via AJAX
349
-     *
350
-     * @return \SilverStripe\Forms\Form
351
-     */
352
-    public function LocationSearch()
353
-    {
354
-
355
-        $form = LocatorForm::create($this, 'LocationSearch');
356
-
357
-        $this->extend('updateLocationSearch', $form);
358
-
359
-        return $form
360
-            ->setFormMethod('GET')
361
-            ->setFormAction($this->Link())
362
-            ->disableSecurityToken()
363
-            ->loadDataFrom($this->request->getVars());
364
-    }
178
+	}
179
+
180
+	/**
181
+	 * @param HTTPRequest $request
182
+	 *
183
+	 * @return bool
184
+	 */
185
+	public function getTrigger(HTTPRequest $request = null)
186
+	{
187
+		if ($request === null) {
188
+			$request = $this->getRequest();
189
+		}
190
+		$trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));
191
+
192
+		return isset($trigger);
193
+	}
194
+
195
+	/**
196
+	 * @return ArrayList|DataList
197
+	 */
198
+	public function getLocations()
199
+	{
200
+		if (!$this->locations) {
201
+			$this->setLocations($this->request);
202
+		}
203
+
204
+		return $this->locations;
205
+	}
206
+
207
+	/**
208
+	 * @param HTTPRequest|null $request
209
+	 *
210
+	 * @return $this
211
+	 */
212
+	public function setLocations(HTTPRequest $request = null)
213
+	{
214
+
215
+		if ($request === null) {
216
+			$request = $this->request;
217
+		}
218
+		$filter = $this->config()->get('base_filter');
219
+
220
+		$categoryVar = $this->data()->config()->get('category_var');
221
+		if ($request->getVar($categoryVar)) {
222
+			$filter['Categories.ID'] = $request->getVar($categoryVar);
223
+		} else {
224
+			if ($this->getPageCategories()->exists()) {
225
+				foreach ($this->getPageCategories() as $category) {
226
+					$filter['Categories.ID'][] = $category->ID;
227
+				}
228
+			}
229
+		}
230
+
231
+		$this->extend('updateLocatorFilter', $filter, $request);
232
+
233
+		$filterAny = $this->config()->get('base_filter_any');
234
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
235
+
236
+		$exclude = $this->config()->get('base_exclude');
237
+		$this->extend('updateLocatorExclude', $exclude, $request);
238
+
239
+		$class = $this->data()->ClassName;
240
+		$locations = $class::get_locations($filter, $filterAny, $exclude);
241
+		$locations = DataToArrayListHelper::to_array_list($locations);
242
+
243
+		//allow for adjusting list post possible distance calculation
244
+		$this->extend('updateLocationList', $locations);
245
+
246
+		if ($locations->canSortBy('Distance')) {
247
+			$locations = $locations->sort('Distance');
248
+		}
249
+
250
+		if ($this->getShowRadius()) {
251
+			$radiusVar = $this->data()->config()->get('radius_var');
252
+
253
+			if ($radius = (int)$request->getVar($radiusVar)) {
254
+				$locations = $locations->filterByCallback(function ($location) use (&$radius) {
255
+					return $location->Distance <= $radius;
256
+				});
257
+			}
258
+		}
259
+
260
+		//allow for returning list to be set as
261
+		$this->extend('updateListType', $locations);
262
+
263
+		$limit = $this->getLimit();
264
+		if ($limit > 0) {
265
+			$locations = $locations->limit($limit);
266
+		}
267
+
268
+		$this->locations = $locations;
269
+
270
+		return $this;
271
+	}
272
+
273
+	/**
274
+	 * @return ArrayData|boolean
275
+	 */
276
+	public function getAddressSearchCoords()
277
+	{
278
+		$addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var');
279
+		if (!$this->request->getVar($addressVar)) {
280
+			return false;
281
+		}
282
+		if (class_exists(GoogleGeocoder::class)) {
283
+			$geocoder = new GoogleGeocoder($this->request->getVar($addressVar));
284
+			$response = $geocoder->getResult();
285
+			$lat = $response->getLatitude();
286
+			$lng = $response->getLongitude();
287
+
288
+			return new ArrayData([
289
+				"Lat" => $lat,
290
+				"Lng" => $lng,
291
+			]);
292
+		}
293
+	}
294
+
295
+	/**
296
+	 * @param HTTPRequest $request
297
+	 *
298
+	 * @return \SilverStripe\View\ViewableData_Customised
299
+	 */
300
+	public function index(HTTPRequest $request)
301
+	{
302
+		if ($this->getTrigger($request)) {
303
+			$locations = $this->getLocations();
304
+		} else {
305
+			$locations = ArrayList::create();
306
+		}
307
+
308
+		return $this->customise([
309
+			'Locations' => $locations,
310
+		]);
311
+	}
312
+
313
+	/**
314
+	 * Renders locations in xml format
315
+	 *
316
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
317
+	 */
318
+	public function xml()
319
+	{
320
+		$this->getResponse()->addHeader("Content-Type", "application/xml");
321
+		$data = new ArrayData([
322
+			"Locations" => $this->getLocations(),
323
+			"AddressCoords" => $this->getAddressSearchCoords(),
324
+		]);
325
+
326
+		return $data->renderWith('Dynamic/Locator/Data/XML');
327
+	}
328
+
329
+	/**
330
+	 * Renders locations in json format
331
+	 *
332
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
333
+	 */
334
+	public function json()
335
+	{
336
+		$this->getResponse()->addHeader("Content-Type", "application/json");
337
+		$data = new ArrayData([
338
+			"Locations" => $this->getLocations(),
339
+			"AddressCoords" => $this->getAddressSearchCoords(),
340
+		]);
341
+
342
+		return $data->renderWith('Dynamic/Locator/Data/JSON');
343
+	}
344
+
345
+	/**
346
+	 * LocationSearch form.
347
+	 *
348
+	 * Search form for locations, updates map and results list via AJAX
349
+	 *
350
+	 * @return \SilverStripe\Forms\Form
351
+	 */
352
+	public function LocationSearch()
353
+	{
354
+
355
+		$form = LocatorForm::create($this, 'LocationSearch');
356
+
357
+		$this->extend('updateLocationSearch', $form);
358
+
359
+		return $form
360
+			->setFormMethod('GET')
361
+			->setFormAction($this->Link())
362
+			->disableSecurityToken()
363
+			->loadDataFrom($this->request->getVars());
364
+	}
365 365
 }
Please login to merge, or discard this patch.
src/admin/LocationAdmin.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -17,83 +17,83 @@
 block discarded – undo
17 17
 class LocationAdmin extends ModelAdmin
18 18
 {
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    private static $managed_models = [
24
-        Location::class,
25
-        LocationCategory::class,
26
-    ];
20
+	/**
21
+	 * @var array
22
+	 */
23
+	private static $managed_models = [
24
+		Location::class,
25
+		LocationCategory::class,
26
+	];
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    private static $model_importers = [
32
-        Location::class => LocationCsvBulkLoader::class,
33
-        LocationCategory::class => CsvBulkLoader::class,
34
-    ];
28
+	/**
29
+	 * @var array
30
+	 */
31
+	private static $model_importers = [
32
+		Location::class => LocationCsvBulkLoader::class,
33
+		LocationCategory::class => CsvBulkLoader::class,
34
+	];
35 35
 
36
-    /**
37
-     * @var string
38
-     */
39
-    private static $menu_title = 'Locator';
40
-    /**
41
-     * @var string
42
-     */
43
-    private static $url_segment = 'locator';
36
+	/**
37
+	 * @var string
38
+	 */
39
+	private static $menu_title = 'Locator';
40
+	/**
41
+	 * @var string
42
+	 */
43
+	private static $url_segment = 'locator';
44 44
 
45
-    /**
46
-     * @return array
47
-     */
48
-    public function getExportFields()
49
-    {
50
-        if ($this->modelClass == Location::class) {
51
-            $fields = [
52
-                'Title' => 'Name',
53
-                'Address' => 'Address',
54
-                'Address2' => 'Address2',
55
-                'City' => 'City',
56
-                'State' => 'State',
57
-                'PostalCode' => 'PostalCode',
58
-                'CountryCode' => 'Country',
59
-                'Phone' => 'Phone',
60
-                'Fax' => 'Fax',
61
-                'Email' => 'Email',
62
-                'Website' => 'Website',
63
-                'Featured' => 'Featured',
64
-                'CategoryList' => 'Categories',
65
-                'Lat' => 'Lat',
66
-                'Lng' => 'Lng',
67
-                'Import_ID' => 'Import_ID',
68
-            ];
69
-        }
45
+	/**
46
+	 * @return array
47
+	 */
48
+	public function getExportFields()
49
+	{
50
+		if ($this->modelClass == Location::class) {
51
+			$fields = [
52
+				'Title' => 'Name',
53
+				'Address' => 'Address',
54
+				'Address2' => 'Address2',
55
+				'City' => 'City',
56
+				'State' => 'State',
57
+				'PostalCode' => 'PostalCode',
58
+				'CountryCode' => 'Country',
59
+				'Phone' => 'Phone',
60
+				'Fax' => 'Fax',
61
+				'Email' => 'Email',
62
+				'Website' => 'Website',
63
+				'Featured' => 'Featured',
64
+				'CategoryList' => 'Categories',
65
+				'Lat' => 'Lat',
66
+				'Lng' => 'Lng',
67
+				'Import_ID' => 'Import_ID',
68
+			];
69
+		}
70 70
 
71
-        if (!isset($fields)) {
72
-            $fields = parent::getExportFields();
73
-        }
71
+		if (!isset($fields)) {
72
+			$fields = parent::getExportFields();
73
+		}
74 74
 
75
-        $this->extend('updateGetExportFields', $fields);
75
+		$this->extend('updateGetExportFields', $fields);
76 76
 
77
-        return $fields;
78
-    }
77
+		return $fields;
78
+	}
79 79
 
80
-    /**
81
-     * @param null $id
82
-     * @param null $fields
83
-     * @return $this|Form
84
-     */
85
-    public function getEditForm($id = null, $fields = null)
86
-    {
87
-        $form = parent::getEditForm($id, $fields);
80
+	/**
81
+	 * @param null $id
82
+	 * @param null $fields
83
+	 * @return $this|Form
84
+	 */
85
+	public function getEditForm($id = null, $fields = null)
86
+	{
87
+		$form = parent::getEditForm($id, $fields);
88 88
 
89
-        if ($this->modelClass == Location::class) {
90
-            /** @var GridField $gridField */
91
-            if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) {
92
-                $gridField->getConfig()
93
-                    ->removeComponentsByType('GridFieldDeleteAction');
94
-            }
95
-        }
89
+		if ($this->modelClass == Location::class) {
90
+			/** @var GridField $gridField */
91
+			if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) {
92
+				$gridField->getConfig()
93
+					->removeComponentsByType('GridFieldDeleteAction');
94
+			}
95
+		}
96 96
 
97
-        return $form;
98
-    }
97
+		return $form;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
src/Tasks/LocationToPageTask.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -15,72 +15,72 @@
 block discarded – undo
15 15
  */
16 16
 class LocationToPageTask extends BuildTask
17 17
 {
18
-    /**
19
-     * @var string
20
-     */
21
-    protected $title = 'Locator - Location to Page Task';
18
+	/**
19
+	 * @var string
20
+	 */
21
+	protected $title = 'Locator - Location to Page Task';
22 22
 
23
-    /**
24
-     * @var string
25
-     */
26
-    private static $segment = 'locator-location-to-page-task';
23
+	/**
24
+	 * @var string
25
+	 */
26
+	private static $segment = 'locator-location-to-page-task';
27 27
 
28
-    /**
29
-     * @var bool
30
-     */
31
-    private static $auto_publish_location = false;
28
+	/**
29
+	 * @var bool
30
+	 */
31
+	private static $auto_publish_location = false;
32 32
 
33
-    /**
34
-     * @param \SilverStripe\Control\HTTPRequest $request
35
-     */
36
-    public function run($request)
37
-    {
38
-        $this->migrateLocations();
39
-    }
33
+	/**
34
+	 * @param \SilverStripe\Control\HTTPRequest $request
35
+	 */
36
+	public function run($request)
37
+	{
38
+		$this->migrateLocations();
39
+	}
40 40
 
41
-    /**
42
-     *
43
-     */
44
-    protected function migrateLocations()
45
-    {
46
-        if (!$parent = Locator::get()->first()) {
47
-            $parent = Locator::create();
48
-            $parent->Title = "Locator";
49
-            $parent->writeToStage(Versioned::DRAFT);
50
-        }
41
+	/**
42
+	 *
43
+	 */
44
+	protected function migrateLocations()
45
+	{
46
+		if (!$parent = Locator::get()->first()) {
47
+			$parent = Locator::create();
48
+			$parent->Title = "Locator";
49
+			$parent->writeToStage(Versioned::DRAFT);
50
+		}
51 51
 
52
-        /** @var Location $location */
53
-        foreach ($this->getLocations() as $location) {
54
-            if (!LocationPage::get()->filter('LegacyObjectID', $location->ID)->first()) {
55
-                if ($location->hasMethod('isPublished')) {
56
-                    $published = $location->isPublished();
57
-                }
52
+		/** @var Location $location */
53
+		foreach ($this->getLocations() as $location) {
54
+			if (!LocationPage::get()->filter('LegacyObjectID', $location->ID)->first()) {
55
+				if ($location->hasMethod('isPublished')) {
56
+					$published = $location->isPublished();
57
+				}
58 58
 
59
-                /** @var LocationPage $newLocation */
60
-                $newLocation = Injector::inst()->create(LocationPage::class, $location->toMap(), false);
61
-                $newLocation->setClassName(LocationPage::class);
62
-                $newLocation->ID = null;
63
-                $newLocation->ParentID = $parent->ID;
64
-                $newLocation->LegacyObjectID = $location->ID;
59
+				/** @var LocationPage $newLocation */
60
+				$newLocation = Injector::inst()->create(LocationPage::class, $location->toMap(), false);
61
+				$newLocation->setClassName(LocationPage::class);
62
+				$newLocation->ID = null;
63
+				$newLocation->ParentID = $parent->ID;
64
+				$newLocation->LegacyObjectID = $location->ID;
65 65
 
66
-                $this->extend('preLocationMigrationUpdate', $location, $newLocation);
66
+				$this->extend('preLocationMigrationUpdate', $location, $newLocation);
67 67
 
68
-                $newLocation->writeToStage(Versioned::DRAFT);
68
+				$newLocation->writeToStage(Versioned::DRAFT);
69 69
 
70
-                if ((isset($published) && $published) || $this->config()->get('auto_publish_location')) {
71
-                    $newLocation->publishSingle();
72
-                }
73
-            }
74
-        }
75
-    }
70
+				if ((isset($published) && $published) || $this->config()->get('auto_publish_location')) {
71
+					$newLocation->publishSingle();
72
+				}
73
+			}
74
+		}
75
+	}
76 76
 
77
-    /**
78
-     * @return \Generator
79
-     */
80
-    protected function getLocations()
81
-    {
82
-        foreach (Location::get() as $location) {
83
-            yield $location;
84
-        }
85
-    }
77
+	/**
78
+	 * @return \Generator
79
+	 */
80
+	protected function getLocations()
81
+	{
82
+		foreach (Location::get() as $location) {
83
+			yield $location;
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
src/Tasks/LocationPublishTask.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -11,76 +11,76 @@
 block discarded – undo
11 11
  */
12 12
 class LocationPublishTask extends BuildTask
13 13
 {
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $title = 'Publish all Locations';
18
-    /**
19
-     * @var string
20
-     */
21
-    protected $description = 'Migration task - pre versioning on Location';
22
-    /**
23
-     * @var bool
24
-     */
25
-    protected $enabled = true;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $title = 'Publish all Locations';
18
+	/**
19
+	 * @var string
20
+	 */
21
+	protected $description = 'Migration task - pre versioning on Location';
22
+	/**
23
+	 * @var bool
24
+	 */
25
+	protected $enabled = true;
26 26
 
27
-    /**
28
-     * @param $request
29
-     */
30
-    public function run($request)
31
-    {
32
-        $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location';
33
-        $this->publishLocations($class);
34
-    }
27
+	/**
28
+	 * @param $request
29
+	 */
30
+	public function run($request)
31
+	{
32
+		$class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location';
33
+		$this->publishLocations($class);
34
+	}
35 35
 
36
-    /**
37
-     * @param string $class
38
-     * @return \Generator
39
-     */
40
-    protected function iterateLocations($class)
41
-    {
42
-        foreach ($class::get()->filter('ShowInLocator', true) as $location) {
43
-            yield $location;
44
-        }
45
-    }
36
+	/**
37
+	 * @param string $class
38
+	 * @return \Generator
39
+	 */
40
+	protected function iterateLocations($class)
41
+	{
42
+		foreach ($class::get()->filter('ShowInLocator', true) as $location) {
43
+			yield $location;
44
+		}
45
+	}
46 46
 
47
-    /**
48
-     * mark all ProductDetail records as ShowInMenus = 0.
49
-     *
50
-     * @param string $class
51
-     */
52
-    public function publishLocations($class)
53
-    {
54
-        if (!isset($class) || !class_exists($class) || !$class instanceof Location) {
55
-            $class = 'Location';
56
-        }
57
-        $ct = 0;
58
-        $publish = function ($location) use (&$ct) {
59
-            if (!$location->isPublished()) {
60
-                $title = $location->Title;
61
-                $location->writeToStage('Stage');
62
-                $location->publish('Stage', 'Live');
63
-                static::write_message($title);
64
-                ++$ct;
65
-            }
66
-        };
47
+	/**
48
+	 * mark all ProductDetail records as ShowInMenus = 0.
49
+	 *
50
+	 * @param string $class
51
+	 */
52
+	public function publishLocations($class)
53
+	{
54
+		if (!isset($class) || !class_exists($class) || !$class instanceof Location) {
55
+			$class = 'Location';
56
+		}
57
+		$ct = 0;
58
+		$publish = function ($location) use (&$ct) {
59
+			if (!$location->isPublished()) {
60
+				$title = $location->Title;
61
+				$location->writeToStage('Stage');
62
+				$location->publish('Stage', 'Live');
63
+				static::write_message($title);
64
+				++$ct;
65
+			}
66
+		};
67 67
 
68
-        foreach ($this->iterateLocations($class) as $location) {
69
-            $publish($location);
70
-        }
68
+		foreach ($this->iterateLocations($class) as $location) {
69
+			$publish($location);
70
+		}
71 71
 
72
-        static::write_message("{$ct} locations updated.");
73
-    }
72
+		static::write_message("{$ct} locations updated.");
73
+	}
74 74
 
75
-    /**
76
-     * @param $message
77
-     */
78
-    protected static function write_message($message)
79
-    {
80
-        if (Director::is_cli()) {
81
-            echo "{$message}\n";
82
-        } else {
83
-            echo "{$message}<br><br>";
84
-        }
85
-    }
75
+	/**
76
+	 * @param $message
77
+	 */
78
+	protected static function write_message($message)
79
+	{
80
+		if (Director::is_cli()) {
81
+			echo "{$message}\n";
82
+		} else {
83
+			echo "{$message}<br><br>";
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
             $class = 'Location';
56 56
         }
57 57
         $ct = 0;
58
-        $publish = function ($location) use (&$ct) {
58
+        $publish = function($location) use (&$ct) {
59 59
             if (!$location->isPublished()) {
60 60
                 $title = $location->Title;
61 61
                 $location->writeToStage('Stage');
Please login to merge, or discard this patch.
src/Tasks/LocationCategoriesTask.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -14,72 +14,72 @@
 block discarded – undo
14 14
 class LocationCategoriesTask extends BuildTask
15 15
 {
16 16
 
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $title = 'Location categories to many_many';
21
-
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $description = 'Migration task - Converts locations to have multiple categories';
26
-
27
-    /**
28
-     * @var bool
29
-     */
30
-    protected $enabled = true;
31
-
32
-    /**
33
-     * @param $request
34
-     */
35
-    public function run($request)
36
-    {
37
-        /** @var DataObject $class */
38
-        $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : Location::class;
39
-        $class::add_extension(LocationCategoryExtension::class);
40
-
41
-
42
-        $categories = [];
43
-
44
-        $convert = function (DataObject $location) use (&$categories) {
45
-            /** @var Location $location */
46
-            // skip if no category
47
-            if ($location->CategoryID > 0) {
48
-                $categories[$location->CategoryID][] = $location->ID;
49
-            }
50
-        };
51
-
52
-        foreach ($this->iterateLocations($class) as $location) {
53
-            $convert($location);
54
-        }
55
-
56
-        $catCt = 0;
57
-        $locCT = 0;
58
-
59
-        foreach ($categories as $categoryID => $locations) {
60
-            /** @var LocationCategory $category */
61
-            $category = LocationCategory::get()->byID($categoryID);
62
-            $category->Locations()->addMany($locations);
63
-
64
-            $catCt++;
65
-            $locCT += count($locations);
66
-        }
67
-
68
-        echo "{$catCt} categories converted<br />";
69
-        echo "{$locCT} location relations converted<br />";
70
-
71
-        $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
72
-        echo "Process Time: {$time} seconds";
73
-    }
74
-
75
-    /**
76
-     * @param string $class
77
-     * @return \Generator
78
-     */
79
-    protected function iterateLocations($class)
80
-    {
81
-        foreach ($class::get() as $location) {
82
-            yield $location;
83
-        }
84
-    }
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $title = 'Location categories to many_many';
21
+
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $description = 'Migration task - Converts locations to have multiple categories';
26
+
27
+	/**
28
+	 * @var bool
29
+	 */
30
+	protected $enabled = true;
31
+
32
+	/**
33
+	 * @param $request
34
+	 */
35
+	public function run($request)
36
+	{
37
+		/** @var DataObject $class */
38
+		$class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : Location::class;
39
+		$class::add_extension(LocationCategoryExtension::class);
40
+
41
+
42
+		$categories = [];
43
+
44
+		$convert = function (DataObject $location) use (&$categories) {
45
+			/** @var Location $location */
46
+			// skip if no category
47
+			if ($location->CategoryID > 0) {
48
+				$categories[$location->CategoryID][] = $location->ID;
49
+			}
50
+		};
51
+
52
+		foreach ($this->iterateLocations($class) as $location) {
53
+			$convert($location);
54
+		}
55
+
56
+		$catCt = 0;
57
+		$locCT = 0;
58
+
59
+		foreach ($categories as $categoryID => $locations) {
60
+			/** @var LocationCategory $category */
61
+			$category = LocationCategory::get()->byID($categoryID);
62
+			$category->Locations()->addMany($locations);
63
+
64
+			$catCt++;
65
+			$locCT += count($locations);
66
+		}
67
+
68
+		echo "{$catCt} categories converted<br />";
69
+		echo "{$locCT} location relations converted<br />";
70
+
71
+		$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
72
+		echo "Process Time: {$time} seconds";
73
+	}
74
+
75
+	/**
76
+	 * @param string $class
77
+	 * @return \Generator
78
+	 */
79
+	protected function iterateLocations($class)
80
+	{
81
+		foreach ($class::get() as $location) {
82
+			yield $location;
83
+		}
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
 
42 42
         $categories = [];
43 43
 
44
-        $convert = function (DataObject $location) use (&$categories) {
44
+        $convert = function(DataObject $location) use (&$categories) {
45 45
             /** @var Location $location */
46 46
             // skip if no category
47 47
             if ($location->CategoryID > 0) {
Please login to merge, or discard this patch.
src/Tasks/LocationCategoryExtension.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
  */
14 14
 class LocationCategoryExtension extends DataExtension
15 15
 {
16
-    private static $has_one = [
17
-        'Category' => LocationCategory::class,
18
-    ];
16
+	private static $has_one = [
17
+		'Category' => LocationCategory::class,
18
+	];
19 19
 }
Please login to merge, or discard this patch.
src/Model/LocationCategory.php 2 patches
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -23,125 +23,125 @@
 block discarded – undo
23 23
  */
24 24
 class LocationCategory extends DataObject
25 25
 {
26
-    /**
27
-     * @var string
28
-     */
29
-    private static $singular_name = 'Category';
30
-
31
-    /**
32
-     * @var string
33
-     */
34
-    private static $plural_name = 'Categories';
35
-
36
-    /**
37
-     * @var array
38
-     */
39
-    private static $db = [
40
-        'Name' => 'Varchar(100)',
41
-    ];
42
-
43
-    /**
44
-     * @var array
45
-     */
46
-    private static $belongs_many_many = [
47
-        'Locators' => Locator::class,
48
-        'LocationSet' => Location::class,
49
-    ];
50
-
51
-    /**
52
-     * @var string
53
-     */
54
-    private static $table_name = 'LocationCategory';
55
-
56
-    /**
57
-     * @var string
58
-     */
59
-    private static $default_sort = 'Name';
60
-
61
-    /**
62
-     * @return \SilverStripe\Forms\FieldList
63
-     */
64
-    public function getCMSFields()
65
-    {
66
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
67
-            $fields->removeByName([
68
-                'Locations',
69
-                'LocationSet',
70
-                'Locators',
71
-                'LinkTracking',
72
-                'FileTracking',
73
-            ]);
74
-
75
-            if ($this->ID) {
76
-                // Locations
77
-                $config = GridFieldConfig_RelationEditor::create();
78
-                $config->removeComponentsByType([
79
-                    GridFieldAddExistingAutocompleter::class,
80
-                    GridFieldAddNewButton::class,
81
-                ])
82
-                    ->addComponents([
83
-                        new GridFieldAddExistingSearchButton(),
84
-                    ]);
85
-                $locations = $this->Locations();
86
-                $locationField = GridField::create('Locations', 'Locations', $locations, $config);
87
-
88
-                $fields->addFieldsToTab('Root.Main', [
89
-                    $locationField,
90
-                ]);
91
-            }
92
-        });
93
-
94
-        $fields = parent::getCMSFields();
95
-
96
-        return $fields;
97
-    }
98
-
99
-    /**
100
-     * For backwards compatability
101
-     * @return ManyManyList
102
-     */
103
-    public function Locations()
104
-    {
105
-        return $this->LocationSet();
106
-    }
107
-
108
-    /**
109
-     * @param null $member
110
-     * @param array $context
111
-     * @return bool
112
-     */
113
-    public function canView($member = null, $context = [])
114
-    {
115
-        return true;
116
-    }
117
-
118
-    /**
119
-     * @param null $member
120
-     * @param array $context
121
-     * @return bool|int
122
-     */
123
-    public function canEdit($member = null, $context = [])
124
-    {
125
-        return Permission::check('Location_EDIT', 'any', $member);
126
-    }
127
-
128
-    /**
129
-     * @param null $member
130
-     * @param array $context
131
-     * @return bool|int
132
-     */
133
-    public function canDelete($member = null, $context = [])
134
-    {
135
-        return Permission::check('Location_DELETE', 'any', $member);
136
-    }
137
-
138
-    /**
139
-     * @param null $member
140
-     * @param array $context
141
-     * @return bool|int
142
-     */
143
-    public function canCreate($member = null, $context = [])
144
-    {
145
-        return Permission::check('Location_CREATE', 'any', $member);
146
-    }
26
+	/**
27
+	 * @var string
28
+	 */
29
+	private static $singular_name = 'Category';
30
+
31
+	/**
32
+	 * @var string
33
+	 */
34
+	private static $plural_name = 'Categories';
35
+
36
+	/**
37
+	 * @var array
38
+	 */
39
+	private static $db = [
40
+		'Name' => 'Varchar(100)',
41
+	];
42
+
43
+	/**
44
+	 * @var array
45
+	 */
46
+	private static $belongs_many_many = [
47
+		'Locators' => Locator::class,
48
+		'LocationSet' => Location::class,
49
+	];
50
+
51
+	/**
52
+	 * @var string
53
+	 */
54
+	private static $table_name = 'LocationCategory';
55
+
56
+	/**
57
+	 * @var string
58
+	 */
59
+	private static $default_sort = 'Name';
60
+
61
+	/**
62
+	 * @return \SilverStripe\Forms\FieldList
63
+	 */
64
+	public function getCMSFields()
65
+	{
66
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
67
+			$fields->removeByName([
68
+				'Locations',
69
+				'LocationSet',
70
+				'Locators',
71
+				'LinkTracking',
72
+				'FileTracking',
73
+			]);
74
+
75
+			if ($this->ID) {
76
+				// Locations
77
+				$config = GridFieldConfig_RelationEditor::create();
78
+				$config->removeComponentsByType([
79
+					GridFieldAddExistingAutocompleter::class,
80
+					GridFieldAddNewButton::class,
81
+				])
82
+					->addComponents([
83
+						new GridFieldAddExistingSearchButton(),
84
+					]);
85
+				$locations = $this->Locations();
86
+				$locationField = GridField::create('Locations', 'Locations', $locations, $config);
87
+
88
+				$fields->addFieldsToTab('Root.Main', [
89
+					$locationField,
90
+				]);
91
+			}
92
+		});
93
+
94
+		$fields = parent::getCMSFields();
95
+
96
+		return $fields;
97
+	}
98
+
99
+	/**
100
+	 * For backwards compatability
101
+	 * @return ManyManyList
102
+	 */
103
+	public function Locations()
104
+	{
105
+		return $this->LocationSet();
106
+	}
107
+
108
+	/**
109
+	 * @param null $member
110
+	 * @param array $context
111
+	 * @return bool
112
+	 */
113
+	public function canView($member = null, $context = [])
114
+	{
115
+		return true;
116
+	}
117
+
118
+	/**
119
+	 * @param null $member
120
+	 * @param array $context
121
+	 * @return bool|int
122
+	 */
123
+	public function canEdit($member = null, $context = [])
124
+	{
125
+		return Permission::check('Location_EDIT', 'any', $member);
126
+	}
127
+
128
+	/**
129
+	 * @param null $member
130
+	 * @param array $context
131
+	 * @return bool|int
132
+	 */
133
+	public function canDelete($member = null, $context = [])
134
+	{
135
+		return Permission::check('Location_DELETE', 'any', $member);
136
+	}
137
+
138
+	/**
139
+	 * @param null $member
140
+	 * @param array $context
141
+	 * @return bool|int
142
+	 */
143
+	public function canCreate($member = null, $context = [])
144
+	{
145
+		return Permission::check('Location_CREATE', 'any', $member);
146
+	}
147 147
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
      */
64 64
     public function getCMSFields()
65 65
     {
66
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
66
+        $this->beforeUpdateCMSFields(function(FieldList $fields) {
67 67
             $fields->removeByName([
68 68
                 'Locations',
69 69
                 'LocationSet',
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
@@ -18,88 +18,88 @@
 block discarded – undo
18 18
  */
19 19
 class LocatorForm extends Form
20 20
 {
21
-    /**
22
-     * LocatorForm constructor.
23
-     * @param Controller $controller
24
-     * @param string $name
25
-     */
26
-    public function __construct(Controller $controller, $name)
27
-    {
21
+	/**
22
+	 * LocatorForm constructor.
23
+	 * @param Controller $controller
24
+	 * @param string $name
25
+	 */
26
+	public function __construct(Controller $controller, $name)
27
+	{
28 28
 
29
-        $fields = FieldList::create(
30
-            TextField::create('Address')
31
-                ->setTitle('')
32
-                ->setAttribute('placeholder', 'address or zip code')
33
-        );
29
+		$fields = FieldList::create(
30
+			TextField::create('Address')
31
+				->setTitle('')
32
+				->setAttribute('placeholder', 'address or zip code')
33
+		);
34 34
 
35
-        $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
36
-        if ($pageCategories && $pageCategories->count() > 0) {
37
-            $categories = false;
38
-        } else {
39
-            $categories = Locator::get_all_categories();
40
-            if ($categories->count() < 1) {
41
-                $categories = false;
42
-            }
43
-        }
35
+		$pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
36
+		if ($pageCategories && $pageCategories->count() > 0) {
37
+			$categories = false;
38
+		} else {
39
+			$categories = Locator::get_all_categories();
40
+			if ($categories->count() < 1) {
41
+				$categories = false;
42
+			}
43
+		}
44 44
 
45
-        if ($categories) {
46
-            $categoriesField = DropdownField::create('CategoryID')
47
-                ->setTitle('')
48
-                ->setEmptyString('all categories')
49
-                ->setSource($categories->map());
50
-            $fields->push($categoriesField);
51
-        }
45
+		if ($categories) {
46
+			$categoriesField = DropdownField::create('CategoryID')
47
+				->setTitle('')
48
+				->setEmptyString('all categories')
49
+				->setSource($categories->map());
50
+			$fields->push($categoriesField);
51
+		}
52 52
 
53
-        if ($controller->getShowRadius()) {
54
-            $radiusArray = array_values($controller->getRadii());
55
-            $this->extend('overrideRadiusArray', $radiusArray);
56
-            $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
57
-                ->setEmptyString('radius'));
58
-        }
53
+		if ($controller->getShowRadius()) {
54
+			$radiusArray = array_values($controller->getRadii());
55
+			$this->extend('overrideRadiusArray', $radiusArray);
56
+			$fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
57
+				->setEmptyString('radius'));
58
+		}
59 59
 
60
-        $actions = FieldList::create(
61
-            FormAction::create('doFilterLocations')
62
-                ->setTitle('Search')
63
-        );
60
+		$actions = FieldList::create(
61
+			FormAction::create('doFilterLocations')
62
+				->setTitle('Search')
63
+		);
64 64
 
65
-        $validator = $this->getValidator();
65
+		$validator = $this->getValidator();
66 66
 
67
-        parent::__construct($controller, $name, $fields, $actions, $validator);
68
-    }
67
+		parent::__construct($controller, $name, $fields, $actions, $validator);
68
+	}
69 69
 
70
-    /**
71
-     * @return null|RequiredFields|\SilverStripe\Forms\Validator
72
-     */
73
-    public function getValidator()
74
-    {
75
-        $validator = parent::getValidator();
76
-        if (empty($validator)) {
77
-            if (!$this->validator instanceof RequiredFields) {
78
-                $this->setValidator(RequiredFields::create('Address'));
79
-            }
80
-            $validator = $this->validator;
81
-        }
82
-        $this->extend('updateRequiredFields', $validator);
83
-        return $validator;
84
-    }
70
+	/**
71
+	 * @return null|RequiredFields|\SilverStripe\Forms\Validator
72
+	 */
73
+	public function getValidator()
74
+	{
75
+		$validator = parent::getValidator();
76
+		if (empty($validator)) {
77
+			if (!$this->validator instanceof RequiredFields) {
78
+				$this->setValidator(RequiredFields::create('Address'));
79
+			}
80
+			$validator = $this->validator;
81
+		}
82
+		$this->extend('updateRequiredFields', $validator);
83
+		return $validator;
84
+	}
85 85
 
86
-    /**
87
-     * @return FieldList
88
-     */
89
-    public function Fields()
90
-    {
91
-        $fields = parent::Fields();
92
-        $this->extend('updateLocatorFormFields', $fields);
93
-        return $fields;
94
-    }
86
+	/**
87
+	 * @return FieldList
88
+	 */
89
+	public function Fields()
90
+	{
91
+		$fields = parent::Fields();
92
+		$this->extend('updateLocatorFormFields', $fields);
93
+		return $fields;
94
+	}
95 95
 
96
-    /**
97
-     * @return \SilverStripe\Forms\FieldList
98
-     */
99
-    public function Actions()
100
-    {
101
-        $actions = parent::Actions();
102
-        $this->extend('updateLocatorActions', $actions);
103
-        return $actions;
104
-    }
96
+	/**
97
+	 * @return \SilverStripe\Forms\FieldList
98
+	 */
99
+	public function Actions()
100
+	{
101
+		$actions = parent::Actions();
102
+		$this->extend('updateLocatorActions', $actions);
103
+		return $actions;
104
+	}
105 105
 }
Please login to merge, or discard this patch.
tests/Model/LocationCategoryTest.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -13,69 +13,69 @@
 block discarded – undo
13 13
  */
14 14
 class LocationCategoryTest extends SapphireTest
15 15
 {
16
-    /**
17
-     * @var string
18
-     */
19
-    protected static $fixture_file = 'categoryfixture.yml';
16
+	/**
17
+	 * @var string
18
+	 */
19
+	protected static $fixture_file = 'categoryfixture.yml';
20 20
 
21
-    /**
22
-     *
23
-     */
24
-    public function testGetCMSFields()
25
-    {
26
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
27
-        $fieldset = $object->getCMSFields();
28
-        $this->assertInstanceOf(FieldList::class, $fieldset);
29
-    }
21
+	/**
22
+	 *
23
+	 */
24
+	public function testGetCMSFields()
25
+	{
26
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
27
+		$fieldset = $object->getCMSFields();
28
+		$this->assertInstanceOf(FieldList::class, $fieldset);
29
+	}
30 30
 
31
-    /**
32
-     *
33
-     */
34
-    public function testCanView()
35
-    {
36
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
37
-        $this->assertTrue($object->canView());
38
-    }
31
+	/**
32
+	 *
33
+	 */
34
+	public function testCanView()
35
+	{
36
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
37
+		$this->assertTrue($object->canView());
38
+	}
39 39
 
40
-    /**
41
-     *
42
-     */
43
-    public function testCanEdit()
44
-    {
45
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
40
+	/**
41
+	 *
42
+	 */
43
+	public function testCanEdit()
44
+	{
45
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
46 46
 
47
-        $admin = $this->objFromFixture(Member::class, 'locationedit');
48
-        $this->assertTrue($object->canEdit($admin));
47
+		$admin = $this->objFromFixture(Member::class, 'locationedit');
48
+		$this->assertTrue($object->canEdit($admin));
49 49
 
50
-        $member = $this->objFromFixture(Member::class, 'default');
51
-        $this->assertFalse($object->canEdit($member));
52
-    }
50
+		$member = $this->objFromFixture(Member::class, 'default');
51
+		$this->assertFalse($object->canEdit($member));
52
+	}
53 53
 
54
-    /**
55
-     *
56
-     */
57
-    public function testCanDelete()
58
-    {
59
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
54
+	/**
55
+	 *
56
+	 */
57
+	public function testCanDelete()
58
+	{
59
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
60 60
 
61
-        $admin = $this->objFromFixture(Member::class, 'locationdelete');
62
-        $this->assertTrue($object->canDelete($admin));
61
+		$admin = $this->objFromFixture(Member::class, 'locationdelete');
62
+		$this->assertTrue($object->canDelete($admin));
63 63
 
64
-        $member = $this->objFromFixture(Member::class, 'default');
65
-        $this->assertFalse($object->canDelete($member));
66
-    }
64
+		$member = $this->objFromFixture(Member::class, 'default');
65
+		$this->assertFalse($object->canDelete($member));
66
+	}
67 67
 
68
-    /**
69
-     *
70
-     */
71
-    public function testCanCreate()
72
-    {
73
-        $object = $this->objFromFixture(LocationCategory::class, 'service');
68
+	/**
69
+	 *
70
+	 */
71
+	public function testCanCreate()
72
+	{
73
+		$object = $this->objFromFixture(LocationCategory::class, 'service');
74 74
 
75
-        $admin = $this->objFromFixture(Member::class, 'locationcreate');
76
-        $this->assertTrue($object->canCreate($admin));
75
+		$admin = $this->objFromFixture(Member::class, 'locationcreate');
76
+		$this->assertTrue($object->canCreate($admin));
77 77
 
78
-        $member = $this->objFromFixture(Member::class, 'default');
79
-        $this->assertFalse($object->canCreate($member));
80
-    }
78
+		$member = $this->objFromFixture(Member::class, 'default');
79
+		$this->assertFalse($object->canCreate($member));
80
+	}
81 81
 }
Please login to merge, or discard this patch.