diff --git a/admin/code/MemberTableField.php b/admin/code/MemberTableField.php old mode 100755 new mode 100644 index 8a69c638a..863b81999 --- a/admin/code/MemberTableField.php +++ b/admin/code/MemberTableField.php @@ -97,7 +97,7 @@ class MemberTableField extends ComplexTableField { foreach($SNG_member->searchableFields() as $fieldName => $fieldSpec) { if(strpos($fieldName, '.') === false) $searchFilters[] = "\"$fieldName\" LIKE '%{$SQL_search}%'"; } - $members = $members->filter('(' . implode(' OR ', $searchFilters) . ')'); + $members = $members->where('(' . implode(' OR ', $searchFilters) . ')'); } parent::__construct($controller, $name, $members, $fieldList); diff --git a/core/model/DataList.php b/core/model/DataList.php index 950e6fe2c..c94250add 100644 --- a/core/model/DataList.php +++ b/core/model/DataList.php @@ -60,11 +60,12 @@ class DataList extends DataObjectSet { } /** - * Filter this data list by a WHERE clause - * @todo Implement array syntax for this. Perhaps the WHERE clause should be $this->where()? + * Add a WHERE clause to the query. + * + * @param string $filter */ - public function filter($filter) { - $this->dataQuery->filter($filter); + public function where($filter) { + $this->dataQuery->where($filter); return $this; } @@ -235,7 +236,7 @@ class DataList extends DataObjectSet { * Find an element of this DataList where the given key = value */ public function find($key, $value) { - return $this->filter("\"$key\" = '" . Convert::raw2sql($value) . "'")->First(); + return $this->where("\"$key\" = '" . Convert::raw2sql($value) . "'")->First(); } @@ -244,7 +245,7 @@ class DataList extends DataObjectSet { */ public function byIDs(array $ids) { $baseClass = ClassInfo::baseDataClass($this->dataClass); - $this->filter("\"$baseClass\".\"ID\" IN (" . implode(',', $ids) .")"); + $this->where("\"$baseClass\".\"ID\" IN (" . implode(',', $ids) .")"); return $this; } @@ -254,7 +255,7 @@ class DataList extends DataObjectSet { */ public function byID($id) { $baseClass = ClassInfo::baseDataClass($this->dataClass); - return $this->filter("\"$baseClass\".\"ID\" = " . (int)$id)->First(); + return $this->where("\"$baseClass\".\"ID\" = " . (int)$id)->First(); } /** @@ -340,7 +341,7 @@ class DataList extends DataObjectSet { * Remove every element in this DataList matching the given $filter. */ function removeByFilter($filter) { - foreach($this->filter($filter) as $item) { + foreach($this->where($filter) as $item) { $this->remove($item); } } diff --git a/core/model/DataQuery.php b/core/model/DataQuery.php index bcea0d23e..3494ab2b6 100644 --- a/core/model/DataQuery.php +++ b/core/model/DataQuery.php @@ -269,7 +269,7 @@ class DataQuery { /** * Set the WHERE clause of this query */ - function filter($filter) { + function where($filter) { if($filter) { $clone = $this; $clone->query->where($filter); diff --git a/core/model/RelationList.php b/core/model/RelationList.php index 05321f2f1..27f72f6d0 100644 --- a/core/model/RelationList.php +++ b/core/model/RelationList.php @@ -18,7 +18,7 @@ abstract class RelationList extends DataList { if(is_array($id) && sizeof($id) == 1) $id = reset($id); $this->foreignID = $id; - $this->dataQuery->filter($this->foreignIDFilter()); + $this->dataQuery->where($this->foreignIDFilter()); } /** diff --git a/forms/TableListField.php b/forms/TableListField.php old mode 100755 new mode 100644 index ad850e0c7..27ab91d62 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -240,7 +240,7 @@ class TableListField extends FormField { $this->dataList = $sourceClass; } else { - $this->dataList = DataObject::get($sourceClass)->filter($sourceFilter) + $this->dataList = DataObject::get($sourceClass)->where($sourceFilter) ->sort($sourceSort)->join($sourceJoin); // Grab it from the form relation, if available. $this->getDataListFromForm = true; diff --git a/model/DataObject.php b/model/DataObject.php old mode 100755 new mode 100644 index da301ecb8..8da2175fd --- a/model/DataObject.php +++ b/model/DataObject.php @@ -1199,7 +1199,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity // - move the details of the delete code in the DataQuery system // - update the code to just delete the base table, and rely on cascading deletes in the DB to do the rest // obviously, that means getting requireTable() to configure cascading deletes ;-) - $srcQuery = DataList::create($this->class)->filter("ID = $this->ID")->dataQuery()->query(); + $srcQuery = DataList::create($this->class)->where("ID = $this->ID")->dataQuery()->query(); foreach($srcQuery->queriedTables() as $table) { $query = new SQLQuery("*", array('"'.$table.'"')); $query->where("\"ID\" = $this->ID"); @@ -1329,7 +1329,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity $result = new HasManyList($componentClass, $joinField); if($this->ID) $result->setForeignID($this->ID); - $result = $result->filter($filter)->limit($limit)->sort($sort)->join($join); + $result = $result->where($filter)->limit($limit)->sort($sort)->join($join); return $result; } @@ -1419,7 +1419,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity // foreignID set elsewhere. if($this->ID) $result->setForeignID($this->ID); - return $result->filter($filter)->sort($sort)->limit($limit); + return $result->where($filter)->sort($sort)->limit($limit); } /** @@ -2487,7 +2487,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity // Deprecated 2.5? // Todo: Make the $containerClass method redundant if($containerClass != "DataList") user_error("The DataObject::get() \$containerClass argument has been deprecated", E_USER_NOTICE); - $result = DataList::create($callerClass)->filter($filter)->sort($sort)->join($join)->limit($limit); + $result = DataList::create($callerClass)->where($filter)->sort($sort)->join($join)->limit($limit); return $result; } @@ -2595,7 +2595,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity ] = false; } if(!$cache || !isset(DataObject::$cache_get_one[$callerClass][$cacheKey])) { - $dl = DataList::create($callerClass)->filter($filter)->sort($orderby); + $dl = DataList::create($callerClass)->where($filter)->sort($orderby); $item = $dl->First(); if($cache) { diff --git a/model/Hierarchy.php b/model/Hierarchy.php old mode 100755 new mode 100644 index 1ddc08bf4..b98a28b86 --- a/model/Hierarchy.php +++ b/model/Hierarchy.php @@ -548,8 +548,8 @@ class Hierarchy extends DataExtension { $baseClass = ClassInfo::baseDataClass($this->owner->class); $id = $this->owner->ID; - $children = DataObject::get($baseClass)->filter("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id"); - if(!$showAll) $children = $children->filter('"ShowInMenus" = 1'); + $children = DataObject::get($baseClass)->where("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id"); + if(!$showAll) $children = $children->where('"ShowInMenus" = 1'); // Query the live site $children->dataQuery()->setQueryParam('Versioned.mode', 'stage'); @@ -558,13 +558,13 @@ class Hierarchy extends DataExtension { if($onlyDeletedFromStage) { // Note that this makes a second query, and could be optimised to be a joi; $stageChildren = DataObject::get($baseClass) - ->filter("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id"); + ->where("\"{$baseClass}\".\"ParentID\" = $id AND \"{$baseClass}\".\"ID\" != $id"); $stageChildren->dataQuery()->setQueryParam('Versioned.mode', 'stage'); $stageChildren->dataQuery()->setQueryParam('Versioned.stage', ''); $ids = $stageChildren->column("ID"); if($ids) { - $children->filter("\"$baseClass\".\"ID\" NOT IN (" . implode(',',$ids) . ")"); + $children->where("\"$baseClass\".\"ID\" NOT IN (" . implode(',',$ids) . ")"); } } diff --git a/model/Versioned.php b/model/Versioned.php index 4444bd5c1..e3ab086c7 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -955,7 +955,7 @@ class Versioned extends DataExtension { */ static function get_latest_version($class, $id) { $baseClass = ClassInfo::baseDataClass($class); - $list = DataList::create($class)->filter("\"$baseClass\".\"RecordID\" = $id"); + $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id"); $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions"); return $list->First(); } @@ -967,7 +967,7 @@ class Versioned extends DataExtension { * In particular, this will query deleted records as well as active ones. */ static function get_including_deleted($class, $filter = "", $sort = "") { - $list = DataList::create($class)->filter($filter)->sort($sort); + $list = DataList::create($class)->where($filter)->sort($sort); $list->dataQuery()->setQueryParam("Versioned.mode", "latest_versions"); return $list; } @@ -978,7 +978,7 @@ class Versioned extends DataExtension { */ static function get_version($class, $id, $version) { $baseClass = ClassInfo::baseDataClass($class); - $list = DataList::create($class)->filter("\"$baseClass\".\"RecordID\" = $id")->filter("\"$baseClass\".\"Version\" = " . (int)$version); + $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id")->where("\"$baseClass\".\"Version\" = " . (int)$version); $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions'); return $list->First(); } @@ -989,7 +989,7 @@ class Versioned extends DataExtension { */ static function get_all_versions($class, $id) { $baseClass = ClassInfo::baseDataClass($class); - $list = DataList::create($class)->filter("\"$baseClass\".\"RecordID\" = $id"); + $list = DataList::create($class)->where("\"$baseClass\".\"RecordID\" = $id"); $list->dataQuery()->setQueryParam('Versioned.mode', 'all_versions'); return $list; } diff --git a/search/filters/EndsWithFilter.php b/search/filters/EndsWithFilter.php index 3cc8eb360..89aa14ee5 100644 --- a/search/filters/EndsWithFilter.php +++ b/search/filters/EndsWithFilter.php @@ -25,7 +25,7 @@ class EndsWithFilter extends SearchFilter { */ public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); - $query->filter($this->getDbName() . " LIKE '%" . Convert::raw2sql($this->getValue()) . "'"); + $query->where($this->getDbName() . " LIKE '%" . Convert::raw2sql($this->getValue()) . "'"); } public function isEmpty() { diff --git a/search/filters/ExactMatchFilter.php b/search/filters/ExactMatchFilter.php index 9dcd28ba2..73cb7dc63 100644 --- a/search/filters/ExactMatchFilter.php +++ b/search/filters/ExactMatchFilter.php @@ -22,7 +22,7 @@ class ExactMatchFilter extends SearchFilter { */ public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); - return $query->filter(sprintf( + return $query->where(sprintf( "%s = '%s'", $this->getDbName(), Convert::raw2sql($this->getValue()) diff --git a/search/filters/ExactMatchMultiFilter.php b/search/filters/ExactMatchMultiFilter.php index 9b35f9106..7c4c80b38 100644 --- a/search/filters/ExactMatchMultiFilter.php +++ b/search/filters/ExactMatchMultiFilter.php @@ -39,7 +39,7 @@ class ExactMatchMultiFilter extends SearchFilter { } $SQL_valueStr = "'" . implode("','", $values) . "'"; - return $query->filter(sprintf( + return $query->where(sprintf( "%s IN (%s)", $this->getDbName(), $SQL_valueStr diff --git a/search/filters/GreaterThanFilter.php b/search/filters/GreaterThanFilter.php index 0556c211d..86ca0d05f 100644 --- a/search/filters/GreaterThanFilter.php +++ b/search/filters/GreaterThanFilter.php @@ -14,7 +14,7 @@ class GreaterThanFilter extends SearchFilter { */ public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); - return $query->filter(sprintf( + return $query->where(sprintf( "%s > '%s'", $this->getDbName(), Convert::raw2sql($this->getDbFormattedValue()) diff --git a/search/filters/LessThanFilter.php b/search/filters/LessThanFilter.php index b79d29a65..84b7f34ad 100644 --- a/search/filters/LessThanFilter.php +++ b/search/filters/LessThanFilter.php @@ -14,7 +14,7 @@ class LessThanFilter extends SearchFilter { */ public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); - return $query->filter(sprintf( + return $query->where(sprintf( "%s < '%s'", $this->getDbName(), Convert::raw2sql($this->getDbFormattedValue()) diff --git a/search/filters/NegationFilter.php b/search/filters/NegationFilter.php index 9d092936a..110093e3e 100644 --- a/search/filters/NegationFilter.php +++ b/search/filters/NegationFilter.php @@ -8,7 +8,7 @@ class NegationFilter extends SearchFilter { public function apply(DataQuery $query) { - return $query->filter(sprintf( + return $query->where(sprintf( "%s != '%s'", $this->getDbName(), Convert::raw2sql($this->getValue()) diff --git a/search/filters/PartialMatchFilter.php b/search/filters/PartialMatchFilter.php index cf97d48fb..4756bd5d9 100644 --- a/search/filters/PartialMatchFilter.php +++ b/search/filters/PartialMatchFilter.php @@ -14,7 +14,7 @@ class PartialMatchFilter extends SearchFilter { public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); - return $query->filter(sprintf( + return $query->where(sprintf( "%s LIKE '%%%s%%'", $this->getDbName(), Convert::raw2sql($this->getValue()) diff --git a/search/filters/StartsWithFilter.php b/search/filters/StartsWithFilter.php index fda662316..35fb33ed6 100644 --- a/search/filters/StartsWithFilter.php +++ b/search/filters/StartsWithFilter.php @@ -25,7 +25,7 @@ class StartsWithFilter extends SearchFilter { */ public function apply(DataQuery $query) { $this->model = $query->applyRelation($this->relation); - $query->filter($this->getDbName() . " LIKE '" . Convert::raw2sql($this->getValue()) . "%'"); + $query->where($this->getDbName() . " LIKE '" . Convert::raw2sql($this->getValue()) . "%'"); } public function isEmpty() { diff --git a/search/filters/StartsWithMultiFilter.php b/search/filters/StartsWithMultiFilter.php index 22f4f4dcf..7bf6c5094 100644 --- a/search/filters/StartsWithMultiFilter.php +++ b/search/filters/StartsWithMultiFilter.php @@ -25,7 +25,7 @@ class StartsWithMultiFilter extends SearchFilter { ); } - return $query->filter(implode(" OR ", $matches)); + return $query->where(implode(" OR ", $matches)); } public function isEmpty() { diff --git a/search/filters/SubstringFilter.php b/search/filters/SubstringFilter.php index a8c345d64..965413270 100644 --- a/search/filters/SubstringFilter.php +++ b/search/filters/SubstringFilter.php @@ -13,7 +13,7 @@ class SubstringFilter extends SearchFilter { public function apply(DataQuery $query) { - return $query->filter(sprintf( + return $query->where(sprintf( "LOCATE('%s', %s) != 0", Convert::raw2sql($this->getValue()), $this->getDbName() diff --git a/security/Group.php b/security/Group.php index 299ba83d7..af30c5f99 100644 --- a/security/Group.php +++ b/security/Group.php @@ -211,7 +211,7 @@ class Group extends DataObject { // Call the relation method on the DataList to get the members from all the groups return $groups->relation('DirectMembers') - ->filter($filter)->sort($sort)->join($join)->limit($limit); + ->where($filter)->sort($sort)->join($join)->limit($limit); } /** diff --git a/security/Member.php b/security/Member.php old mode 100755 new mode 100644 index 33b1b5bd4..d646a0fca --- a/security/Member.php +++ b/security/Member.php @@ -953,7 +953,7 @@ class Member extends DataObject { foreach($groups as $group) { if(!$group->allowedIPAddress($ip)) $disallowedGroups[] = $groupID; } - if($disallowedGroups) $group->filter("\"Group\".\"ID\" NOT IN (" . + if($disallowedGroups) $group->where("\"Group\".\"ID\" NOT IN (" . implode(',',$disallowedGroups) . ")"); return $groups;