From a9b20019e26f1860c98c639ba30d12babbabb9e6 Mon Sep 17 00:00:00 2001 From: Roly Gutierrez Date: Tue, 7 Sep 2021 18:22:39 -0400 Subject: [PATCH] PMCORE-3265 Service support send By filter (inbox, draft, paused, unassigned) --- .../BusinessModel/Cases/AbstractCases.php | 35 +++++++++++++++++++ .../ProcessMaker/BusinessModel/Cases/Home.php | 22 ++++++++++-- .../BusinessModel/Cases/Inbox.php | 5 +++ .../BusinessModel/Cases/Paused.php | 5 +++ .../BusinessModel/Cases/Unassigned.php | 5 +++ .../src/ProcessMaker/Model/Delegation.php | 18 ++++++++++ .../src/ProcessMaker/Services/Api/Home.php | 24 +++++++++---- 7 files changed, 105 insertions(+), 9 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index 9c23d600f..dbe64bf4d 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -113,6 +113,9 @@ class AbstractCases implements CasesInterface // Filter by specific cases, know as "$appUidCheck" in the old lists classes private $casesUids = []; + + // Filter by Send By + private $sendBy = ''; // Filter range related to the start case date private $startCaseFrom = ''; @@ -749,6 +752,26 @@ class AbstractCases implements CasesInterface return $this->casesUids; } + /** + * Set send by. + * + * @param type $sendBy + */ + public function setSendBy(string $sendBy) + { + $this->sendBy = $sendBy; + } + + /** + * Get send by. + * + * @return string + */ + public function getSendBy() + { + return $this->sendBy; + } + /** * Set Cases Numbers * @@ -1381,6 +1404,10 @@ class AbstractCases implements CasesInterface if (get_class($this) === Inbox::class && !empty($properties['delegateTo'])) { $this->setDelegateTo($properties['delegateTo']); } + // Filter by Send By + if (get_class($this) === Inbox::class && !empty($properties['sendBy'])) { + $this->setSendBy($properties['sendBy']); + } /** Apply filters related to PAUSED */ // Filter date related to delegate from if (get_class($this) === Paused::class && !empty($properties['delegateFrom'])) { @@ -1390,6 +1417,10 @@ class AbstractCases implements CasesInterface if (get_class($this) === Paused::class && !empty($properties['delegateTo'])) { $this->setDelegateTo($properties['delegateTo']); } + // Filter by Send By + if (get_class($this) === Paused::class && !empty($properties['sendBy'])) { + $this->setSendBy($properties['sendBy']); + } /** Apply filters related to UNASSIGNED */ // Filter date related to delegate from if (get_class($this) === Unassigned::class && !empty($properties['delegateFrom'])) { @@ -1399,6 +1430,10 @@ class AbstractCases implements CasesInterface if (get_class($this) === Unassigned::class && !empty($properties['delegateTo'])) { $this->setDelegateTo($properties['delegateTo']); } + // Filter by Send By + if (get_class($this) === Unassigned::class && !empty($properties['sendBy'])) { + $this->setSendBy($properties['sendBy']); + } /** Apply filters related to MY CASES */ // My cases filter: started, in-progress, completed, supervising diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Home.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Home.php index 34b786327..85c812eb1 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Home.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Home.php @@ -78,6 +78,7 @@ class Home $sort = explode(',', $sort); $properties['sort'] = $sort[0]; $properties['dir'] = $sort[1]; + $properties['sendBy'] = $sendBy; $list->setProperties($properties); $result = []; $result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback)); @@ -97,6 +98,7 @@ class Home * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @param callable $callback * @return array */ @@ -111,6 +113,7 @@ class Home string $delegateTo = '', string $filterCases = '', string $sort = 'APP_NUMBER,DESC', + string $sendBy = '', callable $callback = null ) { @@ -133,6 +136,7 @@ class Home $sort = explode(',', $sort); $properties['sort'] = $sort[0]; $properties['dir'] = $sort[1]; + $properties['sendBy'] = $sendBy; $list->setProperties($properties); $result = []; $result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback)); @@ -152,6 +156,7 @@ class Home * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @param callable $callback * @return array */ @@ -166,6 +171,7 @@ class Home string $delegateTo = '', string $filterCases = '', string $sort = 'APP_NUMBER,DESC', + string $sendBy = '', callable $callback = null ) { @@ -188,6 +194,7 @@ class Home $sort = explode(',', $sort); $properties['sort'] = $sort[0]; $properties['dir'] = $sort[1]; + $properties['sendBy'] = $sendBy; // todo: some queries related to the unassigned are using the USR_UID $list->setUserUid($usrUid); $list->setProperties($properties); @@ -209,6 +216,7 @@ class Home * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @param callable $callback * @return array */ @@ -223,6 +231,7 @@ class Home string $delegateTo = '', string $filterCases = '', string $sort = 'APP_NUMBER,DESC', + string $sendBy = '', callable $callback = null ) { @@ -245,6 +254,7 @@ class Home $sort = explode(',', $sort); $properties['sort'] = $sort[0]; $properties['dir'] = $sort[1]; + $properties['sendBy'] = $sendBy; $list->setProperties($properties); $result = []; $result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback)); @@ -349,6 +359,7 @@ class Home * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @return array */ public function getCustomInbox( @@ -362,7 +373,8 @@ class Home string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { $arguments = func_get_args(); @@ -390,6 +402,7 @@ class Home * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @return array */ public function getCustomUnassigned( @@ -403,7 +416,8 @@ class Home string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { $arguments = func_get_args(); @@ -431,6 +445,7 @@ class Home * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @return array */ public function getCustomPaused( @@ -444,7 +459,8 @@ class Home string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { $arguments = func_get_args(); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php index b1bfb1f05..e35e1c752 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php @@ -91,6 +91,11 @@ class Inbox extends AbstractCases $query->delegateDateTo($this->getDelegateTo()); } + // Specific usrId represented by sendBy. + if (!empty($this->getSendBy())) { + $query->sendBy($this->getSendBy()); + } + return $query; } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php index 371ef1997..a9b74b53a 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php @@ -90,6 +90,11 @@ class Paused extends AbstractCases $query->delegateDateTo($this->getDelegateTo()); } + // Specific usrId represented by sendBy. + if (!empty($this->getSendBy())) { + $query->sendBy($this->getSendBy()); + } + return $query; } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php index 957e22501..cd5e7b525 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php @@ -91,6 +91,11 @@ class Unassigned extends AbstractCases $query->delegateDateTo($this->getDelegateTo()); } + // Specific usrId represented by sendBy. + if (!empty($this->getSendBy())) { + $query->sendBy($this->getSendBy()); + } + return $query; } diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index 22427bfef..c34b79e25 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -1032,6 +1032,24 @@ class Delegation extends Model return $query; } + /** + * Scope sendBy. + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $usrId + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeSendBy($query, int $usrId) + { + $query->where(DB::raw($usrId), function ($sql) { + $sql->from('APP_DELEGATION AS B') + ->select('B.USR_ID') + ->where('B.APP_NUMBER', '=', DB::raw('APP_DELEGATION.APP_NUMBER')) + ->where('B.DEL_INDEX', '=', DB::raw('APP_DELEGATION.DEL_PREVIOUS')) + ->limit(1); + }); + return $query; + } + /** * Get specific cases unassigned that the user can view * diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Home.php b/workflow/engine/src/ProcessMaker/Services/Api/Home.php index 43304e301..5286cbbfb 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Home.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Home.php @@ -101,6 +101,7 @@ class Home extends Api * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * * @return array * @@ -119,7 +120,8 @@ class Home extends Api string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { try { @@ -145,6 +147,7 @@ class Home extends Api * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * * @return array * @@ -163,7 +166,8 @@ class Home extends Api string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { try { @@ -189,6 +193,7 @@ class Home extends Api * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * * @return array * @@ -207,7 +212,8 @@ class Home extends Api string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { try { @@ -269,6 +275,7 @@ class Home extends Api * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @return array * @throws RestException * @access protected @@ -285,7 +292,8 @@ class Home extends Api string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { try { @@ -310,6 +318,7 @@ class Home extends Api * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @return array * @throws RestException * @access protected @@ -326,7 +335,8 @@ class Home extends Api string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { try { @@ -351,6 +361,7 @@ class Home extends Api * @param string $delegateTo * @param string $filterCases * @param string $sort + * @param string $sendBy * @return array * @throws RestException * @access protected @@ -367,7 +378,8 @@ class Home extends Api string $delegateFrom = '', string $delegateTo = '', string $filterCases = '', - string $sort = 'APP_NUMBER,DESC' + string $sort = 'APP_NUMBER,DESC', + string $sendBy = '' ) { try {