diff --git a/tests/unit/workflow/engine/methods/cases/CasesMenuHighlightTest.php b/tests/unit/workflow/engine/methods/cases/CasesMenuHighlightTest.php index 21333f1d1..042bc07e1 100644 --- a/tests/unit/workflow/engine/methods/cases/CasesMenuHighlightTest.php +++ b/tests/unit/workflow/engine/methods/cases/CasesMenuHighlightTest.php @@ -96,9 +96,9 @@ class CasesMenuHighlightTest extends TestCase // Check if the object is valid $this->assertNotEmpty($result); - $this->assertArrayHasKey('item', $result[0]); - $this->assertArrayHasKey('highlight', $result[0]); - $this->assertEquals('CASES_SELFSERVICE', $result[0]['item']); - $this->assertEquals(true, $result[0]['highlight']); + $this->assertArrayHasKey('item', $result[7]); + $this->assertArrayHasKey('highlight', $result[7]); + $this->assertEquals('CASES_SELFSERVICE', $result[7]['item']); + $this->assertEquals(true, $result[7]['highlight']); } } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php index 4711632b0..961c455bd 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesListTest.php @@ -42,6 +42,18 @@ class CasesListTest extends TestCase return $delegation; } + /** + * This test construct + * + * @covers \ProcessMaker\BusinessModel\Cases\CasesList::__construct() + * @test + */ + public function it_test_construct() + { + $casesList = new CasesList(); + $this->assertInstanceOf(CasesList::class, $casesList); + } + /** * This test getAllCounters * @@ -57,4 +69,29 @@ class CasesListTest extends TestCase $this->assertArrayHasKey('CASES_INBOX', $result); $this->assertArrayHasKey('CASES_DRAFT', $result); } + + /** + * This test getAllCounters + * + * @covers \ProcessMaker\BusinessModel\Cases\CasesList::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\BatchRouting::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Canceled::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Completed::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Paused::atLeastOne() + * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::atLeastOne() + * @test + */ + public function it_return_at_least_one() + { + $delegation = factory(Delegation::class)->states('foreign_keys')->create(); + $count = new CasesList(); + $result = $count->atLeastOne($delegation->USR_UID); + $this->assertNotEmpty($result); + $firstItem = head($result); + $this->assertArrayHasKey('item', $firstItem); + $this->assertArrayHasKey('highlight', $firstItem); + } } \ No newline at end of file diff --git a/workflow/engine/methods/cases/casesMenuHighlight.php b/workflow/engine/methods/cases/casesMenuHighlight.php index b58ab1a13..9ae2b12f0 100644 --- a/workflow/engine/methods/cases/casesMenuHighlight.php +++ b/workflow/engine/methods/cases/casesMenuHighlight.php @@ -1,27 +1,16 @@ limit(1); - $items = $query->get(); - $atLeastOne = $items->count() > 0; -} else { - $query .= " LIMIT 1"; - $items = DB::select($query); - $atLeastOne = !empty($items); -} - -// Initializing the response variable +// Get the user logged +$usrUid = $_SESSION['USER_LOGGED']; +// Instance the class +$casesList = new CasesList(); $response = []; - -// The scope for the first version of this feature is only for unassigned list, so, this value is currently fixed -$response[] = ['item' => 'CASES_SELFSERVICE', 'highlight' => $atLeastOne]; +// Get highlight for all task list +$response = $casesList->atLeastOne($usrUid); // Print the response in JSON format header('Content-Type: application/json'); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index 69de97702..b6117a34d 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -1480,6 +1480,16 @@ class AbstractCases implements CasesInterface throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'."); } + /** + * Get true if the user has at least one case + * + * @throws Exception + */ + public function atLeastOne() + { + throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'."); + } + /** * Get the list counter * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php index e095c43a6..449accfbd 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/BatchRouting.php @@ -56,4 +56,15 @@ class BatchRouting extends AbstractCases // Return the number of rows return $query->count(['APP_DELEGATION.APP_NUMBER']); } + + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + // This class does not require this value + return false; + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php index 3c69cf2b3..2fba4fe06 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Canceled.php @@ -61,4 +61,15 @@ class Canceled extends AbstractCases // Return the number of rows return $query->count(['APP_DELEGATION.APP_NUMBER']); } + + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + // This class does not require this value + return false; + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php index 44d3ce220..c8c45c85e 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/CasesList.php @@ -41,6 +41,7 @@ class CasesList 'inbox' => 'CASES_INBOX', 'participated' => 'CASES_SENT', 'paused' => 'CASES_PAUSED', + 'unassigned' => 'CASES_SELFSERVICE', ]; /*----------------------------------********---------------------------------*/ @@ -83,4 +84,28 @@ class CasesList return $response; } + + /** + * Count if the user has at least one case in the list + * + * @param string $usrUid + * + * @return array + */ + public function atLeastOne(string $usrUid) + { + // Get the usrId key + $usrId = User::getId($usrUid); + // Get the classes + $list = $this->mapList; + $response = []; + foreach ($list as $listObject => $item) { + $this->$listObject->setUserUid($usrUid); + $this->$listObject->setUserId($usrId); + $atLeastOne = $this->$listObject->atLeastOne($usrUid); + $response[] = ['item' => $item, 'highlight' => $atLeastOne]; + } + + return $response; + } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php index ada994487..896817b90 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Completed.php @@ -53,8 +53,18 @@ class Completed extends AbstractCases $participated->setParticipatedStatus('COMPLETED'); $participated->setUserUid($this->getUserUid()); $participated->setUserId($this->getUserId()); - $count = $participated->getCounter(); - return $count; + return $participated->getCounter(); + } + + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + // This class does not require this value + return false; } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php index dc560506c..3238ec292 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php @@ -152,6 +152,24 @@ class Draft extends AbstractCases return $query->count(['APPLICATION.APP_NUMBER']); } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + $query = Application::query()->select(['APPLICATION.APP_NUMBER']); + // Add the initial scope for draft cases for specific user + $query->draft($this->getUserUid()); + // Get only one case + $query->limit(1); + // Get result + $items = $query->get(); + + return $items->count() > 0; + } + /** * Count how many cases the user has in DRAFT, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php index f31a5eb63..82de3e43f 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php @@ -165,6 +165,24 @@ class Inbox extends AbstractCases return $query->count(['APP_DELEGATION.APP_NUMBER']); } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + $query = Delegation::query()->select(['APP_DELEGATION.APP_NUMBER']); + // Scope that sets the queries for List Inbox for specific user + $query->inbox($this->getUserId()); + // Get only one case + $query->limit(1); + // Get the result + $items = $query->get(); + + return $items->count() > 0; + } + /** * Count how many cases the user has in TO_DO, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index 951f18cc1..6881e6680 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -266,6 +266,17 @@ class Participated extends AbstractCases return $query->count(['APP_DELEGATION.APP_NUMBER']); } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + // This class does not require this value + return false; + } + /** * Count how many cases the user has Participation, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php index 1b920bb3f..6edcdd483 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php @@ -159,6 +159,24 @@ class Paused extends AbstractCases return $query->count(['APP_DELEGATION.APP_NUMBER']); } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + $query = Delegation::query()->select(['APP_DELEGATION.APP_NUMBER']); + // Scope that set the paused cases + $query->paused($this->getUserId()); + // Get only one case + $query->limit(1); + // Get result + $items = $query->get(); + + return $items->count() > 0; + } + /** * Count how many cases the user has in PAUSED, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index 16f1cb16c..e52cc980f 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -215,6 +215,17 @@ class Search extends AbstractCases return 0; } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + // This class does not require this value + return false; + } + /** * Get the number of rows corresponding to the advanced search, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php index 1f7c08c6a..08b500421 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -203,6 +203,17 @@ class Supervising extends AbstractCases return $query->count(['APP_DELEGATION.APP_NUMBER']); } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + // This class does not require this value + return false; + } + /** * Count how many cases the user has in Supervising, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php index 5c86ea9c1..706849d00 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php @@ -167,6 +167,24 @@ class Unassigned extends AbstractCases return $query->count(['APP_DELEGATION.APP_NUMBER']); } + /** + * Count if the user has at least one case in the list + * + * @return bool + */ + public function atLeastOne() + { + $query = Delegation::query()->select(['APP_DELEGATION.APP_NUMBER']); + // Add the initial scope for self-service cases + $query->selfService($this->getUserUid()); + // Get only one case + $query->limit(1); + // Get result + $items = $query->get(); + + return $items->count() > 0; + } + /** * Count how many cases the user has in SELF_SERVICE, needs to apply filters * diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index bf89d021e..51359490e 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -355,6 +355,24 @@ class Application extends Model return $query; } + /** + * Scope the Draft cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $user + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeDraft($query, $user) + { + // Filter the status draft + $query->statusId(Application::STATUS_DRAFT); + // Filter the creator + $query->creator($user); + + return $query; + } + /** * Get Applications by PRO_UID, ordered by APP_NUMBER. * diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Home.php b/workflow/engine/src/ProcessMaker/Services/Api/Home.php index 4244a4be0..7b3aa24e4 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Home.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Home.php @@ -6,6 +6,7 @@ use Exception; use G; use Luracast\Restler\RestException; use Menu; +use ProcessMaker\BusinessModel\Cases\CasesList; use ProcessMaker\BusinessModel\Cases\Draft; use ProcessMaker\BusinessModel\Cases\Filter; use ProcessMaker\BusinessModel\Cases\Inbox; @@ -786,7 +787,7 @@ class Home extends Api } /** - * Get the tasks counters for todo, draft, paused and unassigned + * Get the tasks counters for all task list: todo, draft, paused and unassigned * * @url GET /tasks/counter * @@ -824,6 +825,26 @@ class Home extends Api return $result; } + /** + * Get the tasks highlight for all task list + * + * @url GET /tasks/highlight + * + * @return array + * + * @access protected + * @class AccessControl {@permission PM_CASES} + */ + public function getHighlight() + { + $usrUid = $this->getUserId(); + $casesList = new CasesList(); + $result = []; + $result = $casesList->atLeastOne($usrUid); + + return $result; + } + /** * Get all tasks, paged optionally, can be sent a text to filter results by "TAS_TITLE" *