PMCORE-3245

This commit is contained in:
Paula Quispe
2021-08-27 16:49:33 -04:00
parent aa7729d3e7
commit c35fe76ce3
5 changed files with 37 additions and 5 deletions

View File

@@ -62,10 +62,10 @@ class Search extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// Join with delegation
$query->joinDelegation();
// Get the result
$result = Delegation::casesThreadTitle($this->getCaseTitle(), $this->getOffset(), $this->getLimit());
// Add the filter
// $query->title($this->getCaseTitle());
$query->specificCases($result);
}
// Filter by category
if ($this->getCategoryId()) {

View File

@@ -442,7 +442,7 @@ class Delegation extends Model
$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}%");
$query->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%{$search}%");
}
return $query;
@@ -2081,4 +2081,29 @@ class Delegation extends Model
return $results->values()->toArray();
}
/**
* Get cases filter by thread title
*
* @param string $search
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function casesThreadTitle(string $search, int $offset = 0, int $limit = 15)
{
// Get the case numbers related to this filter
$query = Delegation::query()->select(['APP_NUMBER']);
// Filter the title
$query->title($search);
// Group by
$query->groupBy('APP_NUMBER');
// Apply the limit
$query->offset($offset)->limit($limit);
// Get the result
$results = $query->get();
return $results->values()->toArray();
}
}