Commit 8a309525 authored by Ad Schellevis's avatar Ad Schellevis

(mvc) add easier model wrapper for default search behavior

parent 3592b64f
......@@ -49,6 +49,31 @@ class UIModelGrid
$this->DataField = $DataField;
}
/**
* default model search
* @param $request request variable
* @param array $fields to collect
* @param null|string $defaultSort default sort order
* @return array
*/
public function fetchBindRequest($request, $fields, $defaultSort = null)
{
$itemsPerPage = $request->get('rowCount', 'int', 9999);
$currentPage = $request->get('current', 'int', 1);
$sortBy = array($defaultSort);
$sortDescending = false;
if ($request->has('sort') && is_array($request->get("sort"))) {
$sortBy = array_keys($request->get("sort"));
if ($request->get("sort")[$sortBy[0]] == "desc") {
$sortDescending = true;
}
}
$searchPhrase = $request->get('searchPhrase', 'string', '');
return $this->fetch($fields, $itemsPerPage, $currentPage, $sortBy, $sortDescending, $searchPhrase);
}
/**
* Fetch data from Array type field (Base\FieldTypes\ArrayField), sorted by specified fields and optionally filtered
* @param array $fields select fieldnames
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment