diff --git a/code/form/LocatorForm.php b/code/form/LocatorForm.php index c885e7e..d808aac 100644 --- a/code/form/LocatorForm.php +++ b/code/form/LocatorForm.php @@ -5,6 +5,20 @@ */ class LocatorForm extends Form { + /** + * @var bool + */ + private static $show_radius = true; + + /** + * @var array + */ + private static $radius_array = [ + '25' => '25', + '50' => '50', + '75' => '75', + '100' => '100', + ]; /** * LocatorForm constructor. @@ -30,11 +44,19 @@ public function __construct(Controller $controller, $name) if ($categories) { $categoriesField = DropdownField::create('CategoryID') ->setTitle('') - ->setEmptyString('All Categories') + ->setEmptyString('all categories') ->setSource($categories->map()); $fields->push($categoriesField); } + if (Config::inst()->get('LocatorForm', 'show_radius')) { + $radiusArray = Config::inst()->get('LocatorForm', 'radius_array'); + debug::show($radiusArray); + $fields->push(DropdownField::create('Radius', '', $radiusArray) + ->setEmptyString('radius') + ); + } + $actions = FieldList::create( FormAction::create('doFilterLocations') ->setTitle('Search') diff --git a/code/pages/Locator.php b/code/pages/Locator.php index e66deaa..9108731 100644 --- a/code/pages/Locator.php +++ b/code/pages/Locator.php @@ -413,6 +413,14 @@ public function setLocations(SS_HTTPRequest $request = null) $locations = $locations->sort('distance'); } + if (Config::inst()->get('LocatorForm', 'show_radius')) { + if ($radius = (int)$request->getVar('Radius')) { + $locations = $locations->filterByCallback(function ($location) use (&$radius) { + return $location->distance <= $radius; + }); + } + } + //allow for returning list to be set as $this->extend('updateListType', $locations); diff --git a/templates/Layout/Locator.ss b/templates/Layout/Locator.ss index 5d8493d..1d14590 100644 --- a/templates/Layout/Locator.ss +++ b/templates/Layout/Locator.ss @@ -4,17 +4,19 @@
$LocationSearch
- <% if $Locations %> -
-
-
- -
-
- <% else %> -
-

No locations match your search criteria. Please refine your search and try again.

-
+ <% if $getTrigger %> + <% if $Locations %> +
+
+
+ +
+
+ <% else %> +
+

No locations match your search criteria. Please refine your search and try again.

+
+ <% end_if %> <% end_if %> \ No newline at end of file