Merged in bugfix/PMCORE-3073 (pull request #7982)

PMCORE-3073

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Paula Quispe
2021-07-14 17:15:41 +00:00
committed by Julio Cesar Laura Avendaño
4 changed files with 48 additions and 4 deletions

View File

@@ -37,6 +37,9 @@ class AbstractCases implements CasesInterface
// Order by column allowed
const ORDER_BY_COLUMN_ALLOWED = ['APP_NUMBER', 'DEL_TITLE', 'PRO_TITLE'];
// Filter by category using the Id field
private $categoryId = 0;
// Filter by category from a process, know as "$category" in the old lists classes
private $categoryUid = '';
@@ -139,6 +142,26 @@ class AbstractCases implements CasesInterface
// Number of rows to return
private $limit = 15;
/**
* Set Category Uid value
*
* @param int $category
*/
public function setCategoryId(int $category)
{
$this->categoryId = $category;
}
/**
* Get Category Id value
*
* @return string
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* Set Category Uid value
*
@@ -1247,10 +1270,6 @@ class AbstractCases implements CasesInterface
*/
public function setProperties(array $properties)
{
// Filter by category
if (!empty($properties['category'])) {
$this->setCategoryUid($properties['category']);
}
// Filter by process
if (!empty($properties['process'])) {
$this->setProcessId($properties['process']);
@@ -1329,6 +1348,10 @@ class AbstractCases implements CasesInterface
$this->setFinishCaseTo($properties['finishCaseTo']);
}
/** Apply filters related to SEARCH */
// Filter by category
if (get_class($this) === Search::class && !empty($properties['category'])) {
$this->setCategoryId($properties['category']);
}
// Filter by more than one case statuses like ['DRAFT', 'TO_DO']
if (get_class($this) === Search::class && !empty($properties['caseStatuses'])) {
$this->setCaseStatuses($properties['caseStatuses']);

View File

@@ -67,6 +67,11 @@ class Search extends AbstractCases
// Add the filter
// $query->title($this->getCaseTitle());
}
// Filter by category
if ($this->getCategoryId()) {
// This filter require a join with the process table
$query->category($this->getCategoryId());
}
// Filter by process
if ($this->getProcessId()) {
$result = Process::query()->select(['PRO_UID'])

View File

@@ -232,6 +232,19 @@ class Application extends Model
return $query->whereIn('APPLICATION.APP_STATUS_ID', $statuses);
}
/**
* Scope a query to only include specific category
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $category
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCategory($query, $category)
{
return $query->where('PROCESS.CATEGORY_ID', $category);
}
/**
* Scope for query to get the applications by PRO_UID.
*

View File

@@ -460,6 +460,7 @@ class Home extends Api
* @url GET /search
*
* @param int $caseNumber
* @param int $category
* @param int $process
* @param int $task
* @param int $user
@@ -482,6 +483,7 @@ class Home extends Api
*/
public function doGetSearchCases(
int $caseNumber = 0,
int $category = 0,
int $process = 0,
int $task = 0,
int $user = 0,
@@ -500,6 +502,7 @@ class Home extends Api
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['category'] = $category;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;