From bb9e6b77b22458c02797fb08c7aee0d003666de8 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 8 Jul 2021 12:55:24 -0400 Subject: [PATCH] PMCORE-3083 --- database/factories/TaskSchedulerFactory.php | 2 +- .../BusinessModel/Cases/DraftTest.php | 43 +++++++++ .../BusinessModel/Cases/InboxTest.php | 43 +++++++++ .../BusinessModel/Cases/ParticipatedTest.php | 68 ++++++++++++++ .../BusinessModel/Cases/PausedTest.php | 26 ++++++ .../BusinessModel/Cases/SupervisingTest.php | 91 ++++++++++++++++--- .../BusinessModel/Cases/AbstractCases.php | 8 +- .../BusinessModel/Cases/Draft.php | 12 +++ .../BusinessModel/Cases/Inbox.php | 12 +++ .../BusinessModel/Cases/Participated.php | 12 +++ .../BusinessModel/Cases/Paused.php | 12 +++ .../BusinessModel/Cases/Search.php | 12 ++- .../BusinessModel/Cases/Supervising.php | 12 +++ .../BusinessModel/Cases/Unassigned.php | 12 +++ .../src/ProcessMaker/Model/Application.php | 51 +++++++++-- .../src/ProcessMaker/Model/Delegation.php | 51 +++++++++-- .../src/ProcessMaker/Services/Api/Home.php | 15 +++ 17 files changed, 439 insertions(+), 43 deletions(-) diff --git a/database/factories/TaskSchedulerFactory.php b/database/factories/TaskSchedulerFactory.php index 7ee6918c9..1dd54c754 100644 --- a/database/factories/TaskSchedulerFactory.php +++ b/database/factories/TaskSchedulerFactory.php @@ -7,7 +7,7 @@ use Faker\Generator as Faker; $factory->define(\ProcessMaker\Model\TaskScheduler::class, function (Faker $faker) { return [ - 'id' => G::generateUniqueID(), + 'id' => $faker->unique()->numberBetween(5000), 'title' => $faker->title, 'startingTime' => $faker->dateTime(), 'endingTime' => $faker->dateTime(), diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php index d8d6940c6..b8f0eb086 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/DraftTest.php @@ -156,6 +156,49 @@ class DraftTest extends TestCase $this->assertNotEmpty($res); } + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() + * @test + */ + public function it_filter_by_specific_cases() + { + // Create factories related to the draft cases + $cases = $this->createDraft(); + // Create new Draft object + $draft = new Draft(); + $draft->setUserId($cases['USR_ID']); + $draft->setCasesNumbers([$cases['APP_NUMBER']]); + $draft->setOrderByColumn('APP_NUMBER'); + $res = $draft->getData(); + $this->assertNotEmpty($res); + } + + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Draft::filters() + * @test + */ + public function it_filter_by_range_cases() + { + // Create factories related to the draft cases + $cases = $this->createDraft(); + // Create new Draft object + $draft = new Draft(); + $draft->setUserId($cases['USR_ID']); + $rangeOfCases = $cases['APP_NUMBER'] . "-" . $cases['APP_NUMBER']; + $draft->setRangeCasesFromTo([$rangeOfCases]); + $draft->setOrderByColumn('APP_NUMBER'); + $res = $draft->getData(); + $this->assertNotEmpty($res); + } + /** * It tests the getData method with taskId filter * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php index 790adfe81..ea7088534 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/InboxTest.php @@ -150,6 +150,49 @@ class InboxTest extends TestCase $this->assertNotEmpty($res); } + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() + * @test + */ + public function it_filter_by_specific_cases() + { + // Create factories related to the to_do cases + $cases = $this->createInbox(); + // Create new Inbox object + $inbox = new Inbox(); + $inbox->setUserId($cases->USR_ID); + $inbox->setCasesNumbers([$cases->APP_NUMBER]); + $inbox->setOrderByColumn('APP_NUMBER'); + $res = $inbox->getData(); + $this->assertNotEmpty($res); + } + + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() + * @test + */ + public function it_filter_by_range_cases() + { + // Create factories related to the to_do cases + $cases = $this->createInbox(); + // Create new Inbox object + $inbox = new Inbox(); + $inbox->setUserId($cases->USR_ID); + $rangeOfCases = $cases->APP_NUMBER . "-" . $cases->APP_NUMBER; + $inbox->setRangeCasesFromTo([$rangeOfCases]); + $inbox->setOrderByColumn('APP_NUMBER'); + $res = $inbox->getData(); + $this->assertNotEmpty($res); + } + /** * It tests the getData method with taskId filter * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php index 7a9f1ea25..f963f8c28 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/ParticipatedTest.php @@ -116,6 +116,7 @@ class ParticipatedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::setCaseStatus() * @test */ public function it_filter_by_started_by_me() @@ -128,6 +129,8 @@ class ParticipatedTest extends TestCase $participated->setUserUid($cases->USR_UID); // Set the user ID $participated->setUserId($cases->USR_ID); + // Get only the TO_DO + $participated->setCaseStatus(2); // Set the filter STARTED $participated->setParticipatedStatus('STARTED'); // Set OrderBYColumn value @@ -172,6 +175,7 @@ class ParticipatedTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::setProcessId() * @test */ public function it_filter_by_process() @@ -196,12 +200,76 @@ class ParticipatedTest extends TestCase $this->assertEquals(2, count($res)); } + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::setCasesNumbers() + * @test + */ + public function it_filter_by_specific_cases() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the filter + $participated->setFilterCases('STARTED'); + // Set the user UID + $participated->setUserUid($cases['USR_UID']); + // Set the user ID + $participated->setUserId($cases['USR_ID']); + // Set the case numbers + $participated->setCasesNumbers([$cases['APP_NUMBER']]); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(2, count($res)); + } + + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::setRangeCasesFromTo() + * @test + */ + public function it_filter_by_range_cases() + { + // Create factories related to the participated cases + $cases = $this->createParticipated(); + // Create new Participated object + $participated = new Participated(); + // Set the filter + $participated->setFilterCases('STARTED'); + // Set the user UID + $participated->setUserUid($cases['USR_UID']); + // Set the user ID + $participated->setUserId($cases['USR_ID']); + // Set the range of case numbers + $rangeOfCases = $cases['APP_NUMBER'] . "-" . $cases['APP_NUMBER']; + $participated->setRangeCasesFromTo([$rangeOfCases]); + // Set OrderBYColumn value + $participated->setOrderByColumn('APP_NUMBER'); + // Call to getData method + $res = $participated->getData(); + // This assert that the expected numbers of results are returned + $this->assertEquals(2, count($res)); + } + /** * It tests the getData method with processId filter * * @covers \ProcessMaker\BusinessModel\Cases\Participated::getData() * @covers \ProcessMaker\BusinessModel\Cases\Participated::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Participated::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Participated::setCaseTitle() * @test */ public function it_filter_by_thread_title() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php index d3184040c..354eb2b3a 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/PausedTest.php @@ -241,6 +241,32 @@ class PausedTest extends TestCase $this->assertNotEmpty($res); } + /** + * It tests the getData method with case number filter + * + * @covers \ProcessMaker\BusinessModel\Cases\Paused::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Paused::filters() + * @test + */ + public function it_filter_by_specific_cases() + { + // Create factories related to the paused cases + $cases = $this->createPaused(); + //Create new Paused object + $paused = new Paused(); + //Set the user UID + $paused->setUserUid($cases->USR_UID); + //Set the user ID + $paused->setUserId($cases->USR_ID); + //Set app number + $paused->setCasesNumbers([$cases->APP_NUMBER]); + //Call to getData method + $res = $paused->getData(); + //This asserts there are results for the filtered app number + $this->assertNotEmpty($res); + } + /** * It tests the getData method with taskId filter * diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php index 8c96d0dea..e1bfe467e 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/Cases/SupervisingTest.php @@ -351,11 +351,11 @@ class SupervisingTest extends TestCase $cases = $this->createSupervising(); // Instance the Supervising object $Supervising = new Supervising(); - //Set the user UID + // Set the user UID $Supervising->setUserUid($cases->USR_UID); - //Set the user ID + // Set the user ID $Supervising->setUserId($cases->USR_ID); - //Call the getData method + // Call the getData method $res = $Supervising->getData(); // Asserts the result contains 3 registers $this->assertCount(3, $res); @@ -373,11 +373,11 @@ class SupervisingTest extends TestCase $cases = $this->createSupervising(); // Instance the Supervising object $Supervising = new Supervising(); - //Set the user UID + // Set the user UID $Supervising->setUserUid($user->USR_UID); - //Set the user ID + // Set the user ID $Supervising->setUserId($user->USR_ID); - //Call the getData method + // Call the getData method $res = $Supervising->getData(); // Asserts the result $this->assertEmpty($res); @@ -394,13 +394,13 @@ class SupervisingTest extends TestCase $cases = $this->createSupervising(); // Instance the Supervising object $Supervising = new Supervising(); - //Set the user UID + // Set the user UID $Supervising->setUserUid($cases->USR_UID); - //Set the user ID + // Set the user ID $Supervising->setUserId($cases->USR_ID); - //Call the getCounter method + // Call the getCounter method $res = $Supervising->getCounter(); - //Assert the counter + // Assert the counter $this->assertEquals(3, $res); } @@ -410,6 +410,7 @@ class SupervisingTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setCaseNumber() * @test */ public function it_filter_by_app_number() @@ -417,16 +418,74 @@ class SupervisingTest extends TestCase $cases = $this->createSupervising(); // Instance the Supervising object $Supervising = new Supervising(); - //Set the user UID + // Set the user UID $Supervising->setUserUid($cases->USR_UID); - //Set the user ID + // Set the user ID $Supervising->setUserId($cases->USR_ID); + // Set the case number $Supervising->setCaseNumber($cases->APP_NUMBER); - //Call the getData method + // Call the getData method $res = $Supervising->getData(); // Asserts the result contains 3 registers $this->assertCount(1, $res); - //Asserts that the result contains the app number searched + // Asserts that the result contains the app number searched + $this->assertContains($cases->APP_NUMBER, $res[0]); + } + + /** + * Tests the filter by APP_NUMBER + * + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setCaseNumber() + * @test + */ + public function it_filter_by_specific_cases() + { + $cases = $this->createSupervising(); + // Instance the Supervising object + $Supervising = new Supervising(); + // Set the user UID + $Supervising->setUserUid($cases->USR_UID); + // Set the user ID + $Supervising->setUserId($cases->USR_ID); + // Set the case numbers + $Supervising->setCasesNumbers([$cases->APP_NUMBER]); + // Call the getData method + $res = $Supervising->getData(); + // Asserts the result contains 3 registers + $this->assertCount(1, $res); + // Asserts that the result contains the app number searched + $this->assertContains($cases->APP_NUMBER, $res[0]); + } + + /** + * Tests the filter by APP_NUMBER + * + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setRangeCasesFromTo() + * @test + */ + public function it_filter_by_range_cases() + { + $cases = $this->createSupervising(); + // Instance the Supervising object + $Supervising = new Supervising(); + // Set the user UID + $Supervising->setUserUid($cases->USR_UID); + // Set the user ID + $Supervising->setUserId($cases->USR_ID); + // Set the range of case numbers + $rangeOfCases = $cases->APP_NUMBER . "-" . $cases->APP_NUMBER; + $Supervising->setRangeCasesFromTo([$rangeOfCases]); + // Call the getData method + $res = $Supervising->getData(); + // Asserts the result contains 3 registers + $this->assertCount(1, $res); + // Asserts that the result contains the app number searched $this->assertContains($cases->APP_NUMBER, $res[0]); } @@ -436,6 +495,7 @@ class SupervisingTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setProcessId() * @test */ public function it_filter_by_process() @@ -460,6 +520,7 @@ class SupervisingTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setTaskId() * @test */ public function it_filter_by_task() @@ -484,6 +545,7 @@ class SupervisingTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setCaseTitle() * @test */ public function it_filter_by_thread_title() @@ -515,6 +577,7 @@ class SupervisingTest extends TestCase * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getData() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Supervising::filters() + * @covers \ProcessMaker\BusinessModel\Cases\Supervising::setOrderByColumn() * @test */ public function it_order_by_column() diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php index c62f3c423..81c8efc12 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/AbstractCases.php @@ -1260,6 +1260,10 @@ class AbstractCases implements CasesInterface if (!empty($properties['caseNumber'])) { $this->setCaseNumber($properties['caseNumber']); } + // Add a filter with specific cases or range of cases like '1, 3-5, 8, 10-15' + if (!empty($properties['filterCases'])) { + $this->setFilterCases($properties['filterCases']); + } // Filter by case title if (!empty($properties['caseTitle'])) { $this->setCaseTitle($properties['caseTitle']); @@ -1290,10 +1294,6 @@ class AbstractCases implements CasesInterface $this->setFinishCaseTo($properties['finishCaseTo']); } /** Apply filters related to SEARCH */ - // Add a filter with specific cases or range of cases like '1, 3-5, 8, 10-15' - if (get_class($this) === Search::class && !empty($properties['filterCases'])) { - $this->setFilterCases($properties['filterCases']); - } // 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/Draft.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php index 1235ab3dd..1d9e0d9b6 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Draft.php @@ -47,6 +47,18 @@ class Draft extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { + $query->specificCases($this->getCasesNumbers()); + } + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { + $query->rangeOfCases($this->getRangeCasesFromTo()); + } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if (!empty($this->getCaseTitle())) { $query->title($this->getCaseTitle()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php index 3257bb3eb..5f19e9d85 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Inbox.php @@ -50,6 +50,18 @@ class Inbox extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { + $query->specificCases($this->getCasesNumbers()); + } + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { + $query->rangeOfCases($this->getRangeCasesFromTo()); + } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if (!empty($this->getCaseTitle())) { $query->title($this->getCaseTitle()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php index afedfb453..83a1ca085 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Participated.php @@ -52,6 +52,18 @@ class Participated extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { + $query->specificCases($this->getCasesNumbers()); + } + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { + $query->rangeOfCases($this->getRangeCasesFromTo()); + } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if (!empty($this->getCaseTitle())) { $query->title($this->getCaseTitle()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php index c05bbeb27..caf1d57a4 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Paused.php @@ -49,6 +49,18 @@ class Paused extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { + $query->specificCases($this->getCasesNumbers()); + } + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { + $query->rangeOfCases($this->getRangeCasesFromTo()); + } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if (!empty($this->getCaseTitle())) { $query->title($this->getCaseTitle()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php index 9bf8ffbbe..4b8dfa495 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Search.php @@ -48,14 +48,18 @@ class Search extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } - // Filter cases by specific cases like [1,3,5] - if (!empty($this->getCasesNumbers())) { + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { $query->specificCases($this->getCasesNumbers()); } - // Filter cases by range of cases like ['1-5', '10-15'] - if (!empty($this->getRangeCasesFromTo())) { + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { $query->rangeOfCases($this->getRangeCasesFromTo()); } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if (!empty($this->getCaseTitle())) { // Join with delegation diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php index b960d344e..16b66b482 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php @@ -49,6 +49,18 @@ class Supervising extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { + $query->specificCases($this->getCasesNumbers()); + } + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { + $query->rangeOfCases($this->getRangeCasesFromTo()); + } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if (!empty($this->getCaseTitle())) { $query->title($this->getCaseTitle()); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php index 938cfb69b..5a7e25fce 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Unassigned.php @@ -50,6 +50,18 @@ class Unassigned extends AbstractCases if ($this->getCaseNumber()) { $query->case($this->getCaseNumber()); } + // Filter only cases by specific cases like [1,3,5] + if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) { + $query->specificCases($this->getCasesNumbers()); + } + // Filter only cases by range of cases like ['1-5', '10-15'] + if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) { + $query->rangeOfCases($this->getRangeCasesFromTo()); + } + // Filter cases mixed by range of cases and specific cases like '1,3-5,8' + if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) { + $query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo()); + } // Specific case title if ($this->getCaseTitle()) { $query->title($this->getCaseTitle()); diff --git a/workflow/engine/src/ProcessMaker/Model/Application.php b/workflow/engine/src/ProcessMaker/Model/Application.php index 3b9d49c9a..63201c023 100644 --- a/workflow/engine/src/ProcessMaker/Model/Application.php +++ b/workflow/engine/src/ProcessMaker/Model/Application.php @@ -135,18 +135,49 @@ class Application extends Model */ public function scopeRangeOfCases($query, array $rangeCases) { - foreach ($rangeCases as $fromTo) { - $fromTo = explode("-", $fromTo); - if (count($fromTo) === 2) { - $from = $fromTo[0]; - $to = $fromTo[1]; - if ($to > $from) { - $query->orWhere(function ($query) use ($from, $to) { - $query->casesFrom($from)->casesTo($to); - }); + $query->where(function ($query) use ($rangeCases) { + foreach ($rangeCases as $fromTo) { + $fromTo = explode("-", $fromTo); + if (count($fromTo) === 2) { + $from = $fromTo[0]; + $to = $fromTo[1]; + if ($to > $from) { + $query->orWhere(function ($query) use ($from, $to) { + $query->casesFrom($from)->casesTo($to); + }); + } } } - } + }); + } + + /** + * Scope more than one range of cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $cases + * @param array $rangeCases + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCasesOrRangeOfCases($query, array $cases, array $rangeCases) + { + $query->where(function ($query) use ($cases, $rangeCases) { + // Get the cases related to the task self service + $query->specificCases($cases); + foreach ($rangeCases as $fromTo) { + $fromTo = explode("-", $fromTo); + if (count($fromTo) === 2) { + $from = $fromTo[0]; + $to = $fromTo[1]; + if ($to > $from) { + $query->orWhere(function ($query) use ($from, $to) { + $query->casesFrom($from)->casesTo($to); + }); + } + } + } + }); } /** diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index f5a24a243..8b143a3b2 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -488,18 +488,49 @@ class Delegation extends Model */ public function scopeRangeOfCases($query, array $rangeCases) { - foreach ($rangeCases as $fromTo) { - $fromTo = explode("-", $fromTo); - if (count($fromTo) === 2) { - $from = $fromTo[0]; - $to = $fromTo[1]; - if ($to > $from) { - $query->orWhere(function ($query) use ($from, $to) { - $query->casesFrom($from)->casesTo($to); - }); + $query->where(function ($query) use ($rangeCases) { + foreach ($rangeCases as $fromTo) { + $fromTo = explode("-", $fromTo); + if (count($fromTo) === 2) { + $from = $fromTo[0]; + $to = $fromTo[1]; + if ($to > $from) { + $query->orWhere(function ($query) use ($from, $to) { + $query->casesFrom($from)->casesTo($to); + }); + } } } - } + }); + } + + /** + * Scope more than one range of cases + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $cases + * @param array $rangeCases + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCasesOrRangeOfCases($query, array $cases, array $rangeCases) + { + $query->where(function ($query) use ($cases, $rangeCases) { + // Get the cases related to the task self service + $query->specificCases($cases); + foreach ($rangeCases as $fromTo) { + $fromTo = explode("-", $fromTo); + if (count($fromTo) === 2) { + $from = $fromTo[0]; + $to = $fromTo[1]; + if ($to > $from) { + $query->orWhere(function ($query) use ($from, $to) { + $query->casesFrom($from)->casesTo($to); + }); + } + } + } + }); } /** diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Home.php b/workflow/engine/src/ProcessMaker/Services/Api/Home.php index 39a6ad256..bf61dec1d 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Home.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Home.php @@ -50,6 +50,7 @@ class Home extends Api * @param int $process * @param int $task * @param string $caseTitle + * @param string $filterCases * @param string $paged * @param string $sort * @@ -65,6 +66,7 @@ class Home extends Api int $process = 0, int $task = 0, string $caseTitle = '', + string $filterCases = '', string $paged = '0,15', string $sort = 'APP_NUMBER,DESC' ) { @@ -74,6 +76,7 @@ class Home extends Api $properties = []; $properties['caseNumber'] = $caseNumber; $properties['caseTitle'] = $caseTitle; + $properties['filterCases'] = $filterCases; $properties['process'] = $process; $properties['task'] = $task; // Get the user that access to the API @@ -105,6 +108,7 @@ class Home extends Api * @param int $process * @param int $task * @param string $caseTitle + * @param string $filterCases * @param string $paged * @param string $sort * @@ -120,6 +124,7 @@ class Home extends Api int $process = 0, int $task = 0, string $caseTitle = '', + string $filterCases = '', string $paged = '0,15', string $sort = 'APP_NUMBER,DESC' ) { @@ -129,6 +134,7 @@ class Home extends Api $properties = []; $properties['caseNumber'] = $caseNumber; $properties['caseTitle'] = $caseTitle; + $properties['filterCases'] = $filterCases; $properties['process'] = $process; $properties['task'] = $task; // Get the user that access to the API @@ -160,6 +166,7 @@ class Home extends Api * @param int $process * @param int $task * @param string $caseTitle + * @param string $filterCases * @param string $paged * @param string $sort * @@ -175,6 +182,7 @@ class Home extends Api int $process = 0, int $task = 0, string $caseTitle = '', + string $filterCases = '', string $paged = '0,15', string $sort = 'APP_NUMBER,DESC' ) { @@ -184,6 +192,7 @@ class Home extends Api $properties = []; $properties['caseNumber'] = $caseNumber; $properties['caseTitle'] = $caseTitle; + $properties['filterCases'] = $filterCases; $properties['process'] = $process; $properties['task'] = $task; // Get the user that access to the API @@ -217,6 +226,7 @@ class Home extends Api * @param int $process * @param int $task * @param string $caseTitle + * @param string $filterCases * @param string $paged * @param string $sort * @@ -232,6 +242,7 @@ class Home extends Api int $process = 0, int $task = 0, string $caseTitle = '', + string $filterCases = '', string $paged = '0,15', string $sort = 'APP_NUMBER,DESC' ) { @@ -241,6 +252,7 @@ class Home extends Api $properties = []; $properties['caseNumber'] = $caseNumber; $properties['caseTitle'] = $caseTitle; + $properties['filterCases'] = $filterCases; $properties['process'] = $process; $properties['task'] = $task; // Get the user that access to the API @@ -272,6 +284,7 @@ class Home extends Api * @param int $process * @param int $task * @param string $caseTitle + * @param string $filterCases * @param string $filter * @param string $caseStatus * @param string $startCaseFrom @@ -293,6 +306,7 @@ class Home extends Api int $process = 0, int $task = 0, string $caseTitle = '', + string $filterCases = '', string $filter = 'IN_PROGRESS', string $caseStatus = '', string $startCaseFrom = '', @@ -306,6 +320,7 @@ class Home extends Api $properties = []; $properties['caseNumber'] = $caseNumber; $properties['caseTitle'] = $caseTitle; + $properties['filterCases'] = $filterCases; $properties['process'] = $process; $properties['task'] = $task; // Get the user that access to the API