Last active
October 1, 2015 15:35
-
-
Save muskie9/474df7b261d2b4de39fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyClass extends Page{ | |
public static function getFilteredList(SS_HTTPRequest $request = null){ | |
//assume the request var holds a valid SS_HTTPRequest | |
$list = MyObject::get(); | |
if($someVar = $request->getVar('Somevar')){ | |
$list = $list->filter('Somevar', $someVar); | |
} | |
if($anotherVar = $request->getVar('AnotherVar')){ | |
$list = $list->filter('AnotherVar', $anotherVar); | |
} | |
//to this point the list is filtered fine with proper results | |
if($yetAnother = $request->getVar('YetAnother')){ | |
$filterByThat = function($obj){ | |
return $obj->myFunctionThatCalcs();//function returns true/false on the MyObject being iterated over | |
}; | |
$list = $list->filterByCallback($filterByThat); | |
} | |
//list now only filtered by the callback if YetAnother is set as a GET var | |
return $list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment