From ff33075228deaa165b9a57de6bd57bc148a21232 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Mon, 13 May 2019 16:44:40 -0400 Subject: [PATCH] PMC-786 --- phpunit.xml | 5 + .../src/ProcessMaker/Model/DelegationTest.php | 514 ++++++++++++++++ .../src/ProcessMaker/Model/DelegationTest.php | 419 ++++++++++++- .../ProcessMaker/Model/ListUnassignedTest.php | 572 +++++++++--------- .../src/ProcessMaker/BusinessModel/Lists.php | 18 +- .../Model/AppAssignSelfServiceValue.php | 58 ++ .../Model/AppAssignSelfServiceValueGroup.php | 8 + .../src/ProcessMaker/Model/Delegation.php | 116 ++++ .../src/ProcessMaker/Model/GroupUser.php | 48 ++ .../engine/src/ProcessMaker/Model/Groupwf.php | 19 + .../src/ProcessMaker/Model/ListUnassigned.php | 88 +++ .../engine/src/ProcessMaker/Model/Task.php | 12 + .../src/ProcessMaker/Model/TaskUser.php | 60 ++ .../engine/src/ProcessMaker/Model/User.php | 21 + 14 files changed, 1655 insertions(+), 303 deletions(-) create mode 100644 tests/Performance/workflow/engine/src/ProcessMaker/Model/DelegationTest.php diff --git a/phpunit.xml b/phpunit.xml index 91b213c61..dad99dd69 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,6 +17,9 @@ ./tests/Unit + + ./tests/Performance/ + @@ -45,6 +48,8 @@ + + diff --git a/tests/Performance/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/Performance/workflow/engine/src/ProcessMaker/Model/DelegationTest.php new file mode 100644 index 000000000..a0b5e7e65 --- /dev/null +++ b/tests/Performance/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -0,0 +1,514 @@ +markTestSkipped('Test related to the performance are disabled for this server configuration'); + } else { + $this->totalCases = (int)env('TOTAL_CASES', 120); + $this->maximumExecutionTime = (int)env('MAX_EXECUTION_TIME', 60); + } + } + + /** + * This checks the counters is working properly in self-service user assigned + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_user_assigned() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, $total)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_user_assigned took [' . $total . ']--->' . $time); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the USR_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID] + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, $total)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_value_based_usr_uid took [' . $total . ']--->' . $time); + } + + /** + * This checks the counters is working properly in self-service and self-service value based + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in self service + factory(Delegation::class, $total / 2)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create a task self service value based + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task1->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self service value based + factory(Delegation::class, $total / 2)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based took [' . $total . ']--->' . $time); + } + + /** + * This checks the counters is working properly in self-service group assigned + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_group_assigned() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in self-service + factory(Delegation::class, $total)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_group_assigned took [' . $total . ']--->' . $time); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the GRP_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID] + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create a case + $application = factory(Application::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, $total)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_value_based_grp_uid took [' . $total . ']--->' . $time); + } + + /** + * This checks the counters is working properly in self-service user and group assigned in parallel task + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task1 + factory(TaskUser::class)->create([ + 'TAS_UID' => $task1->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task2 + factory(TaskUser::class)->create([ + 'TAS_UID' => $task2->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task3 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task3->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task4 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task4->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in self-service related to the task1 + factory(Delegation::class, $total / 4)->create([ + 'TAS_ID' => $task1->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task2 + factory(Delegation::class, $total / 4)->create([ + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task3 + factory(Delegation::class, $total / 4)->create([ + 'TAS_ID' => $task3->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task4 + factory(Delegation::class, $total / 4)->create([ + 'TAS_ID' => $task4->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task took [' . $total . ']--->' . $time); + } + + /** + * This checks the counters is working properly in self-service-value-based with GRP_UID and USR_UID in parallel task + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID, USR_UID] + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() + { + //Define the total of cases to create + $total = $this->totalCases; + //Define the maximum time of execution + $maximumTime = $this->maximumExecutionTime; + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task1 self service value based + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task1->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, $total / 2)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task1->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create a task2 self service value based + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task2->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, $total / 2)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $timeStart = microtime(true); + Delegation::countSelfService($user->USR_UID); + $timeEnd = microtime(true); + $time = $timeEnd - $timeStart; + //Compare if the time of execution is minor than the time defined in the .env + $this->assertLessThan($maximumTime, $time); + error_log('it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid took [' . $total . ']--->' . $time); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php index 686e857e9..3f56c0379 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DelegationTest.php @@ -2,13 +2,17 @@ namespace Tests\unit\workflow\src\ProcessMaker\Model; use G; -use Faker; use Illuminate\Foundation\Testing\DatabaseTransactions; +use ProcessMaker\Model\AppAssignSelfServiceValue; +use ProcessMaker\Model\AppAssignSelfServiceValueGroup; use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\GroupUser; +use ProcessMaker\Model\Groupwf; use ProcessMaker\Model\Process; use ProcessMaker\Model\ProcessCategory; use ProcessMaker\Model\Task; +use ProcessMaker\Model\TaskUser; use ProcessMaker\Model\User; use Tests\TestCase; @@ -1136,4 +1140,417 @@ class DelegationTest extends TestCase // Check the information returned $this->assertEmpty($results); } + + /** + * This checks the counters is working properly in self-service user assigned + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_user_assigned() + { + //Create process + $process = factory(Process::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in delegation relate to self-service + factory(Delegation::class, 25)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the USR_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID] + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() + { + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service and self-service value based + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() + { + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create the register in self service + factory(Delegation::class, 15)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create a task self service value based + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task1->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self service value based + factory(Delegation::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(30, $result); + } + + /** + * This checks the counters is working properly in self-service group assigned + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_group_assigned() + { + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service-value-based when the variable has a value related with the GRP_UID + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID] + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() + { + //Create process + $process = factory(Process::class)->create(); + //Create a task self service value based + $task = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create a case + $application = factory(Application::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create([ + 'USR_USERNAME' => 'gary', + 'USR_LASTNAME' => 'Gary', + 'USR_FIRSTNAME' => 'Bailey', + ]); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => 2, + 'TAS_ID' => $task->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); + } + + /** + * This checks the counters is working properly in self-service user and group assigned in parallel task + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() + { + //Create process + $process = factory(Process::class)->create(); + //Create group + $group = factory(Groupwf::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Assign a user in the group + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID + ]); + //Create a task self service + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task1 + factory(TaskUser::class)->create([ + 'TAS_UID' => $task1->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task2 + factory(TaskUser::class)->create([ + 'TAS_UID' => $task2->TAS_UID, + 'USR_UID' => $user->USR_UID, + 'TU_RELATION' => 1, //Related to the user + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task3 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task3->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create a task self service + $task4 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '', + 'PRO_UID' => $process->PRO_UID + ]); + //Assign a user in the task + factory(TaskUser::class)->create([ + 'TAS_UID' => $task4->TAS_UID, + 'USR_UID' => $group->GRP_UID, + 'TU_RELATION' => 2, //Related to the group + 'TU_TYPE' => 1 + ]); + //Create the register in self-service related to the task1 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task1->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task2 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task3 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task3->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create the register in self-service related to the task4 + factory(Delegation::class, 10)->create([ + 'TAS_ID' => $task4->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(40, $result); + } + + /** + * This checks the counters is working properly in self-service-value-based with GRP_UID and USR_UID in parallel task + * When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID, USR_UID] + * @covers Delegation::countSelfService + * @test + */ + public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() + { + //Create process + $process = factory(Process::class)->create(); + //Create a case + $application = factory(Application::class)->create(); + //Create user + $user = factory(User::class)->create(); + //Create a task1 self service value based + $task1 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task1->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 10)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task1->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Create a task2 self service value based + $task2 = factory(Task::class)->create([ + 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', + 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', + 'PRO_UID' => $process->PRO_UID + ]); + //Create the relation for the value assigned in the TAS_GROUP_VARIABLE + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task2->TAS_ID + ]); + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId + 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 + ]); + //Create the register in self-service + factory(Delegation::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task2->TAS_ID, + 'DEL_THREAD_STATUS' => 'OPEN', + 'USR_ID' => 0, + ]); + //Review the count self-service + $result = Delegation::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); + } } \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php index 6574caef7..8ceda84d6 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/ListUnassignedTest.php @@ -32,32 +32,29 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_user_assigned() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task[0]->TAS_ID + factory(ListUnassigned::class, 25)->create([ + 'TAS_ID' => $task->TAS_ID ]); - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $timeEnd = microtime(true); - $this->assertEquals(15, $result); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_user_assigned took [15]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); } /** @@ -69,41 +66,38 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a case - $application = factory(Application::class, 1)->create(); + $application = factory(Application::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task self service value based - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, 'DEL_INDEX' => 2, - 'TAS_ID' => $task[0]->TAS_ID + 'TAS_ID' => $task->TAS_ID ]); - factory(AppAssignSelfServiceValueGroup::class, 1)->create([ - 'ID' => $appSelfValue[0]->ID, - 'GRP_UID' => $user[0]->USR_UID, - 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 10)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, - 'TAS_ID' => $task[0]->TAS_ID, + factory(ListUnassigned::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, ]); - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $this->assertEquals(10, $result); - $timeEnd = microtime(true); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_value_based_usr_uid took [10]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); } /** @@ -114,59 +108,55 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a case - $application = factory(Application::class, 1)->create(); + $application = factory(Application::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in self service factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task[0]->TAS_ID + 'TAS_ID' => $task->TAS_ID ]); //Create a task self service value based - $task1 = factory(Task::class, 1)->create([ + $task1 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, 'DEL_INDEX' => 2, - 'TAS_ID' => $task1[0]->TAS_ID + 'TAS_ID' => $task1->TAS_ID ]); - factory(AppAssignSelfServiceValueGroup::class, 1)->create([ - 'ID' => $appSelfValue[0]->ID, - 'GRP_UID' => $user[0]->USR_UID, - 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 ]); //Create the register in self service value based - factory(ListUnassigned::class, 10)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, - 'TAS_ID' => $task[0]->TAS_ID, + factory(ListUnassigned::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task->TAS_ID, ]); - - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $timeEnd = microtime(true); - $this->assertEquals(25, $result); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based took [25]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(30, $result); } /** @@ -177,40 +167,37 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_group_assigned() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create group - $group = factory(Groupwf::class, 1)->create(); + $group = factory(Groupwf::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Assign a user in the group - factory(GroupUser::class, 1)->create([ - 'GRP_UID' => $group[0]->GRP_UID, - 'GRP_ID' => $group[0]->GRP_ID, - 'USR_UID' => $user[0]->USR_UID + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID ]); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 2, //Related to the group 'TU_TYPE' => 1 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task[0]->TAS_ID + factory(ListUnassigned::class, 25)->create([ + 'TAS_ID' => $task->TAS_ID ]); - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $timeEnd = microtime(true); - $this->assertEquals(15, $result); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_group_assigned took [15]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); } /** @@ -222,54 +209,51 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a task self service value based - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Create a case - $application = factory(Application::class, 1)->create(); + $application = factory(Application::class)->create(); //Create group - $group = factory(Groupwf::class, 1)->create(); + $group = factory(Groupwf::class)->create(); //Create user - $user = factory(User::class, 1)->create([ + $user = factory(User::class)->create([ 'USR_USERNAME' => 'gary', 'USR_LASTNAME' => 'Gary', 'USR_FIRSTNAME' => 'Bailey', ]); //Assign a user in the group - factory(GroupUser::class, 1)->create([ - 'GRP_UID' => $group[0]->GRP_UID, - 'GRP_ID' => $group[0]->GRP_ID, - 'USR_UID' => $user[0]->USR_UID, + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID, ]); //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'APP_UID' => $application[0]->APP_UID, + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID, 'DEL_INDEX' => 2, - 'TAS_ID' => $task[0]->TAS_ID + 'TAS_ID' => $task->TAS_ID ]); - factory(AppAssignSelfServiceValueGroup::class, 1)->create([ - 'ID' => $appSelfValue[0]->ID, - 'GRP_UID' => $group[0]->GRP_UID, - 'ASSIGNEE_ID' => $group[0]->GRP_ID, //The usrId or grpId + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $group->GRP_UID, + 'ASSIGNEE_ID' => $group->GRP_ID, //The usrId or grpId 'ASSIGNEE_TYPE' => 2 //Related to the user=1 related to the group=2 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 10)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, + factory(ListUnassigned::class, 25)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, 'DEL_INDEX' => 2, - 'TAS_ID' => $task[0]->TAS_ID, + 'TAS_ID' => $task->TAS_ID, ]); - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $this->assertEquals(10, $result); - $timeEnd = microtime(true); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_value_based_grp_uid took [10]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(25, $result); } /** @@ -280,91 +264,88 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create group - $group = factory(Groupwf::class, 1)->create(); + $group = factory(Groupwf::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Assign a user in the group - factory(GroupUser::class, 1)->create([ - 'GRP_UID' => $group[0]->GRP_UID, - 'GRP_ID' => $group[0]->GRP_ID, - 'USR_UID' => $user[0]->USR_UID + factory(GroupUser::class)->create([ + 'GRP_UID' => $group->GRP_UID, + 'GRP_ID' => $group->GRP_ID, + 'USR_UID' => $user->USR_UID ]); //Create a task self service - $task1 = factory(Task::class, 1)->create([ + $task1 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task1 - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task1[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task1->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create a task self service - $task2 = factory(Task::class, 1)->create([ + $task2 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task2 - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task2[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task2->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create a task self service - $task3 = factory(Task::class, 1)->create([ + $task3 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task3[0]->TAS_UID, - 'USR_UID' => $group[0]->GRP_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task3->TAS_UID, + 'USR_UID' => $group->GRP_UID, 'TU_RELATION' => 2, //Related to the group 'TU_TYPE' => 1 ]); //Create a task self service - $task4 = factory(Task::class, 1)->create([ + $task4 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task4[0]->TAS_UID, - 'USR_UID' => $group[0]->GRP_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task4->TAS_UID, + 'USR_UID' => $group->GRP_UID, 'TU_RELATION' => 2, //Related to the group 'TU_TYPE' => 1 ]); //Create the register in list unassigned related to the task1 - factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task1[0]->TAS_ID + factory(ListUnassigned::class, 10)->create([ + 'TAS_ID' => $task1->TAS_ID ]); //Create the register in list unassigned related to the task2 - factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task2[0]->TAS_ID + factory(ListUnassigned::class, 10)->create([ + 'TAS_ID' => $task2->TAS_ID ]); //Create the register in list unassigned related to the task3 - factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task3[0]->TAS_ID + factory(ListUnassigned::class, 10)->create([ + 'TAS_ID' => $task3->TAS_ID ]); //Create the register in list unassigned related to the task4 - factory(ListUnassigned::class, 15)->create([ - 'TAS_ID' => $task4[0]->TAS_ID + factory(ListUnassigned::class, 10)->create([ + 'TAS_ID' => $task4->TAS_ID ]); - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $timeEnd = microtime(true); - $this->assertEquals(60, $result); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task took [60]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(40, $result); } /** @@ -376,63 +357,60 @@ class ListUnassignedTest extends TestCase public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a case - $application = factory(Application::class, 1)->create(); + $application = factory(Application::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task1 self service value based - $task1 = factory(Task::class, 1)->create([ + $task1 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'TAS_ID' => $task1[0]->TAS_ID + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task1->TAS_ID ]); - factory(AppAssignSelfServiceValueGroup::class, 1)->create([ - 'ID' => $appSelfValue[0]->ID, - 'GRP_UID' => $user[0]->USR_UID, - 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 10)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, - 'TAS_ID' => $task1[0]->TAS_ID, + factory(ListUnassigned::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task1->TAS_ID, ]); //Create a task2 self service value based - $task2 = factory(Task::class, 1)->create([ + $task2 = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '@@ARRAY_OF_USERS', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Create the relation for the value assigned in the TAS_GROUP_VARIABLE - $appSelfValue = factory(AppAssignSelfServiceValue::class, 1)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'TAS_ID' => $task2[0]->TAS_ID + $appSelfValue = factory(AppAssignSelfServiceValue::class)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'TAS_ID' => $task2->TAS_ID ]); - factory(AppAssignSelfServiceValueGroup::class, 1)->create([ - 'ID' => $appSelfValue[0]->ID, - 'GRP_UID' => $user[0]->USR_UID, - 'ASSIGNEE_ID' => $user[0]->USR_ID, //The usrId or grpId + factory(AppAssignSelfServiceValueGroup::class)->create([ + 'ID' => $appSelfValue->ID, + 'GRP_UID' => $user->USR_UID, + 'ASSIGNEE_ID' => $user->USR_ID, //The usrId or grpId 'ASSIGNEE_TYPE' => 1 //Related to the user=1 related to the group=2 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 10)->create([ - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'DEL_INDEX' => $appSelfValue[0]->DEL_INDEX, - 'TAS_ID' => $task2[0]->TAS_ID, + factory(ListUnassigned::class, 15)->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'DEL_INDEX' => $appSelfValue->DEL_INDEX, + 'TAS_ID' => $task2->TAS_ID, ]); - $timeStart = microtime(true); - $result = ListUnassigned::doCount($user[0]->USR_UID); - $this->assertEquals(20, $result); - $timeEnd = microtime(true); - $time = $timeEnd - $timeStart; - error_log('it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid took [20]--->' . $time); + //Review the count self-service + $result = ListUnassigned::countSelfService($user->USR_UID); + $this->assertEquals(30, $result); } /** @@ -443,38 +421,38 @@ class ListUnassignedTest extends TestCase public function it_should_return_pages_of_data() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in list unassigned factory(ListUnassigned::class, 51)->create([ - 'TAS_ID' => $task[0]->TAS_ID + 'TAS_ID' => $task->TAS_ID ]); //Define the filters $filters = ['start' => 0, 'limit' => 25]; //Get data first page - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(25, $result); //Get data second page $filters = ['start' => 25, 'limit' => 25]; - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(25, $result); //Get data third page $filters = ['start' => 50, 'limit' => 25]; - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(1, $result); } @@ -486,44 +464,44 @@ class ListUnassignedTest extends TestCase public function it_should_sort_by_case_number() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create a case - $application = factory(Application::class, 1)->create([ + $application = factory(Application::class)->create([ 'APP_NUMBER' => 3000 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, - 'APP_NUMBER' => $application[0]->APP_NUMBER + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, + 'APP_NUMBER' => $application->APP_NUMBER ]); //Create a case - $application = factory(Application::class, 1)->create([ + $application = factory(Application::class)->create([ 'APP_NUMBER' => 2000 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, - 'APP_NUMBER' => $application[0]->APP_NUMBER + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, + 'APP_NUMBER' => $application->APP_NUMBER ]); //Define the filters $filters = ['sort' => 'APP_NUMBER', 'dir' => 'ASC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the minor case number first $this->assertEquals(2000, $result[0]['APP_NUMBER']); @@ -532,7 +510,7 @@ class ListUnassignedTest extends TestCase //Define the filters $filters = ['sort' => 'APP_NUMBER', 'dir' => 'DESC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the major case number first $this->assertEquals(3000, $result[0]['APP_NUMBER']); @@ -548,46 +526,46 @@ class ListUnassignedTest extends TestCase public function it_should_sort_by_case_title() { //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create a case - $application = factory(Application::class, 1)->create([ + $application = factory(Application::class)->create([ 'APP_NUMBER' => 3001 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'APP_TITLE' => 'Request nro ' . $application[0]->APP_NUMBER, + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_TITLE' => 'Request nro ' . $application->APP_NUMBER, ]); //Create a case - $application = factory(Application::class, 1)->create([ + $application = factory(Application::class)->create([ 'APP_NUMBER' => 2001 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, - 'APP_NUMBER' => $application[0]->APP_NUMBER, - 'APP_TITLE' => 'Request nro ' . $application[0]->APP_NUMBER, + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_TITLE' => 'Request nro ' . $application->APP_NUMBER, ]); //Define the filters $filters = ['sort' => 'APP_TITLE', 'dir' => 'ASC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the minor case title first $this->assertEquals('Request nro 2001', $result[0]['APP_TITLE']); @@ -596,7 +574,7 @@ class ListUnassignedTest extends TestCase //Define the filters $filters = ['sort' => 'APP_TITLE', 'dir' => 'DESC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the major case title first $this->assertEquals('Request nro 3001', $result[0]['APP_TITLE']); @@ -612,37 +590,37 @@ class ListUnassignedTest extends TestCase public function it_should_sort_by_process() { //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, 'APP_PRO_TITLE' => 'Egypt Supplier Payment Proposal', ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, 'APP_PRO_TITLE' => 'Russia Supplier Payment Proposal', ]); //Define the filters $filters = ['sort' => 'APP_PRO_TITLE', 'dir' => 'ASC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the minor process name first $this->assertEquals('Egypt Supplier Payment Proposal', $result[0]['APP_PRO_TITLE']); @@ -651,7 +629,7 @@ class ListUnassignedTest extends TestCase //Define the filters $filters = ['sort' => 'APP_PRO_TITLE', 'dir' => 'DESC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the major process name first $this->assertEquals('Russia Supplier Payment Proposal', $result[0]['APP_PRO_TITLE']); @@ -667,36 +645,36 @@ class ListUnassignedTest extends TestCase public function it_should_sort_by_task() { //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, 'APP_TAS_TITLE' => 'Initiate Request', ]); //Create the register in list unassigned - factory(ListUnassigned::class, 1)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + factory(ListUnassigned::class)->create([ + 'TAS_ID' => $task->TAS_ID, 'APP_TAS_TITLE' => 'Waiting for AP Manager Validation', ]); //Define the filters $filters = ['sort' => 'APP_TAS_TITLE', 'dir' => 'ASC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the minor task name first $this->assertEquals('Initiate Request', $result[0]['APP_TAS_TITLE']); @@ -705,7 +683,7 @@ class ListUnassignedTest extends TestCase //Define the filters $filters = ['sort' => 'APP_TAS_TITLE', 'dir' => 'DESC']; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the major task name first $this->assertEquals('Waiting for AP Manager Validation', $result[0]['APP_TAS_TITLE']); @@ -721,54 +699,54 @@ class ListUnassignedTest extends TestCase public function it_should_return_data_filtered_by_process_category() { //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create a category - $category = factory(ProcessCategory::class, 1)->create(); + $category = factory(ProcessCategory::class)->create(); //Create process - $process = factory(Process::class, 1)->create([ - 'PRO_CATEGORY' => $category[0]->CATEGORY_UID + $process = factory(Process::class)->create([ + 'PRO_CATEGORY' => $category->CATEGORY_UID ]); //Create a category - $category1 = factory(ProcessCategory::class, 1)->create(); + $category1 = factory(ProcessCategory::class)->create(); //Create process - $process1 = factory(Process::class, 1)->create([ - 'PRO_CATEGORY' => $category1[0]->CATEGORY_UID + $process1 = factory(Process::class)->create([ + 'PRO_CATEGORY' => $category1->CATEGORY_UID ]); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in list unassigned factory(ListUnassigned::class, 2)->create([ - 'TAS_ID' => $task[0]->TAS_ID, - 'PRO_UID' => $process[0]->PRO_UID, + 'TAS_ID' => $task->TAS_ID, + 'PRO_UID' => $process->PRO_UID, ]); //Create the register in list unassigned factory(ListUnassigned::class, 5)->create([ - 'TAS_ID' => $task[0]->TAS_ID, - 'PRO_UID' => $process1[0]->PRO_UID, + 'TAS_ID' => $task->TAS_ID, + 'PRO_UID' => $process1->PRO_UID, ]); //Get all data - $result = ListUnassigned::loadList($user[0]->USR_UID); + $result = ListUnassigned::loadList($user->USR_UID); $this->assertCount(7, $result); //Define the filters - $filters = ['category' => $category[0]->CATEGORY_UID]; + $filters = ['category' => $category->CATEGORY_UID]; //Get data - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Get the minor case number first - $this->assertEquals($category[0]->CATEGORY_UID, $result[0]['PRO_CATEGORY']); + $this->assertEquals($category->CATEGORY_UID, $result[0]['PRO_CATEGORY']); //Get the major case number second - $this->assertEquals($category[0]->CATEGORY_UID, $result[1]['PRO_CATEGORY']); + $this->assertEquals($category->CATEGORY_UID, $result[1]['PRO_CATEGORY']); } /** @@ -779,55 +757,55 @@ class ListUnassignedTest extends TestCase public function it_should_return_data_filtered_by_generic_search() { //Create user - $user = factory(User::class, 1)->create(); + $user = factory(User::class)->create(); //Create process - $process = factory(Process::class, 1)->create(); + $process = factory(Process::class)->create(); //Create a task self service - $task = factory(Task::class, 1)->create([ + $task = factory(Task::class)->create([ 'TAS_ASSIGN_TYPE' => 'SELF_SERVICE', 'TAS_GROUP_VARIABLE' => '', - 'PRO_UID' => $process[0]->PRO_UID + 'PRO_UID' => $process->PRO_UID ]); //Assign a user in the task - factory(TaskUser::class, 1)->create([ - 'TAS_UID' => $task[0]->TAS_UID, - 'USR_UID' => $user[0]->USR_UID, + factory(TaskUser::class)->create([ + 'TAS_UID' => $task->TAS_UID, + 'USR_UID' => $user->USR_UID, 'TU_RELATION' => 1, //Related to the user 'TU_TYPE' => 1 ]); //Create the register in list unassigned factory(ListUnassigned::class, 2)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + 'TAS_ID' => $task->TAS_ID, 'APP_TITLE' => 'This is a case name', ]); //Create the register in list unassigned factory(ListUnassigned::class, 2)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + 'TAS_ID' => $task->TAS_ID, 'APP_PRO_TITLE' => 'This is a process name', ]); //Create the register in list unassigned factory(ListUnassigned::class, 2)->create([ - 'TAS_ID' => $task[0]->TAS_ID, + 'TAS_ID' => $task->TAS_ID, 'APP_TAS_TITLE' => 'This is a task name', ]); //Create other registers factory(ListUnassigned::class, 4)->create([ - 'TAS_ID' => $task[0]->TAS_ID + 'TAS_ID' => $task->TAS_ID ]); //Define the filters $filters = ['search' => 'case name']; //Get data related to the search - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Define the filters $filters = ['search' => 'process name']; //Get data related to the search - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); //Define the filters $filters = ['search' => 'task name']; //Get data related to the search - $result = ListUnassigned::loadList($user[0]->USR_UID, $filters); + $result = ListUnassigned::loadList($user->USR_UID, $filters); $this->assertCount(2, $result); } } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Lists.php b/workflow/engine/src/ProcessMaker/BusinessModel/Lists.php index f1a1ceb08..3944c5243 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Lists.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Lists.php @@ -2,13 +2,13 @@ namespace ProcessMaker\BusinessModel; -use \G; -use \Criteria; -use \UsersPeer; -use \PMLicensedFeatures; +use G; +use Criteria; +use PMLicensedFeatures; +use ProcessMaker\Model\Delegation; +use UsersPeer; /** - * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia */ class Lists @@ -258,6 +258,7 @@ class Lists /** * Get counters for lists + * * @param $userId * @return array */ @@ -271,6 +272,13 @@ class Lists $total = $this->$listObject->getCountList($userId, array('action' => 'draft')); array_push($response, (array('count' => $total, 'item' => $item))); break; + case 'ListSelfService': + $total = Delegation::countSelfService($userId); + array_push($response, ([ + 'count' => $total, + 'item' => $item + ])); + break; /*----------------------------------********---------------------------------*/ case 'ListConsolidated': $licensedFeatures = PMLicensedFeatures::getSingleton(); diff --git a/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php b/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php index f2cf56c94..e6eb6796e 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php +++ b/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValue.php @@ -10,5 +10,63 @@ class AppAssignSelfServiceValue extends Model protected $primaryKey = 'ID'; // We do not have create/update timestamps for this table public $timestamps = false; + + /** + * Return the case number this belongs to + */ + public function appNumber() + { + return $this->belongsTo(Delegation::class, 'APP_NUMBER', 'APP_NUMBER'); + } + + /** + * Return the index this belongs to + */ + public function index() + { + return $this->belongsTo(Delegation::class, 'DEL_INDEX', 'DEL_INDEX'); + } + + /** + * Return the task this belongs to + */ + public function task() + { + return $this->belongsTo(Task::class, 'TAS_ID', 'TAS_ID'); + } + + /** + * Get cases with assignment Self-Service Value Based + * + * @param string $usrUid + * + * @return array + */ + public static function getSelfServiceCasesByEvaluatePerUser($usrUid) + { + //Get the groups related to the user + $groups = GroupUser::getGroups($usrUid); + + // Build query + $query = AppAssignSelfServiceValue::query()->select(); + $query->join('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP', function ($join) { + $join->on('APP_ASSIGN_SELF_SERVICE_VALUE.ID', '=', 'APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.ID'); + }); + $query->where(function ($query) use ($usrUid, $groups) { + //Filtering the user assigned in the task + $query->where('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.GRP_UID', '=', $usrUid); + if (!empty($groups)) { + //Consider the group related to the user + $query->orWhere(function ($query) use ($groups) { + $query->whereIn('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.ASSIGNEE_ID', $groups); + $query->where('APP_ASSIGN_SELF_SERVICE_VALUE_GROUP.ASSIGNEE_TYPE', '=', 2); + }); + } + }); + $query->distinct(); + $result = $query->get()->values()->toArray(); + + return $result; + } } diff --git a/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValueGroup.php b/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValueGroup.php index 44492e5cd..4b2a0696e 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValueGroup.php +++ b/workflow/engine/src/ProcessMaker/Model/AppAssignSelfServiceValueGroup.php @@ -9,5 +9,13 @@ class AppAssignSelfServiceValueGroup extends Model protected $table = 'APP_ASSIGN_SELF_SERVICE_VALUE_GROUP'; // We do not have create/update timestamps for this table public $timestamps = false; + + /** + * Return the appSelfServiceValue this belongs to + */ + public function appSelfService() + { + return $this->belongsTo(AppAssignSelfServiceValue::class, 'ID', 'ID'); + } } diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index cd694908d..661c6dbc8 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -58,6 +58,79 @@ class Delegation extends Model return $query->where('APP_UID', '=', $appUid); } + /** + * Scope a query to only include open threads + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIsThreadOpen($query) + { + return $query->where('DEL_THREAD_STATUS', '=', 'OPEN'); + } + + /** + * Scope a query to only include threads without user + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeNoUserInThread($query) + { + return $query->where('USR_ID', '=', 0); + } + + /** + * Scope a query to only include specific tasks + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $tasks + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTasksIn($query, array $tasks) + { + return $query->whereIn('APP_DELEGATION.TAS_ID', $tasks); + } + + /** + * Scope a query to only include a specific case + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $appNumber + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCase($query, $appNumber) + { + return $query->where('APP_NUMBER', '=', $appNumber); + } + + /** + * Scope a query to only include a specific index + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $index + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIndex($query, $index) + { + return $query->where('DEL_INDEX', '=', $index); + } + + /** + * Scope a query to only include a specific task + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $task + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTask($query, $task) + { + return $query->where('APP_DELEGATION.TAS_ID', '=', $task); + } + /** * Searches for delegations which match certain criteria * @@ -389,4 +462,47 @@ class Delegation extends Model return $arrayData; } + /** + * Count the self-services cases by user + * + * @param string $usrUid + * + * @return integer + */ + public static function countSelfService($usrUid) + { + //Get the task self services related to the user + $taskSelfService = TaskUser::getSelfServicePerUser($usrUid); + //Get the task self services value based related to the user + $selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid); + + //Start the query for get the cases related to the user + $query = Delegation::query()->select('APP_NUMBER'); + //Add Join with task filtering only the type self-service + $query->join('TASK', function ($join) { + $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') + ->where('TASK.TAS_ASSIGN_TYPE', '=', 'SELF_SERVICE'); + }); + //Filtering the open threads and without users + $query->isThreadOpen()->noUserInThread(); + + //Get the cases unassigned + if (!empty($selfServiceValueBased)) { + $query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) { + //Get the cases related to the task self service + $query->tasksIn($taskSelfService); + foreach ($selfServiceValueBased as $case) { + //Get the cases related to the task self service value based + $query->orWhere(function ($query) use ($case) { + $query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']); + }); + } + }); + } else { + //Get the cases related to the task self service + $query->tasksIn($taskSelfService); + } + + return $query->count(); + } } diff --git a/workflow/engine/src/ProcessMaker/Model/GroupUser.php b/workflow/engine/src/ProcessMaker/Model/GroupUser.php index b20474e02..101ba5e92 100644 --- a/workflow/engine/src/ProcessMaker/Model/GroupUser.php +++ b/workflow/engine/src/ProcessMaker/Model/GroupUser.php @@ -9,5 +9,53 @@ class GroupUser extends Model protected $table = 'GROUP_USER'; // We do not have create/update timestamps for this table public $timestamps = false; + + /** + * Return the user this belongs to + */ + public function user() + { + return $this->belongsTo(User::class, 'USR_UID', 'USR_UID'); + } + + /** + * Return the group user this belongs to + */ + public function groupsWf() + { + return $this->belongsTo(Groupwf::class, 'GRP_ID', 'GRP_ID'); + } + + /** + * Scope a query to specific user + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $user + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeUser($query, $user) + { + return $query->where('USR_UID', '=', $user); + } + + /** + * Return the groups from a user + * + * @param string $usrUid + * @param string $column + * + * @return array + */ + public static function getGroups($usrUid, $column = 'GRP_ID') + { + $groups = GroupUser::query()->select(['GROUP_USER.' . $column]) + ->join('GROUPWF', function ($join) use ($usrUid) { + $join->on('GROUPWF.GRP_ID', '=', 'GROUP_USER.GRP_ID') + ->where('GROUPWF.GRP_STATUS', 'ACTIVE') + ->where('GROUP_USER.USR_UID', $usrUid); + })->get()->values()->toArray(); + + return $groups; + } } diff --git a/workflow/engine/src/ProcessMaker/Model/Groupwf.php b/workflow/engine/src/ProcessMaker/Model/Groupwf.php index 3c6e306e2..5a383010b 100644 --- a/workflow/engine/src/ProcessMaker/Model/Groupwf.php +++ b/workflow/engine/src/ProcessMaker/Model/Groupwf.php @@ -10,5 +10,24 @@ class Groupwf extends Model protected $primaryKey = 'GRP_ID'; // We do not have create/update timestamps for this table public $timestamps = false; + + /** + * Scope a query to active groups + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeActive($query) + { + return $query->where('GRP_STATUS', '=', 'ACTIVE'); + } + + /** + * Return the user this belongs to + */ + public function groupUsers() + { + return $this->belongsTo(GroupUser::class, 'GRP_ID', 'GRP_ID'); + } } diff --git a/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php b/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php index 724d9912e..aa69c2f3c 100644 --- a/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php +++ b/workflow/engine/src/ProcessMaker/Model/ListUnassigned.php @@ -35,6 +35,57 @@ class ListUnassigned extends Model return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID'); } + /** + * Scope a query to only include specific tasks + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param array $tasks + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTasksIn($query, array $tasks) + { + return $query->whereIn('TAS_ID', $tasks); + } + + /** + * Scope a query to only include a specific case + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $appNumber + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeCase($query, $appNumber) + { + return $query->where('APP_NUMBER', '=', $appNumber); + } + + /** + * Scope a query to only include a specific index + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $index + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIndex($query, $index) + { + return $query->where('DEL_INDEX', '=', $index); + } + + /** + * Scope a query to only include a specific task + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param integer $task + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeTask($query, $task) + { + return $query->where('TAS_ID', '=', $task); + } + /** * Get count * @@ -51,6 +102,43 @@ class ListUnassigned extends Model return $result; } + /** + * Count the self-services cases by user + * + * @param string $usrUid + * + * @return integer + */ + public static function countSelfService($usrUid) + { + //Get the task self services related to the user + $taskSelfService = TaskUser::getSelfServicePerUser($usrUid); + //Get the task self services value based related to the user + $selfServiceValueBased = AppAssignSelfServiceValue::getSelfServiceCasesByEvaluatePerUser($usrUid); + + //Start the query for get the cases related to the user + $query = ListUnassigned::query()->select('APP_NUMBER'); + + //Get the cases unassigned + if (!empty($selfServiceValueBased)) { + $query->where(function ($query) use ($selfServiceValueBased, $taskSelfService) { + //Get the cases related to the task self service + $query->tasksIn($taskSelfService); + foreach ($selfServiceValueBased as $case) { + //Get the cases related to the task self service value based + $query->orWhere(function ($query) use ($case) { + $query->case($case['APP_NUMBER'])->index($case['DEL_INDEX'])->task($case['TAS_ID']); + }); + } + }); + } else { + //Get the cases related to the task self service + $query->tasksIn($taskSelfService); + } + + return $query->count(); + } + /** * Search data * diff --git a/workflow/engine/src/ProcessMaker/Model/Task.php b/workflow/engine/src/ProcessMaker/Model/Task.php index 89ab49222..3e78e3a33 100644 --- a/workflow/engine/src/ProcessMaker/Model/Task.php +++ b/workflow/engine/src/ProcessMaker/Model/Task.php @@ -20,4 +20,16 @@ class Task extends Model { return $this->hasMany(Delegation::class, 'TAS_ID', 'TAS_ID'); } + + /** + * Scope a query to only include self-service + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeIsSelfService($query) + { + return $query->where('TAS_ASSIGN_TYPE', '=', 'SELF_SERVICE') + ->where('TAS_GROUP_VARIABLE', '=', ''); + } } diff --git a/workflow/engine/src/ProcessMaker/Model/TaskUser.php b/workflow/engine/src/ProcessMaker/Model/TaskUser.php index 67549792b..b56897ff7 100644 --- a/workflow/engine/src/ProcessMaker/Model/TaskUser.php +++ b/workflow/engine/src/ProcessMaker/Model/TaskUser.php @@ -9,4 +9,64 @@ class TaskUser extends Model protected $table = 'TASK_USER'; public $timestamps = false; + + /** + * Return the task this belongs to + */ + public function task() + { + return $this->belongsTo(Task::class, 'TAS_UID', 'TAS_UID'); + } + + /** + * Return the user this belongs to + */ + public function user() + { + return $this->belongsTo(User::class, 'USR_UID', 'USR_UID'); + } + + /** + * Get the task self services related to the user + * + * @param string $usrUid + * + * @return array + */ + public static function getSelfServicePerUser($usrUid) + { + //Get the groups related to the user + $groups = GroupUser::getGroups($usrUid, 'GRP_UID'); + + // Build query + $query = Task::query()->select('TAS_ID'); + //Add Join with process filtering only the active process + $query->join('PROCESS', function ($join) { + $join->on('PROCESS.PRO_UID', '=', 'TASK.PRO_UID') + ->where('PROCESS.PRO_STATUS', 'ACTIVE'); + }); + //Add join with with the task users + $query->join('TASK_USER', function ($join) { + $join->on('TASK.TAS_UID', '=', 'TASK_USER.TAS_UID') + //We not considered the Ad-hoc + ->where('TASK_USER.TU_TYPE', '=', 1); + }); + //Filtering only the task self-service + $query->isSelfService(); + //Filtering the task related to the user + $query->where(function ($query) use ($usrUid, $groups) { + //Filtering the user assigned in the task + $query->where('TASK_USER.USR_UID', '=', $usrUid); + if (!empty($groups)) { + //Consider the group related to the user + $query->orWhere(function ($query) use ($groups) { + $query->whereIn('TASK_USER.USR_UID', $groups); + }); + } + }); + $query->distinct(); + $tasks = $query->get()->values()->toArray(); + + return $tasks; + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Model/User.php b/workflow/engine/src/ProcessMaker/Model/User.php index 7c6da958d..43e9ede32 100644 --- a/workflow/engine/src/ProcessMaker/Model/User.php +++ b/workflow/engine/src/ProcessMaker/Model/User.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = "USERS"; + protected $primaryKey = 'USR_ID'; // Our custom timestamp columns const CREATED_AT = 'USR_CREATE_DATE'; const UPDATED_AT = 'USR_UPDATE_DATE'; @@ -18,4 +19,24 @@ class User extends Model { return $this->hasMany(Delegation::class, 'USR_ID', 'USR_ID'); } + + /** + * Return the user this belongs to + */ + public function groups() + { + return $this->belongsTo(GroupUser::class, 'USR_UID', 'USR_UID'); + } + + /** + * Return the groups from a user + * + * @param boolean $usrUid + * + * @return array + */ + public static function getGroups($usrUid) + { + return User::find($usrUid)->groups()->get(); + } }