Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX: Ensure that DataList::filter() doesn't modify the original ob…

…ject.
  • Loading branch information...
commit e19ab7aa5acf39b84f4f7b4f45300617c97acf79 1 parent 0821f02
Sam Minnée sminnee authored
Showing with 17 additions and 9 deletions.
  1. +17 −9 model/DataList.php
26 model/DataList.php
View
@@ -220,18 +220,26 @@ public function sort() {
* @return DataList
*/
public function filter() {
- $numberFuncArgs = count(func_get_args());
- $whereArguments = array();
- if($numberFuncArgs == 1 && is_array(func_get_arg(0))) {
- $whereArguments = func_get_arg(0);
- } elseif($numberFuncArgs == 2) {
- $whereArguments[func_get_arg(0)] = func_get_arg(1);
- } else {
- throw new InvalidArgumentException('Incorrect number of arguments passed to filter()');
+ // Validate and process arguments
+ $arguments = func_get_args();
+ switch(sizeof($arguments)) {
+ case 1: $filters = $arguments[0]; break;
+ case 2: $filters = array($arguments[0] => $arguments[1]); break;
+ default:
+ throw new InvalidArgumentException('Incorrect number of arguments passed to filter()');
}
+
+ $clone = clone $this;
+ $clone->addFilter($filters);
+ return $clone;
+ }
+ /**
+ * Modify this DataList, adding a filter
+ */
+ public function addFilter($filterArray) {
$SQL_Statements = array();
- foreach($whereArguments as $field => $value) {
+ foreach($filterArray as $field => $value) {
if(is_array($value)) {
$customQuery = 'IN (\''.implode('\',\'',Convert::raw2sql($value)).'\')';
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.