PMCORE-2397

This commit is contained in:
Paula Quispe
2020-12-09 19:04:05 -04:00
parent bb38e8acd8
commit 9565312ca9
20 changed files with 806 additions and 1431 deletions

View File

@@ -153,7 +153,19 @@ class Delegation extends Model
*/
public function scopeCaseInProgress($query)
{
return $query->where('APPLICATION.APP_STATUS_ID', 2);
return $query->statusIds([Application::STATUS_DRAFT, Application::STATUS_TODO]);
}
/**
* Scope a query to get the to_do cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCaseTodo($query)
{
return $query->where('APPLICATION.APP_STATUS_ID', Application::STATUS_TODO);
}
/**
@@ -165,7 +177,7 @@ class Delegation extends Model
*/
public function scopeCaseCompleted($query)
{
return $query->where('APPLICATION.APP_STATUS_ID', 3);
return $query->where('APPLICATION.APP_STATUS_ID', Application::STATUS_COMPLETED);
}
/**
@@ -373,6 +385,37 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.APP_NUMBER', '=', $appNumber);
}
/**
* Scope a query to only include a specific case title
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $search
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTitle($query, string $search)
{
$config = System::getSystemConfiguration();
if ((int)$config['disable_advanced_search_case_title_fulltext'] === 0) {
// Cleaning "fulltext" operators in order to avoid unexpected results
$search = str_replace(
['-', '+', '<', '>', '(', ')', '~', '*', '"'],
['', '', '', '', '', '', '', '', ''],
$search
);
// Build the "fulltext" expression
$search = '+"' . preg_replace('/\s+/', '" +"', addslashes($search)) . '"';
// Searching using "fulltext" index
$query->whereRaw("MATCH(APP_DELEGATION.DEL_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)");
} else {
// Searching using "like" operator
$query->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%${$search}%");
}
return $query;
}
/**
* Scope a query to only include specific cases
*