Completed
Push — master ( 38f5b7...442fb4 )
by Nic
32s
created
code/form/LocatorForm.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
 class LocatorForm extends Form
7 7
 {
8 8
 
9
-    /**
10
-     * LocatorForm constructor.
11
-     * @param Controller $controller
12
-     * @param string $name
13
-     */
14
-    public function __construct(Controller $controller, $name)
15
-    {
16
-
17
-        $fields = FieldList::create(
18
-            TextField::create('Address')
19
-                ->setTitle('')
20
-                ->setAttribute('placeholder', 'address or zip code')
21
-        );
22
-
23
-        $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
24
-            ? Locator::locator_categories_by_locator($controller->data()->ID)
25
-            : Locator::get_all_categories();
26
-
27
-        $categoriesField = DropdownField::create('CategoryID')
28
-            ->setTitle('')
29
-            ->setEmptyString('All Categories')
30
-            ->setSource($categories->map());
31
-
32
-        $fields->push($categoriesField);
33
-
34
-        $actions = FieldList::create(
35
-            FormAction::create('doFilterLocations')
36
-                ->setTitle('Search')
37
-        );
38
-
39
-        $validator = RequiredFields::create();
40
-
41
-        parent::__construct($controller, $name, $fields, $actions, $validator);
42
-    }
9
+	/**
10
+	 * LocatorForm constructor.
11
+	 * @param Controller $controller
12
+	 * @param string $name
13
+	 */
14
+	public function __construct(Controller $controller, $name)
15
+	{
16
+
17
+		$fields = FieldList::create(
18
+			TextField::create('Address')
19
+				->setTitle('')
20
+				->setAttribute('placeholder', 'address or zip code')
21
+		);
22
+
23
+		$categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
24
+			? Locator::locator_categories_by_locator($controller->data()->ID)
25
+			: Locator::get_all_categories();
26
+
27
+		$categoriesField = DropdownField::create('CategoryID')
28
+			->setTitle('')
29
+			->setEmptyString('All Categories')
30
+			->setSource($categories->map());
31
+
32
+		$fields->push($categoriesField);
33
+
34
+		$actions = FieldList::create(
35
+			FormAction::create('doFilterLocations')
36
+				->setTitle('Search')
37
+		);
38
+
39
+		$validator = RequiredFields::create();
40
+
41
+		parent::__construct($controller, $name, $fields, $actions, $validator);
42
+	}
43 43
 
44 44
 }
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
code/form/LocatorBootstrapForm.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -2,46 +2,46 @@
 block discarded – undo
2 2
 
3 3
 if (class_exists('BootstrapForm')) {
4 4
 
5
-    /**
6
-     * Class LocatorForm
7
-     */
8
-    class LocatorBootstrapForm extends BootstrapForm
9
-    {
10
-
11
-        /**
12
-         * LocatorForm constructor.
13
-         * @param Controller $controller
14
-         * @param string $name
15
-         */
16
-        public function __construct(Controller $controller, $name)
17
-        {
18
-            $fields = FieldList::create(
19
-                TextField::create('Address')
20
-                    ->setTitle('')
21
-                    ->setAttribute('placeholder', 'address or zip code')
22
-            );
23
-
24
-            $categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
25
-                ? Locator::locator_categories_by_locator($controller->data()->ID)
26
-                : Locator::get_all_categories();
27
-
28
-            $categoriesField = DropdownField::create('CategoryID')
29
-                ->setTitle('')
30
-                ->setEmptyString('All Categories')
31
-                ->setSource($categories->map());
32
-
33
-            $fields->push($categoriesField);
34
-
35
-            $actions = FieldList::create(
36
-                FormAction::create('doFilterLocations')
37
-                    ->setTitle('Search')
38
-            );
39
-
40
-            $validator = RequiredFields::create();
41
-
42
-            parent::__construct($controller, $name, $fields, $actions, $validator);
43
-        }
44
-
45
-    }
5
+	/**
6
+	 * Class LocatorForm
7
+	 */
8
+	class LocatorBootstrapForm extends BootstrapForm
9
+	{
10
+
11
+		/**
12
+		 * LocatorForm constructor.
13
+		 * @param Controller $controller
14
+		 * @param string $name
15
+		 */
16
+		public function __construct(Controller $controller, $name)
17
+		{
18
+			$fields = FieldList::create(
19
+				TextField::create('Address')
20
+					->setTitle('')
21
+					->setAttribute('placeholder', 'address or zip code')
22
+			);
23
+
24
+			$categories = (Locator::locator_categories_by_locator($controller->data()->ID)->count() > 0)
25
+				? Locator::locator_categories_by_locator($controller->data()->ID)
26
+				: Locator::get_all_categories();
27
+
28
+			$categoriesField = DropdownField::create('CategoryID')
29
+				->setTitle('')
30
+				->setEmptyString('All Categories')
31
+				->setSource($categories->map());
32
+
33
+			$fields->push($categoriesField);
34
+
35
+			$actions = FieldList::create(
36
+				FormAction::create('doFilterLocations')
37
+					->setTitle('Search')
38
+			);
39
+
40
+			$validator = RequiredFields::create();
41
+
42
+			parent::__construct($controller, $name, $fields, $actions, $validator);
43
+		}
44
+
45
+	}
46 46
 
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
code/pages/Locator.php 2 patches
Indentation   +365 added lines, -365 removed lines patch added patch discarded remove patch
@@ -11,137 +11,137 @@  discard block
 block discarded – undo
11 11
 class Locator extends Page
12 12
 {
13 13
 
14
-    /**
15
-     * @var array
16
-     */
17
-    private static $db = array(
18
-        'AutoGeocode' => 'Boolean',
19
-        'ModalWindow' => 'Boolean',
20
-        'Unit' => 'Enum("m,km","m")',
21
-    );
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private static $many_many = array(
27
-        'Categories' => 'LocationCategory',
28
-    );
29
-
30
-    /**
31
-     * @var array
32
-     */
33
-    private static $defaults = array(
34
-        'AutoGeocode' => true,
35
-    );
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    private static $singular_name = 'Locator';
41
-    /**
42
-     * @var string
43
-     */
44
-    private static $plural_name = 'Locators';
45
-    /**
46
-     * @var string
47
-     */
48
-    private static $description = 'Find locations on a map';
49
-
50
-    /**
51
-     * @return FieldList
52
-     */
53
-    public function getCMSFields()
54
-    {
55
-        $fields = parent::getCMSFields();
56
-
57
-        // Settings
58
-        $fields->addFieldsToTab('Root.Settings', array(
59
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
60
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
61
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
62
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
63
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
64
-        ));
65
-
66
-        // Filter categories
67
-        $config = GridFieldConfig_RelationEditor::create();
68
-        if (class_exists('GridFieldAddExistingSearchButton')) {
69
-            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
70
-            $config->addComponent(new GridFieldAddExistingSearchButton());
71
-        }
72
-        $categories = $this->Categories();
73
-        $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
74
-            ->setDescription('only show locations from the selected category');
75
-
76
-        // Filter
77
-        $fields->addFieldsToTab('Root.Filter', array(
78
-            HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
79
-            $categoriesField,
80
-        ));
81
-
82
-        $this->extend('updateCMSFields', $fields);
83
-
84
-        return $fields;
85
-    }
86
-
87
-    /**
88
-     * @param array $filter
89
-     * @param array $filterAny
90
-     * @param array $exclude
91
-     * @param null|callable $callback
92
-     * @return DataList|ArrayList
93
-     */
94
-    public static function get_locations(
95
-        $filter = [],
96
-        $filterAny = [],
97
-        $exclude = [],
98
-        $callback = null
99
-    )
100
-    {
101
-        $locations = Location::get()->filter($filter)->exclude($exclude);
102
-
103
-        if (!empty($filterAny)) {
104
-            $locations = $locations->filterAny($filterAny);
105
-        }
106
-        if (!empty($exclude)) {
107
-            $locations = $locations->exclude($exclude);
108
-        }
109
-
110
-        if ($callback !== null && is_callable($callback)) {
111
-            $locations->filterByCallback($callback);
112
-        }
113
-
114
-        return $locations;
115
-    }
116
-
117
-    /**
118
-     * @return DataList
119
-     */
120
-    public static function get_all_categories()
121
-    {
122
-        return LocationCategory::get();
123
-    }
124
-
125
-    /**
126
-     * @return bool
127
-     */
128
-    public function getPageCategories()
129
-    {
130
-        return self::locator_categories_by_locator($this->ID);
131
-    }
132
-
133
-    /**
134
-     * @param int $id
135
-     * @return bool|
136
-     */
137
-    public static function locator_categories_by_locator($id = 0)
138
-    {
139
-        if ($id == 0) {
140
-            return false;
141
-        }
142
-
143
-        return Locator::get()->byID($id)->Categories();
144
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	private static $db = array(
18
+		'AutoGeocode' => 'Boolean',
19
+		'ModalWindow' => 'Boolean',
20
+		'Unit' => 'Enum("m,km","m")',
21
+	);
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private static $many_many = array(
27
+		'Categories' => 'LocationCategory',
28
+	);
29
+
30
+	/**
31
+	 * @var array
32
+	 */
33
+	private static $defaults = array(
34
+		'AutoGeocode' => true,
35
+	);
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	private static $singular_name = 'Locator';
41
+	/**
42
+	 * @var string
43
+	 */
44
+	private static $plural_name = 'Locators';
45
+	/**
46
+	 * @var string
47
+	 */
48
+	private static $description = 'Find locations on a map';
49
+
50
+	/**
51
+	 * @return FieldList
52
+	 */
53
+	public function getCMSFields()
54
+	{
55
+		$fields = parent::getCMSFields();
56
+
57
+		// Settings
58
+		$fields->addFieldsToTab('Root.Settings', array(
59
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
60
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
61
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
62
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
63
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
64
+		));
65
+
66
+		// Filter categories
67
+		$config = GridFieldConfig_RelationEditor::create();
68
+		if (class_exists('GridFieldAddExistingSearchButton')) {
69
+			$config->removeComponentsByType('GridFieldAddExistingAutocompleter');
70
+			$config->addComponent(new GridFieldAddExistingSearchButton());
71
+		}
72
+		$categories = $this->Categories();
73
+		$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
74
+			->setDescription('only show locations from the selected category');
75
+
76
+		// Filter
77
+		$fields->addFieldsToTab('Root.Filter', array(
78
+			HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
79
+			$categoriesField,
80
+		));
81
+
82
+		$this->extend('updateCMSFields', $fields);
83
+
84
+		return $fields;
85
+	}
86
+
87
+	/**
88
+	 * @param array $filter
89
+	 * @param array $filterAny
90
+	 * @param array $exclude
91
+	 * @param null|callable $callback
92
+	 * @return DataList|ArrayList
93
+	 */
94
+	public static function get_locations(
95
+		$filter = [],
96
+		$filterAny = [],
97
+		$exclude = [],
98
+		$callback = null
99
+	)
100
+	{
101
+		$locations = Location::get()->filter($filter)->exclude($exclude);
102
+
103
+		if (!empty($filterAny)) {
104
+			$locations = $locations->filterAny($filterAny);
105
+		}
106
+		if (!empty($exclude)) {
107
+			$locations = $locations->exclude($exclude);
108
+		}
109
+
110
+		if ($callback !== null && is_callable($callback)) {
111
+			$locations->filterByCallback($callback);
112
+		}
113
+
114
+		return $locations;
115
+	}
116
+
117
+	/**
118
+	 * @return DataList
119
+	 */
120
+	public static function get_all_categories()
121
+	{
122
+		return LocationCategory::get();
123
+	}
124
+
125
+	/**
126
+	 * @return bool
127
+	 */
128
+	public function getPageCategories()
129
+	{
130
+		return self::locator_categories_by_locator($this->ID);
131
+	}
132
+
133
+	/**
134
+	 * @param int $id
135
+	 * @return bool|
136
+	 */
137
+	public static function locator_categories_by_locator($id = 0)
138
+	{
139
+		if ($id == 0) {
140
+			return false;
141
+		}
142
+
143
+		return Locator::get()->byID($id)->Categories();
144
+	}
145 145
 
146 146
 
147 147
 }
@@ -151,111 +151,111 @@  discard block
 block discarded – undo
151 151
  */
152 152
 class Locator_Controller extends Page_Controller
153 153
 {
154
-    /**
155
-     * @var array
156
-     */
157
-    private static $allowed_actions = array(
158
-        'xml',
159
-    );
160
-
161
-    /**
162
-     * @var array
163
-     */
164
-    private static $base_filter = [
165
-        'ShowInLocator' => true,
166
-    ];
167
-
168
-    /**
169
-     * @var array
170
-     */
171
-    private static $base_exclude = [
172
-        'Lat' => 0,
173
-        'Lng' => 0,
174
-    ];
175
-
176
-    /**
177
-     * @var array
178
-     */
179
-    private static $base_filter_any = [];
180
-
181
-    /**
182
-     * @var string
183
-     */
184
-    private static $list_template_path = 'locator/templates/location-list-description.html';
185
-
186
-    /**
187
-     * @var string
188
-     */
189
-    private static $info_window_template_path = 'locator/templates/infowindow-description.html';
190
-
191
-    /**
192
-     * @var bool
193
-     */
194
-    private static $bootstrapify = true;
195
-
196
-    /**
197
-     * @var DataList|ArrayList
198
-     */
199
-    private $locations;
200
-
201
-    /**
202
-     * Set Requirements based on input from CMS
203
-     */
204
-    public function init()
205
-    {
206
-        parent::init();
207
-
208
-        // google maps api key
209
-        $key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
210
-
211
-        $locations = $this->getLocations();
212
-
213
-        if ($locations) {
214
-
215
-            Requirements::css('locator/css/map.css');
216
-            Requirements::javascript('framework/thirdparty/jquery/jquery.js');
217
-            Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
218
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
219
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
220
-
221
-            $featuredInList = ($locations->filter('Featured', true)->count() > 0);
222
-            $defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
223
-            $isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE);
224
-
225
-            $featured = $featuredInList
226
-                ? 'featuredLocations: true'
227
-                : 'featuredLocations: false';
228
-
229
-            // map config based on user input in Settings tab
230
-            // AutoGeocode or Full Map
231
-            if ($this->data()->AutoGeocode) {
232
-                $load = $featuredInList || $defaultCoords != '' || $isChrome
233
-                    ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
234
-                    : 'autoGeocode: true, fullMapStart: false,';
235
-            } else {
236
-                $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
237
-            }
238
-
239
-            $listTemplatePath = $this->config()->get('list_template_path');
240
-            $infowindowTemplatePath = $this->config()->get('info_window_template_path');
241
-
242
-            // in page or modal
243
-            $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
244
-
245
-            $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
246
-
247
-            // pass GET variables to xml action
248
-            $vars = $this->request->getVars();
249
-            unset($vars['url']);
250
-            unset($vars['action_doFilterLocations']);
251
-            $url = '';
252
-            if (count($vars)) {
253
-                $url .= '?' . http_build_query($vars);
254
-            }
255
-            $link = $this->Link() . 'xml.xml' . $url;
256
-
257
-            // init map
258
-            Requirements::customScript("
154
+	/**
155
+	 * @var array
156
+	 */
157
+	private static $allowed_actions = array(
158
+		'xml',
159
+	);
160
+
161
+	/**
162
+	 * @var array
163
+	 */
164
+	private static $base_filter = [
165
+		'ShowInLocator' => true,
166
+	];
167
+
168
+	/**
169
+	 * @var array
170
+	 */
171
+	private static $base_exclude = [
172
+		'Lat' => 0,
173
+		'Lng' => 0,
174
+	];
175
+
176
+	/**
177
+	 * @var array
178
+	 */
179
+	private static $base_filter_any = [];
180
+
181
+	/**
182
+	 * @var string
183
+	 */
184
+	private static $list_template_path = 'locator/templates/location-list-description.html';
185
+
186
+	/**
187
+	 * @var string
188
+	 */
189
+	private static $info_window_template_path = 'locator/templates/infowindow-description.html';
190
+
191
+	/**
192
+	 * @var bool
193
+	 */
194
+	private static $bootstrapify = true;
195
+
196
+	/**
197
+	 * @var DataList|ArrayList
198
+	 */
199
+	private $locations;
200
+
201
+	/**
202
+	 * Set Requirements based on input from CMS
203
+	 */
204
+	public function init()
205
+	{
206
+		parent::init();
207
+
208
+		// google maps api key
209
+		$key = Config::inst()->get('GoogleGeocoding', 'google_api_key');
210
+
211
+		$locations = $this->getLocations();
212
+
213
+		if ($locations) {
214
+
215
+			Requirements::css('locator/css/map.css');
216
+			Requirements::javascript('framework/thirdparty/jquery/jquery.js');
217
+			Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
218
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
219
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
220
+
221
+			$featuredInList = ($locations->filter('Featured', true)->count() > 0);
222
+			$defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
223
+			$isChrome = (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE);
224
+
225
+			$featured = $featuredInList
226
+				? 'featuredLocations: true'
227
+				: 'featuredLocations: false';
228
+
229
+			// map config based on user input in Settings tab
230
+			// AutoGeocode or Full Map
231
+			if ($this->data()->AutoGeocode) {
232
+				$load = $featuredInList || $defaultCoords != '' || $isChrome
233
+					? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
234
+					: 'autoGeocode: true, fullMapStart: false,';
235
+			} else {
236
+				$load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
237
+			}
238
+
239
+			$listTemplatePath = $this->config()->get('list_template_path');
240
+			$infowindowTemplatePath = $this->config()->get('info_window_template_path');
241
+
242
+			// in page or modal
243
+			$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
244
+
245
+			$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
246
+
247
+			// pass GET variables to xml action
248
+			$vars = $this->request->getVars();
249
+			unset($vars['url']);
250
+			unset($vars['action_doFilterLocations']);
251
+			$url = '';
252
+			if (count($vars)) {
253
+				$url .= '?' . http_build_query($vars);
254
+			}
255
+			$link = $this->Link() . 'xml.xml' . $url;
256
+
257
+			// init map
258
+			Requirements::customScript("
259 259
                 $(function(){
260 260
                     $('#map-container').storeLocator({
261 261
                         " . $load . "
@@ -274,134 +274,134 @@  discard block
 block discarded – undo
274 274
                     });
275 275
                 });
276 276
             ');
277
-        }
278
-    }
279
-
280
-    /**
281
-     * @param SS_HTTPRequest $request
282
-     *
283
-     * @return ViewableData_Customised
284
-     */
285
-    public function index(SS_HTTPRequest $request)
286
-    {
287
-        $locations = $this->getLocations();
288
-
289
-        if ($locations->canSortBy('distance')) {
290
-            $locations = $locations->sort('distance');
291
-        }
292
-
293
-        return $this->customise(array(
294
-            'Locations' => $locations,
295
-        ));
296
-    }
297
-
298
-    /**
299
-     * Return a XML feed of all locations marked "show in locator"
300
-     *
301
-     * @param SS_HTTPRequest $request
302
-     * @return HTMLText
303
-     */
304
-    public function xml(SS_HTTPRequest $request)
305
-    {
306
-        $locations = $this->getLocations();
307
-
308
-        if ($locations->canSortBy('distance')) {
309
-            $locations = $locations->sort('distance');
310
-        }
311
-
312
-        return $this->customise(array(
313
-            'Locations' => $locations,
314
-        ))->renderWith('LocationXML');
315
-    }
316
-
317
-    /**
318
-     * @return ArrayList|DataList
319
-     */
320
-    public function getLocations()
321
-    {
322
-        if (!$this->locations) {
323
-            $this->setLocations($this->request);
324
-        }
325
-        return $this->locations;
326
-    }
327
-
328
-    /**
329
-     * @param SS_HTTPRequest|null $request
330
-     * @return $this
331
-     */
332
-    public function setLocations(SS_HTTPRequest $request = null)
333
-    {
334
-
335
-        if ($request === null) {
336
-            $request = $this->request;
337
-        }
338
-        $filter = ArrayData::create($this->config()->get('base_filter'));
339
-
340
-        if ($request->getVar('CategoryID')) {
341
-            $filter->CategoryID = $request->getVar('CategoryID');
342
-        }
343
-
344
-        $this->extend('updateLocatorFilter', $filter, $request);
345
-        $filter = $filter->toMap();
346
-
347
-        $filterAny = ArrayData::create($this->config()->get('base_filter_any'));
348
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
349
-        $filterAny = $filterAny->toMap();
350
-
351
-        $exclude = ArrayData::create($this->config()->get('base_exclude'));
352
-        $this->extend('updateLocatorExclude', $exclude, $request);
353
-        $exclude = $exclude->toMap();
354
-
355
-        $callback = null;
356
-        $this->extend('updateLocatorCallback', $callback, $request);
357
-
358
-        $locations = Locator::get_locations($filter, $filterAny, $exclude, $callback);
359
-        $locations = DataToArrayListHelper::to_array_list($locations);
360
-
361
-        $this->extend('alterListType', $locations);//allow for setting as grouped list
362
-
363
-        $this->locations = $locations;
364
-        return $this;
365
-
366
-    }
367
-
368
-    /**
369
-     * @return bool|string
370
-     */
371
-    public function getAddressSearchCoords()
372
-    {
373
-        if (!$this->request->getVar('Address')) {
374
-            return false;
375
-        }
376
-        $coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
377
-
378
-        $lat = $coords['lat'];
379
-        $lng = $coords['lng'];
380
-
381
-        return "defaultLat: {$lat}, defaultLng: {$lng},";
382
-    }
383
-
384
-    /**
385
-     * LocationSearch form.
386
-     *
387
-     * Search form for locations, updates map and results list via AJAX
388
-     *
389
-     * @return Form
390
-     */
391
-    public function LocationSearch()
392
-    {
393
-
394
-        $form = LocatorForm::create($this, 'LocationSearch');
395
-        if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) {
396
-            $form->Fields()->bootstrapify();
397
-            $form->Actions()->bootstrapify();
398
-        }
399
-
400
-        return $form
401
-            ->setFormMethod('GET')
402
-            ->setFormAction($this->Link())
403
-            ->disableSecurityToken()
404
-            ->loadDataFrom($this->request->getVars());
405
-    }
277
+		}
278
+	}
279
+
280
+	/**
281
+	 * @param SS_HTTPRequest $request
282
+	 *
283
+	 * @return ViewableData_Customised
284
+	 */
285
+	public function index(SS_HTTPRequest $request)
286
+	{
287
+		$locations = $this->getLocations();
288
+
289
+		if ($locations->canSortBy('distance')) {
290
+			$locations = $locations->sort('distance');
291
+		}
292
+
293
+		return $this->customise(array(
294
+			'Locations' => $locations,
295
+		));
296
+	}
297
+
298
+	/**
299
+	 * Return a XML feed of all locations marked "show in locator"
300
+	 *
301
+	 * @param SS_HTTPRequest $request
302
+	 * @return HTMLText
303
+	 */
304
+	public function xml(SS_HTTPRequest $request)
305
+	{
306
+		$locations = $this->getLocations();
307
+
308
+		if ($locations->canSortBy('distance')) {
309
+			$locations = $locations->sort('distance');
310
+		}
311
+
312
+		return $this->customise(array(
313
+			'Locations' => $locations,
314
+		))->renderWith('LocationXML');
315
+	}
316
+
317
+	/**
318
+	 * @return ArrayList|DataList
319
+	 */
320
+	public function getLocations()
321
+	{
322
+		if (!$this->locations) {
323
+			$this->setLocations($this->request);
324
+		}
325
+		return $this->locations;
326
+	}
327
+
328
+	/**
329
+	 * @param SS_HTTPRequest|null $request
330
+	 * @return $this
331
+	 */
332
+	public function setLocations(SS_HTTPRequest $request = null)
333
+	{
334
+
335
+		if ($request === null) {
336
+			$request = $this->request;
337
+		}
338
+		$filter = ArrayData::create($this->config()->get('base_filter'));
339
+
340
+		if ($request->getVar('CategoryID')) {
341
+			$filter->CategoryID = $request->getVar('CategoryID');
342
+		}
343
+
344
+		$this->extend('updateLocatorFilter', $filter, $request);
345
+		$filter = $filter->toMap();
346
+
347
+		$filterAny = ArrayData::create($this->config()->get('base_filter_any'));
348
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
349
+		$filterAny = $filterAny->toMap();
350
+
351
+		$exclude = ArrayData::create($this->config()->get('base_exclude'));
352
+		$this->extend('updateLocatorExclude', $exclude, $request);
353
+		$exclude = $exclude->toMap();
354
+
355
+		$callback = null;
356
+		$this->extend('updateLocatorCallback', $callback, $request);
357
+
358
+		$locations = Locator::get_locations($filter, $filterAny, $exclude, $callback);
359
+		$locations = DataToArrayListHelper::to_array_list($locations);
360
+
361
+		$this->extend('alterListType', $locations);//allow for setting as grouped list
362
+
363
+		$this->locations = $locations;
364
+		return $this;
365
+
366
+	}
367
+
368
+	/**
369
+	 * @return bool|string
370
+	 */
371
+	public function getAddressSearchCoords()
372
+	{
373
+		if (!$this->request->getVar('Address')) {
374
+			return false;
375
+		}
376
+		$coords = GoogleGeocoding::address_to_point(Controller::curr()->getRequest()->getVar('Address'));
377
+
378
+		$lat = $coords['lat'];
379
+		$lng = $coords['lng'];
380
+
381
+		return "defaultLat: {$lat}, defaultLng: {$lng},";
382
+	}
383
+
384
+	/**
385
+	 * LocationSearch form.
386
+	 *
387
+	 * Search form for locations, updates map and results list via AJAX
388
+	 *
389
+	 * @return Form
390
+	 */
391
+	public function LocationSearch()
392
+	{
393
+
394
+		$form = LocatorForm::create($this, 'LocationSearch');
395
+		if (class_exists('BootstrapForm') && $this->config()->get('bootstrapify')) {
396
+			$form->Fields()->bootstrapify();
397
+			$form->Actions()->bootstrapify();
398
+		}
399
+
400
+		return $form
401
+			->setFormMethod('GET')
402
+			->setFormAction($this->Link())
403
+			->disableSecurityToken()
404
+			->loadDataFrom($this->request->getVars());
405
+	}
406 406
 
407 407
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
             Requirements::css('locator/css/map.css');
216 216
             Requirements::javascript('framework/thirdparty/jquery/jquery.js');
217
-            Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
217
+            Requirements::javascript('https://maps.google.com/maps/api/js?key='.$key);
218 218
             Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
219 219
             Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
220 220
 
@@ -250,27 +250,27 @@  discard block
 block discarded – undo
250 250
             unset($vars['action_doFilterLocations']);
251 251
             $url = '';
252 252
             if (count($vars)) {
253
-                $url .= '?' . http_build_query($vars);
253
+                $url .= '?'.http_build_query($vars);
254 254
             }
255
-            $link = $this->Link() . 'xml.xml' . $url;
255
+            $link = $this->Link().'xml.xml'.$url;
256 256
 
257 257
             // init map
258 258
             Requirements::customScript("
259 259
                 $(function(){
260 260
                     $('#map-container').storeLocator({
261
-                        " . $load . "
262
-                        dataLocation: '" . $link . "',
263
-                        listTemplatePath: '" . $listTemplatePath . "',
264
-                        infowindowTemplatePath: '" . $infowindowTemplatePath . "',
261
+                        " . $load."
262
+                        dataLocation: '" . $link."',
263
+                        listTemplatePath: '" . $listTemplatePath."',
264
+                        infowindowTemplatePath: '" . $infowindowTemplatePath."',
265 265
                         originMarker: true,
266
-                        " . $modal . ',
267
-                        ' . $featured . ",
266
+                        " . $modal.',
267
+                        ' . $featured.",
268 268
                         slideMap: false,
269 269
                         zoomLevel: 0,
270 270
                         noForm: true,
271 271
                         distanceAlert: -1,
272
-                        " . $kilometer . ',
273
-                        ' . $defaultCoords . '
272
+                        " . $kilometer.',
273
+                        ' . $defaultCoords.'
274 274
                     });
275 275
                 });
276 276
             ');
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
         $locations = Locator::get_locations($filter, $filterAny, $exclude, $callback);
359 359
         $locations = DataToArrayListHelper::to_array_list($locations);
360 360
 
361
-        $this->extend('alterListType', $locations);//allow for setting as grouped list
361
+        $this->extend('alterListType', $locations); //allow for setting as grouped list
362 362
 
363 363
         $this->locations = $locations;
364 364
         return $this;
Please login to merge, or discard this patch.