mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Improve class naming and docs for DataList::applyFilterContext()
This commit is contained in:
parent
7be8a2252f
commit
c23df511cd
@ -386,7 +386,7 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
$fieldArgs = explode(':',$field);
|
$fieldArgs = explode(':',$field);
|
||||||
$field = array_shift($fieldArgs);
|
$field = array_shift($fieldArgs);
|
||||||
foreach($fieldArgs as $fieldArg){
|
foreach($fieldArgs as $fieldArg){
|
||||||
$comparisor = $this->applyFilterContext($field, $fieldArg, $value);
|
$this->applyFilterContext($field, $fieldArg, $value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if($field == 'ID') {
|
if($field == 'ID') {
|
||||||
@ -455,20 +455,20 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates the comparisator to the sql query
|
* Translates a filter type to a SQL query.
|
||||||
*
|
*
|
||||||
* @param string $field - the fieldname in the db
|
* @param string $field - the fieldname in the db
|
||||||
* @param string $comparisators - example StartsWith, relates to a filtercontext
|
* @param string $filter - a {@link SearchFilter} class, e.g. PartialMatch or StartsWith
|
||||||
* @param string $value - the value that the filtercontext will use for matching
|
* @param string $value - the value that the filtercontext will use for matching
|
||||||
* @todo Deprecated SearchContexts and pull their functionality into the core of the ORM
|
* @todo Deprecated SearchContexts and pull their functionality into the core of the ORM
|
||||||
*/
|
*/
|
||||||
private function applyFilterContext($field, $comparisators, $value) {
|
private function applyFilterContext($field, $filter, $value) {
|
||||||
$t = singleton($this->dataClass())->dbObject($field);
|
$t = singleton($this->dataClass())->dbObject($field);
|
||||||
$className = "{$comparisators}Filter";
|
$className = sprintf('%sFilter', $filter);
|
||||||
if(!class_exists($className)){
|
if(!class_exists($className)) {
|
||||||
throw new InvalidArgumentException('There are no '.$comparisators.' comparisator');
|
throw new InvalidArgumentException(sprintf('Filter class "%s" does not exist', $className));
|
||||||
}
|
}
|
||||||
$t = new $className($field,$value);
|
$t = new $className($field, $value);
|
||||||
$t->apply($this->dataQuery());
|
$t->apply($this->dataQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user