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   1611 Views

Avatar
Terry Apodaca

Community Member, 109 Posts

22 March 2010 at 12:37pm

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

Community Member, 109 Posts

23 March 2010 at 6:13am

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

Community Member, 109 Posts

23 March 2010 at 12:03pm

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

Avatar
VRoxane

Community Member, 42 Posts

14 January 2012 at 4:20am

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

Community Member, 12 Posts

25 January 2012 at 7:51pm

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
);