Merge pull request #848 from nicolas-lescop/develop

Extend query of the filter options lists
This commit is contained in:
Samuel Georges 2015-01-03 15:58:34 +11:00
commit 4852722ba1
2 changed files with 23 additions and 2 deletions

View File

@ -217,6 +217,13 @@ class ListController extends ControllerBehavior
return $widget->onRefresh();
});
/*
* Extend the query of the list of options
*/
$filterWidget->bindEvent('filter.extendQuery', function($query, $scope) {
$this->controller->listFilterExtendQuery($query, $scope);
});
// Apply predefined filter values
$widget->addFilter([$filterWidget, 'applyAllScopesToQuery']);
@ -351,6 +358,16 @@ class ListController extends ControllerBehavior
{
}
/**
* Controller override: Extend the query used for populating the filter
* options before the default query is processed.
* @param October\Rain\Database\Builder $query
* @param array $scope
*/
public function listFilterExtendQuery($query, $scope)
{
}
/**
* Returns a CSS class name for a list row (<tr class="...">).
* @param Model $record The populated model used for the column

View File

@ -208,12 +208,16 @@ class Filter extends WidgetBase
protected function getOptionsFromModel($scope, $searchQuery = null)
{
$model = $this->scopeModels[$scope->scopeName];
$query = $model->newQuery();
$this->fireEvent('filter.extendQuery', [$query, $scope]);
if (!$searchQuery) {
return $model->all();
return $query->get();
}
$searchFields = [$model->getKeyName(), $this->getScopeNameColumn($scope)];
return $model->searchWhere($searchQuery, $searchFields)->get();
return $query->searchWhere($searchQuery, $searchFields)->get();
}
/**