Skip to content

Instantly share code, notes, and snippets.

@muskie9
Last active October 1, 2015 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muskie9/474df7b261d2b4de39fa to your computer and use it in GitHub Desktop.
Save muskie9/474df7b261d2b4de39fa to your computer and use it in GitHub Desktop.
<?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