Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

SearchContext filters and WithinRangeFilter


Reply

5 Posts   1600 Views

Avatar
Terry Apodaca

22 March 2010 at 12:37pm Community Member, 109 Posts

I've seen this listed in most places as being Incomplete...but I was wondering if someone can tell me if it actually works...and if so, how do I implement it?

If it's not ready, can someone tell me how to use the filters that are in place to mimic this? I have to add to a search I currently have something that will require this. I need to be able to search for properties that are between two given input fields:

Square Feet Range: High (input box) and Low (input box).

Avatar
Terry Apodaca

23 March 2010 at 6:13am Community Member, 109 Posts

Is there a simple way to modify this in the $searchCriteria?

this is what the actual $query looks like:

SELECT `Property`.*, `Property`.ID, if(`Property`.ClassName,`Property`.ClassName,'Property') AS RecordClassName
FROM `Property`
WHERE (`Property`.`SQFTRangeLow` > '200') AND (`Property`.`SQFTRangeHigh` < '500')

and this is what I need it to look like:

SELECT `Property`.*, `Property`.ID, if(`Property`.ClassName,`Property`.ClassName,'Property') AS RecordClassName
FROM `Property`
WHERE (`Property`.`SQFTRangeLow` >= '200' AND `Property`.`SQFTRangeHigh` <= '500')

wish there was an easy way to make this a BETWEEN clause.

Avatar
Terry Apodaca

23 March 2010 at 12:03pm Community Member, 109 Posts

Someone has to know a way to do what I want to do here...or know how to use the WithinRangeFilter...

Avatar
VRoxane

14 January 2012 at 4:20am Community Member, 42 Posts

Hi Terry !

I was wondering if you managed to use that WithinRangeFilter.
I have trouble doing a "GreaterThan or equal filter" in my search form :( ... and a Lessthan or equal as well !

That filter would be of great use !

Avatar
chillburn.com.au

25 January 2012 at 7:51pm Community Member, 12 Posts

I haven't used the WithinRangeFilter before but by looking at the code, sapphire/search/filters/WithinRangeFilter.php you will probably need to do something like:

//setup within range filter 200 - 500
$within_range_filter = new WithinRangeFilter('SQFTRangeLow');
$within_range_filter->setMin(200);
$within_range_filter->setMax(500);

//then perhaps do something like this.
$filters = array(
'SQFTRangeLow' => $within_range_filter
);

return new SearchContext(
$this->class,
$fields,
$filters
);