Add some sort functionality and app title, case number and task title searching working properly.

This commit is contained in:
Taylor Dondich
2019-04-25 16:10:12 -07:00
committed by Paula Quispe
parent ea6b030193
commit ccf7209228

View File

@@ -81,6 +81,8 @@ class Delegation extends Model
$filterBy = 'APP_TITLE'
)
{
$search = trim($search);
// Default pagination values
$start = $start ? $start : 0;
$limit = $limit ? $limit : 25;
@@ -104,7 +106,7 @@ class Delegation extends Model
});
// Add join for application, but only for certain scenarios of app title search or sorting by app title
if($filterBy == 'APP_TITLE' || $sort == 'APP_TITLE') {
if(($filterBy == 'APP_TITLE' && $search) || $sort == 'APP_TITLE') {
$query->join('APPLICATION', function($join) use($filterBy, $search) {
$join->on('APP_DELEGATION.APP_UID', '=', 'APPLICATION.APP_UID');
if($filterBy == 'APP_TITLE') {
@@ -113,6 +115,19 @@ class Delegation extends Model
});
}
if($filterBy == 'APP_NUMBER') {
$query->where('APP_DELEGATION.APP_NUMBER', 'LIKE', "%${search}%");
}
// Add any sort if needed
if($sort) {
// Clean up any specific sort parameters
if($sort == 'APP_NUMBER') {
$sort = 'APP_DELEGATION.APP_NUMBER';
}
$query->orderBy($sort, $dir);
}
// Add pagination to the query
$query = $query->offset($start)
->limit($limit);
@@ -195,6 +210,7 @@ class Delegation extends Model
$response = [
// Fake totalCount to show pagination
'totalCount' => $start + $limit + 1,
'sql' => $query->toSql(),
'data' => $results->toArray()
];