Macrura Posted October 27, 2013 Share Posted October 27, 2013 I have a situation where a template has 2 age range fields: age_min and age_max. If the age_max is blank, i would like to tell the api to treat that as the number 99, so that searches by age will return results; i'm using a search system very similar to the skyscrapers profile; I couldn't come up with a selector that would return results with this situation; for now it works if we enter 99 as the age_max; but looking for a backup for the pages already entered.. Link to comment Share on other sites More sharing options...
BUCKHORN Posted October 28, 2013 Share Posted October 28, 2013 hmm, maybe try this... (untested) if(empty($page->age_max)) { $page->age_max = 99; } $people = $pages->find('age_min >= ' .$age_min. ', age_max <= '.$page->age_max); Link to comment Share on other sites More sharing options...
Macrura Posted October 28, 2013 Author Share Posted October 28, 2013 @sshaw - i don't think that would work because at the point that the if statement is run, it would only apply to the $page which would be the search page or any page with the search form; i tried a lot of ways of doing selectors with an OR; the selector is built up like in the skyscrapers profile, so has various other elements; but the part with the ages i want to return pages where age_min<=$value, age_max>=$value OR age_max='' [ so i can't do a pipe here because the >= won't work to compare to an empty field ] (age selected on the form = $value) I could add a secondary selector all through the search processor and then run 2 $pages->find at the end, one with each of the 2 selectors and then import one into the other, but i was hoping to avoid doing a double query for this, i would probably at that point just run some code to fill in all the empty fields with defaults.. main reason why i'm bringing it up is in case i'm missing some easy way to do this with a single selector string, or anyway to globally replace that field value with a hook, sort of like how in the CMS critic study, Ryan changes the default Page::path function for certain templates Link to comment Share on other sites More sharing options...
Wanze Posted October 28, 2013 Share Posted October 28, 2013 I'm not sure if I get the problem. But depending on the amount of data, you could quickly loop through and remove invalid items. However, this may introduce problems with the paging, if you use it: $results = $pages->find("your selector and then only, age_min<=$value"); foreach ($results as $result) { if (!$result->age_max) $result->age_max = 99; if ($value > $result->age_max) { $results->remove($result); } } Link to comment Share on other sites More sharing options...
Macrura Posted October 28, 2013 Author Share Posted October 28, 2013 @Wanze - good solution thanks!, this might work, i'll try it out; this is searching through about 200 pages max, so it should be ok i think for performance; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now