Add conditions config to RecordFinder

Fixes #1524
This commit is contained in:
Alexander Guth 2015-08-16 05:34:28 +10:00 committed by Samuel Georges
parent f2d8fcaf14
commit 13276a500e
1 changed files with 14 additions and 2 deletions

View File

@ -58,6 +58,11 @@ class RecordFinder extends FormWidgetBase
*/
public $scope;
/**
* @var string Filters the relation using a raw where query statement.
*/
public $conditions;
/**
* @var string If searching the records, specifies a policy to use.
* - all: result must contain all words
@ -86,12 +91,12 @@ class RecordFinder extends FormWidgetBase
public $relationModel;
/**
* @var Backend\Classes\WidgetBase Reference to the widget used for viewing (list or form).
* @var \Backend\Classes\WidgetBase Reference to the widget used for viewing (list or form).
*/
protected $listWidget;
/**
* @var Backend\Classes\WidgetBase Reference to the widget used for searching.
* @var \Backend\Classes\WidgetBase Reference to the widget used for searching.
*/
protected $searchWidget;
@ -107,6 +112,7 @@ class RecordFinder extends FormWidgetBase
'nameFrom',
'descriptionFrom',
'scope',
'conditions',
'searchMode',
'searchScope',
]);
@ -250,6 +256,12 @@ class RecordFinder extends FormWidgetBase
});
}
if ($sqlConditions = $this->conditions) {
$widget->bindEvent('list.extendQueryBefore', function($query) use ($sqlConditions) {
$query->whereRaw($sqlConditions);
});
}
return $widget;
}