diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index bd66fc067..52afbf0f6 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -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']); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index 4b8dfa495..84085fc12 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -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']) diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 63201c023..8159ebd36 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -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. * diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Home.php b/workflow/engine/src/ProcessMaker/Services/Api/Home.php index fabed4940..62a9c7c63 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Home.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Home.php @@ -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;