Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » SearchContext filters and WithinRangeFilter

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1538 Views
  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    SearchContext filters and WithinRangeFilter Link to this post

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

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: SearchContext filters and WithinRangeFilter Link to this post

    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.

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: SearchContext filters and WithinRangeFilter Link to this post

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

  • VRoxane
    Avatar
    Community Member
    42 Posts

    Re: SearchContext filters and WithinRangeFilter Link to this post

    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 !

  • chillburn.com.au
    Avatar
    Community Member
    12 Posts

    Re: SearchContext filters and WithinRangeFilter Link to this post

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

    1538 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.