PMCORE-514

This commit is contained in:
Paula Quispe
2021-08-02 13:06:17 -04:00
parent f6770eff24
commit 2077edb64b
11 changed files with 393 additions and 279 deletions

View File

@@ -9,8 +9,8 @@ $factory->define(\ProcessMaker\Model\AppDelay::class, function (Faker $faker) {
'PRO_UID' => G::generateUniqueID(), 'PRO_UID' => G::generateUniqueID(),
'APP_UID' => G::generateUniqueID(), 'APP_UID' => G::generateUniqueID(),
'APP_NUMBER' => $faker->unique()->numberBetween(1000), 'APP_NUMBER' => $faker->unique()->numberBetween(1000),
'APP_THREAD_INDEX' => 1, 'APP_THREAD_INDEX' => $faker->unique()->numberBetween(100),
'APP_DEL_INDEX' => $faker->unique()->numberBetween(10), 'APP_DEL_INDEX' => $faker->unique()->numberBetween(100),
'APP_TYPE' => $faker->randomElement($actions), 'APP_TYPE' => $faker->randomElement($actions),
'APP_STATUS' => 'TO_DO', 'APP_STATUS' => 'TO_DO',
'APP_NEXT_TASK' => 0, 'APP_NEXT_TASK' => 0,
@@ -28,56 +28,33 @@ $factory->define(\ProcessMaker\Model\AppDelay::class, function (Faker $faker) {
// Create a delegation with the foreign keys // Create a delegation with the foreign keys
$factory->state(\ProcessMaker\Model\AppDelay::class, 'paused_foreign_keys', function (Faker $faker) { $factory->state(\ProcessMaker\Model\AppDelay::class, 'paused_foreign_keys', function (Faker $faker) {
// Create values in the foreign key relations // Create values in the foreign key relations
$user = factory(\ProcessMaker\Model\User::class)->create(); $delegation1 = factory(\ProcessMaker\Model\Delegation::class)->states('closed')->create();
$process = factory(\ProcessMaker\Model\Process::class)->create(); $delegation2 = factory(\ProcessMaker\Model\Delegation::class)->states('foreign_keys')->create([
$task = factory(\ProcessMaker\Model\Task::class)->create([ 'PRO_UID' => $delegation1->PRO_UID,
'PRO_UID' => $process->PRO_UID, 'PRO_ID' => $delegation1->PRO_ID,
'PRO_ID' => $process->PRO_ID 'TAS_UID' => $delegation1->TAS_UID,
]); 'TAS_ID' => $delegation1->TAS_ID,
$application = factory(\ProcessMaker\Model\Application::class)->create([ 'APP_NUMBER' => $delegation1->APP_NUMBER,
'PRO_UID' => $process->PRO_UID, 'APP_UID' => $delegation1->APP_UID,
'APP_INIT_USER' => $user->USR_UID,
'APP_CUR_USER' => $user->USR_UID
]);
$delegation1 = factory(\ProcessMaker\Model\Delegation::class)->create([
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'DEL_THREAD_STATUS' => 'CLOSED',
'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID,
'DEL_PREVIOUS' => 0,
'DEL_INDEX' => 1
]);
$delegation = factory(\ProcessMaker\Model\Delegation::class)->create([
'PRO_UID' => $process->PRO_UID,
'PRO_ID' => $process->PRO_ID,
'TAS_UID' => $task->TAS_UID,
'TAS_ID' => $task->TAS_ID,
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'DEL_THREAD_STATUS' => 'OPEN', 'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID, 'USR_UID' => $delegation1->USR_UID,
'USR_ID' => $user->USR_ID, 'USR_ID' => $delegation1->USR_ID,
'DEL_PREVIOUS' => $delegation1->DEL_INDEX, 'DEL_PREVIOUS' => $delegation1->DEL_INDEX,
'DEL_INDEX' => $delegation1->DEL_INDEX++ 'DEL_INDEX' => $faker->unique()->numberBetween(2000),
]); ]);
// Return with default values // Return with default values
return [ return [
'APP_DELAY_UID' => G::generateUniqueID(), 'APP_DELAY_UID' => G::generateUniqueID(),
'PRO_UID' => $process->PRO_UID, 'PRO_UID' => $delegation2->PRO_UID,
'PRO_ID' => $process->PRO_ID, 'PRO_ID' => $delegation2->PRO_ID,
'APP_UID' => $application->APP_UID, 'APP_UID' => $delegation2->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER, 'APP_NUMBER' => $delegation2->APP_NUMBER,
'APP_DEL_INDEX' => $delegation->DEL_INDEX, 'APP_DEL_INDEX' => $delegation2->DEL_INDEX,
'APP_TYPE' => 'PAUSE', 'APP_TYPE' => 'PAUSE',
'APP_STATUS' => $application->APP_STATUS, 'APP_STATUS' => 'TO_DO',
'APP_DELEGATION_USER' => $user->USR_UID, 'APP_DELEGATION_USER' => $delegation2->USR_UID,
'APP_DELEGATION_USER_ID' => $user->USR_ID, 'APP_DELEGATION_USER_ID' => $delegation2->USR_ID,
'APP_ENABLE_ACTION_USER' => G::generateUniqueID(), 'APP_ENABLE_ACTION_USER' => G::generateUniqueID(),
'APP_ENABLE_ACTION_DATE' => $faker->dateTime(), 'APP_ENABLE_ACTION_DATE' => $faker->dateTime(),
'APP_DISABLE_ACTION_USER' => 0, 'APP_DISABLE_ACTION_USER' => 0,

View File

@@ -69,7 +69,7 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'foreign_keys', function
return [ return [
'DELEGATION_ID' => $faker->unique()->numberBetween(5000), 'DELEGATION_ID' => $faker->unique()->numberBetween(5000),
'APP_UID' => $application->APP_UID, 'APP_UID' => $application->APP_UID,
'DEL_INDEX' => 1, 'DEL_INDEX' => $faker->unique()->numberBetween(2000),
'APP_NUMBER' => $application->APP_NUMBER, 'APP_NUMBER' => $application->APP_NUMBER,
'DEL_PREVIOUS' => 0, 'DEL_PREVIOUS' => 0,
'PRO_UID' => $process->PRO_UID, 'PRO_UID' => $process->PRO_UID,
@@ -176,7 +176,17 @@ $factory->state(\ProcessMaker\Model\Delegation::class, 'closed', function (Faker
// Create a last delegation // Create a last delegation
$factory->state(\ProcessMaker\Model\Delegation::class, 'last_thread', function (Faker $faker) { $factory->state(\ProcessMaker\Model\Delegation::class, 'last_thread', function (Faker $faker) {
return [ return [
'DEL_LAST_INDEX' => 1, 'DEL_LAST_INDEX' => 1,
]; ];
}); });
// Create a first delegation
$factory->state(\ProcessMaker\Model\Delegation::class, 'first_thread', function (Faker $faker) {
return [
'DEL_INDEX' => 1,
'DEL_PREVIOUS' => 0,
];
});

View File

@@ -354,6 +354,7 @@ class DraftTest extends TestCase
* It tests the getCountersByProcesses() method with the category filter * It tests the getCountersByProcesses() method with the category filter
* *
* @covers \ProcessMaker\BusinessModel\Cases\Draft::getCountersByProcesses() * @covers \ProcessMaker\BusinessModel\Cases\Draft::getCountersByProcesses()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getCountersByProcesses()
* @test * @test
*/ */
public function it_should_test_get_counters_by_processes_method_category() public function it_should_test_get_counters_by_processes_method_category()
@@ -643,6 +644,7 @@ class DraftTest extends TestCase
* It tests the getCountersByRange() method * It tests the getCountersByRange() method
* *
* @covers \ProcessMaker\BusinessModel\Cases\Draft::getCountersByRange() * @covers \ProcessMaker\BusinessModel\Cases\Draft::getCountersByRange()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getCountersByProcesses()
* @test * @test
*/ */
public function it_should_test_get_counters_by_range_method() public function it_should_test_get_counters_by_range_method()

View File

@@ -199,6 +199,7 @@ class InboxTest extends TestCase
* @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData()
* @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::getColumnsView()
* @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters() * @covers \ProcessMaker\BusinessModel\Cases\Inbox::filters()
* @covers \ProcessMaker\Model\Delegation::scopeTask()
* @test * @test
*/ */
public function it_filter_by_task() public function it_filter_by_task()

View File

@@ -5,6 +5,7 @@ namespace ProcessMaker\BusinessModel;
use Exception; use Exception;
use G; use G;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\AppDelay;
use ProcessMaker\Model\Application; use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Documents; use ProcessMaker\Model\Documents;
@@ -380,4 +381,45 @@ class CasesTest extends TestCase
// Get DynaForms assigned as steps for the second task when the application status is COMPLETED // Get DynaForms assigned as steps for the second task when the application status is COMPLETED
self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED')); self::assertCount(1, Cases::dynaFormsByApplication($application->APP_UID, $task2->TAS_UID, '', 'COMPLETED'));
} }
/**
* It test the case info used in the PMFCaseLink
*
* @covers \ProcessMaker\BusinessModel\Cases::getStatusInfo()
* @covers \ProcessMaker\Model\AppDelay::getPaused()
* @test
*/
public function it_should_test_case_status_info()
{
// Get status info when the case is PAUSED
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$cases = new Cases();
$result = $cases->getStatusInfo($table->APP_UID, $table->APP_DEL_INDEX, $table->APP_DELEGATION_USER);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('APP_STATUS', $result);
$this->assertArrayHasKey('DEL_INDEX', $result);
$this->assertArrayHasKey('PRO_UID', $result);
// Get status info when the case is UNASSIGNED
// Get status info when the case is TO_DO
$table = factory(Delegation::class)->states('foreign_keys')->create();
$cases = new Cases();
$result = $cases->getStatusInfo($table->APP_UID, $table->DEL_INDEX, $table->USR_UID);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('APP_STATUS', $result);
$this->assertArrayHasKey('DEL_INDEX', $result);
$this->assertArrayHasKey('PRO_UID', $result);
// Get status info when the case is COMPLETED
$table = factory(Application::class)->states('completed')->create();
$table = factory(Delegation::class)->states('foreign_keys')->create([
'APP_NUMBER' => $table->APP_NUMBER,
'APP_UID' => $table->APP_UID,
]);
$cases = new Cases();
$result = $cases->getStatusInfo($table->APP_UID, $table->DEL_INDEX, $table->USR_UID);
$this->assertNotEmpty($result);
$this->assertArrayHasKey('APP_STATUS', $result);
$this->assertArrayHasKey('DEL_INDEX', $result);
$this->assertArrayHasKey('PRO_UID', $result);
}
} }

View File

@@ -0,0 +1,102 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\Model\AppDelay;
use Tests\TestCase;
/**
* Class AppDelayTest
*
* @coversDefaultClass \ProcessMaker\Model\AppDelay
*/
class AppDelayTest extends TestCase
{
use DatabaseTransactions;
/**
* Set up function.
*/
public function setUp()
{
parent::setUp();
AppDelay::truncate();
}
/**
* This test scopeType
*
* @covers \ProcessMaker\Model\AppDelay::scopeType()
* @test
*/
public function it_return_scope_type()
{
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$this->assertCount(1, $table->type('PAUSE')->get());
}
/**
* This test scopeNotDisabled
*
* @covers \ProcessMaker\Model\AppDelay::scopeNotDisabled()
* @test
*/
public function it_return_scope_not_action_disable()
{
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$this->assertCount(1, $table->notDisabled()->get());
}
/**
* This test scopeCase
*
* @covers \ProcessMaker\Model\AppDelay::scopeCase()
* @test
*/
public function it_return_scope_case()
{
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$this->assertCount(1, $table->case($table->APP_NUMBER)->get());
}
/**
* This test scopeIndex
*
* @covers \ProcessMaker\Model\AppDelay::scopeIndex()
* @test
*/
public function it_return_scope_index()
{
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$this->assertCount(1, $table->index($table->APP_DEL_INDEX)->get());
}
/**
* This test scopeDelegateUser
*
* @covers \ProcessMaker\Model\AppDelay::scopeDelegateUser()
* @test
*/
public function it_return_scope_delegate_user()
{
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$this->assertCount(1, $table->delegateUser($table->APP_DELEGATION_USER)->get());
}
/**
* This test getPaused
*
* @covers \ProcessMaker\Model\AppDelay::getPaused()
* @covers \ProcessMaker\Model\AppDelay::scopeCase()
* @covers \ProcessMaker\Model\AppDelay::scopeIndex()
* @covers \ProcessMaker\Model\AppDelay::scopeDelegateUser()
* @test
*/
public function it_return_paused_threads()
{
$table = factory(AppDelay::class)->states('paused_foreign_keys')->create();
$result = AppDelay::getPaused($table->APP_NUMBER, $table->APP_DEL_INDEX, $table->APP_DELEGATION_USER);
$this->assertNotEmpty($result);
}
}

View File

@@ -170,7 +170,7 @@ class DelegationTest extends TestCase
*/ */
public function it_return_scope_case_started() public function it_return_scope_case_started()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('first_thread')->create();
$this->assertCount(1, $table->caseStarted($table->DEL_INDEX)->get()); $this->assertCount(1, $table->caseStarted($table->DEL_INDEX)->get());
} }
@@ -532,7 +532,7 @@ class DelegationTest extends TestCase
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create();
$cases = [$table->APP_NUMBER]; $cases = [$table->APP_NUMBER];
$rangeCases = [$table->APP_NUMBER.'-'.$table->APP_NUMBER]; $rangeCases = [$table->APP_NUMBER . '-' . $table->APP_NUMBER];
$this->assertCount(1, $table->casesOrRangeOfCases($cases, $rangeCases)->get()); $this->assertCount(1, $table->casesOrRangeOfCases($cases, $rangeCases)->get());
} }
@@ -2150,6 +2150,8 @@ class DelegationTest extends TestCase
//Review the self-service records //Review the self-service records
$result = Delegation::getSelfService($user->USR_UID); $result = Delegation::getSelfService($user->USR_UID);
$this->assertEquals(25, count($result)); $this->assertEquals(25, count($result));
$result = Delegation::getSelfService($user->USR_UID, ['APP_DELEGATION.APP_NUMBER', 'APP_DELEGATION.DEL_INDEX'], null, null,null, null, null, 0, 15);
$this->assertEquals(15, count($result));
} }
/** /**
@@ -3369,7 +3371,7 @@ class DelegationTest extends TestCase
*/ */
public function it_get_cases_started_by_specific_user() public function it_get_cases_started_by_specific_user()
{ {
$delegation = factory(Delegation::class)->states('foreign_keys')->create(); $delegation = factory(Delegation::class)->states('first_thread')->create();
$result = Delegation::casesStartedBy($delegation->USR_ID); $result = Delegation::casesStartedBy($delegation->USR_ID);
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }

View File

@@ -46,6 +46,7 @@ use ProcessMaker\BusinessModel\User as BmUser;
use ProcessMaker\Core\System; use ProcessMaker\Core\System;
use ProcessMaker\Exception\UploadException; use ProcessMaker\Exception\UploadException;
use ProcessMaker\Exception\CaseNoteUploadFile; use ProcessMaker\Exception\CaseNoteUploadFile;
use ProcessMaker\Model\AppDelay as Delay;
use ProcessMaker\Model\Application as ModelApplication; use ProcessMaker\Model\Application as ModelApplication;
use ProcessMaker\Model\AppNotes as Notes; use ProcessMaker\Model\AppNotes as Notes;
use ProcessMaker\Model\AppTimeoutAction; use ProcessMaker\Model\AppTimeoutAction;
@@ -2456,33 +2457,25 @@ class Cases
/** /**
* This function get the status information * This function get the status information
* *
* @param object $rsCriteria * @param array $result
* @param string $status
* *
* @return array * @return array
* @throws Exception * @throws Exception
*/ */
private function getStatusInfoDataByRsCriteria($rsCriteria) private function getStatusInfoFormatted(array $result, string $status = '')
{ {
try { try {
$arrayData = []; $record = head($result);
$arrayData = [
if ($rsCriteria->next()) { 'APP_STATUS' => empty($status) ? $record['APP_STATUS'] : $status,
$record = $rsCriteria->getRow(); 'DEL_INDEX' => [],
'PRO_UID' => $record['PRO_UID']
$arrayData = [ ];
'APP_STATUS' => $record['APP_STATUS'], $arrayData['DEL_INDEX'][] = $record['DEL_INDEX'];
'DEL_INDEX' => [], foreach ($result as $record) {
'PRO_UID' => $record['PRO_UID']
];
$arrayData['DEL_INDEX'][] = $record['DEL_INDEX']; $arrayData['DEL_INDEX'][] = $record['DEL_INDEX'];
while ($rsCriteria->next()) {
$record = $rsCriteria->getRow();
$arrayData['DEL_INDEX'][] = $record['DEL_INDEX'];
}
} }
//Return //Return
return $arrayData; return $arrayData;
} catch (Exception $e) { } catch (Exception $e) {
@@ -2493,8 +2486,8 @@ class Cases
/** /**
* Get status info Case * Get status info Case
* *
* @param string $applicationUid Unique id of Case * @param string $appUid Unique id of Case
* @param int $delIndex Delegation index * @param int $index Delegation index
* @param string $userUid Unique id of User * @param string $userUid Unique id of User
* *
* @return array Return an array with status info Case, array empty otherwise * @return array Return an array with status info Case, array empty otherwise
@@ -2502,179 +2495,120 @@ class Cases
* *
* @see workflow/engine/methods/cases/main_init.php * @see workflow/engine/methods/cases/main_init.php
* @see workflow/engine/methods/cases/opencase.php * @see workflow/engine/methods/cases/opencase.php
* @see ProcessMaker\BusinessModel\Cases->setCaseVariables() * @see \ProcessMaker\BusinessModel\Cases::setCaseVariables()
* @see ProcessMaker\BusinessModel\Cases\InputDocument->getCasesInputDocuments() * @see \ProcessMaker\BusinessModel\Cases\InputDocument::getCasesInputDocuments()
* @see ProcessMaker\BusinessModel\Cases\InputDocument->throwExceptionIfHaventPermissionToDelete() * @see \ProcessMaker\BusinessModel\Cases\InputDocument::throwExceptionIfHaventPermissionToDelete()
* @see ProcessMaker\BusinessModel\Cases\OutputDocument->throwExceptionIfCaseNotIsInInbox() * @see \ProcessMaker\BusinessModel\Cases\OutputDocument::throwExceptionIfCaseNotIsInInbox()
* @see ProcessMaker\BusinessModel\Cases\OutputDocument->throwExceptionIfHaventPermissionToDelete() * @see \ProcessMaker\BusinessModel\Cases\OutputDocument::throwExceptionIfHaventPermissionToDelete()
*/ */
public function getStatusInfo($applicationUid, $delIndex = 0, $userUid = "") public function getStatusInfo(string $appUid, int $index = 0, string $userUid = "")
{ {
try { try {
//Verify data $arrayData = [];
$this->throwExceptionIfNotExistsCase($applicationUid, $delIndex, // Verify data
$this->getFieldNameByFormatFieldName("APP_UID")); $this->throwExceptionIfNotExistsCase($appUid, $index, $this->getFieldNameByFormatFieldName("APP_UID"));
// Get the case number
//Get data $caseNumber = ModelApplication::getCaseNumber($appUid);
//Status is PAUSED // Status is PAUSED
$delimiter = DBAdapter::getStringDelimiter(); $result = Delay::getPaused($caseNumber, $index, $userUid);
if (!empty($result)) {
$criteria = new Criteria("workflow"); $arrayData = $this->getStatusInfoFormatted($result, 'PAUSED');
return $arrayData;
$criteria->setDistinct();
$criteria->addSelectColumn($delimiter . 'PAUSED' . $delimiter . ' AS APP_STATUS');
$criteria->addSelectColumn(AppDelayPeer::APP_DEL_INDEX . " AS DEL_INDEX");
$criteria->addSelectColumn(AppDelayPeer::PRO_UID);
$criteria->add(AppDelayPeer::APP_UID, $applicationUid, Criteria::EQUAL);
$criteria->add(AppDelayPeer::APP_TYPE, "PAUSE", Criteria::EQUAL);
$criteria->add(
$criteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, null, Criteria::ISNULL)->addOr(
$criteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, 0, Criteria::EQUAL))
);
if ($delIndex != 0) {
$criteria->add(AppDelayPeer::APP_DEL_INDEX, $delIndex, Criteria::EQUAL);
} }
if ($userUid != "") { // Status is UNASSIGNED
$criteria->add(AppDelayPeer::APP_DELEGATION_USER, $userUid, Criteria::EQUAL); $query = Delegation::query()->select([
'APP_DELEGATION.APP_NUMBER',
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.PRO_UID'
]);
$query->taskAssignType('SELF_SERVICE');
$query->threadOpen()->withoutUserId();
// Filter specific user
if (!empty($userUid)) {
$delegation = new Delegation();
$delegation->casesUnassigned($query, $userUid);
}
// Filter specific case
$query->case($caseNumber);
// Filter specific index
if (is_int($index)) {
$query->index($index);
}
$results = $query->get();
$arrayData = $results->values()->toArray();
if (!empty($arrayData)) {
$arrayData = $this->getStatusInfoFormatted($arrayData, 'UNASSIGNED');
return $arrayData;
} }
$rsCriteria = AppDelayPeer::doSelectRS($criteria); // Status is TO_DO, DRAFT
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); $query = Delegation::query()->select([
'APPLICATION.APP_STATUS',
'APP_DELEGATION.APP_NUMBER',
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.PRO_UID'
]);
$query->joinApplication();
// Filter the status TO_DO and DRAFT
$query->casesInProgress([1, 2]);
// Filter the OPEN thread
$query->threadOpen();
// Filter specific case
$query->case($caseNumber);
// Filter specific index
if ($index > 0) {
$query->index($index);
}
// Filter specific user
if (!empty($userUid)) {
$userId = !empty($userUid) ? User::getId($userUid) : 0;
$query->userId($userId);
}
$results = $query->get();
$arrayData = $results->values()->toArray();
$arrayData = $this->getStatusInfoDataByRsCriteria($rsCriteria); if (!empty($arrayData)) {
$arrayData = $this->getStatusInfoFormatted($arrayData);
return $arrayData;
}
// Status is CANCELLED, COMPLETED
$query = Delegation::query()->select([
'APPLICATION.APP_STATUS',
'APP_DELEGATION.APP_NUMBER',
'APP_DELEGATION.DEL_INDEX',
'APP_DELEGATION.PRO_UID'
]);
$query->joinApplication();
// Filter the status COMPLETED and CANCELLED
$query->casesDone([3, 4]);
// Filter specific case
$query->case($caseNumber);
// Filter specific index
if ($index > 0) {
$query->index($index);
}
// Filter specific user
if (!empty($userUid)) {
$userId = !empty($userUid) ? User::getId($userUid) : 0;
$query->userId($userId);
}
$query->lastThread();
$results = $query->get();
$arrayData = $results->values()->toArray();
if (!empty($arrayData)) {
$arrayData = $this->getStatusInfoFormatted($arrayData);
return $arrayData;
}
// Status is PARTICIPATED
$arrayData = Delegation::getParticipatedInfo($appUid);
if (!empty($arrayData)) { if (!empty($arrayData)) {
return $arrayData; return $arrayData;
} }
//Status is UNASSIGNED return $arrayData;
if ($userUid != '') {
$appCacheView = new AppCacheView();
$criteria = $appCacheView->getUnassignedListCriteria($userUid);
} else {
$criteria = new Criteria('workflow');
$criteria->add(AppCacheViewPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
$criteria->add(AppCacheViewPeer::USR_UID, '', Criteria::EQUAL);
}
$criteria->setDistinct();
$criteria->clearSelectColumns();
$criteria->addSelectColumn($delimiter . 'UNASSIGNED' . $delimiter . ' AS APP_STATUS');
$criteria->addSelectColumn(AppCacheViewPeer::DEL_INDEX);
$criteria->addSelectColumn(AppCacheViewPeer::PRO_UID);
$criteria->add(AppCacheViewPeer::APP_UID, $applicationUid, Criteria::EQUAL);
if ($delIndex != 0) {
$criteria->add(AppCacheViewPeer::DEL_INDEX, $delIndex, Criteria::EQUAL);
}
$rsCriteria = AppCacheViewPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$arrayData = $this->getStatusInfoDataByRsCriteria($rsCriteria);
if (!empty($arrayData)) {
return $arrayData;
}
//Status is TO_DO, DRAFT
$criteria = new Criteria("workflow");
$criteria->setDistinct();
$criteria->addSelectColumn(ApplicationPeer::APP_STATUS);
$criteria->addSelectColumn(ApplicationPeer::PRO_UID);
$criteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$arrayCondition = array();
$arrayCondition[] = array(ApplicationPeer::APP_UID, AppDelegationPeer::APP_UID, Criteria::EQUAL);
$arrayCondition[] = array(
ApplicationPeer::APP_UID,
$delimiter . $applicationUid . $delimiter,
Criteria::EQUAL
);
$criteria->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);
$criteria->add(
$criteria->getNewCriterion(ApplicationPeer::APP_STATUS, "TO_DO", Criteria::EQUAL)->addAnd(
$criteria->getNewCriterion(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL))->addAnd(
$criteria->getNewCriterion(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN"))
)->addOr(
$criteria->getNewCriterion(ApplicationPeer::APP_STATUS, "DRAFT", Criteria::EQUAL)->addAnd(
$criteria->getNewCriterion(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN"))
);
if ($delIndex != 0) {
$criteria->add(AppDelegationPeer::DEL_INDEX, $delIndex, Criteria::EQUAL);
}
if ($userUid != "") {
$criteria->add(AppDelegationPeer::USR_UID, $userUid, Criteria::EQUAL);
}
$rsCriteria = ApplicationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$arrayData = $this->getStatusInfoDataByRsCriteria($rsCriteria);
if (!empty($arrayData)) {
return $arrayData;
}
//Status is CANCELLED, COMPLETED
$criteria = new Criteria("workflow");
$criteria->addSelectColumn(ApplicationPeer::APP_STATUS);
$criteria->addSelectColumn(ApplicationPeer::PRO_UID);
$criteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
$arrayCondition = array();
$arrayCondition[] = array(ApplicationPeer::APP_UID, AppDelegationPeer::APP_UID, Criteria::EQUAL);
$arrayCondition[] = array(
ApplicationPeer::APP_UID,
$delimiter . $applicationUid . $delimiter,
Criteria::EQUAL
);
$criteria->addJoinMC($arrayCondition, Criteria::LEFT_JOIN);
if ($delIndex != 0) {
$criteria->add(AppDelegationPeer::DEL_INDEX, $delIndex, Criteria::EQUAL);
}
if ($userUid != "") {
$criteria->add(AppDelegationPeer::USR_UID, $userUid, Criteria::EQUAL);
}
$criteria2 = clone $criteria;
$criteria2->setDistinct();
$criteria2->add(ApplicationPeer::APP_STATUS, ['CANCELLED', 'COMPLETED'], Criteria::IN);
$criteria2->add(AppDelegationPeer::DEL_LAST_INDEX, 1, Criteria::EQUAL);
$rsCriteria2 = ApplicationPeer::doSelectRS($criteria2);
$rsCriteria2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$arrayData = $this->getStatusInfoDataByRsCriteria($rsCriteria2);
if (!empty($arrayData)) {
return $arrayData;
}
//Status is PARTICIPATED
$arrayData = Delegation::getParticipatedInfo($applicationUid);
if (!empty($arrayData)) {
return $arrayData;
}
//Return
return array();
} catch (Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }

View File

@@ -1492,8 +1492,7 @@ class AbstractCases implements CasesInterface
/** /**
* Count how many cases has each process * Count how many cases has each process
* *
* @param string $list
* @param int $category * @param int $category
* @param bool $topTen * @param bool $topTen
* @param array $processes * @param array $processes
@@ -1528,7 +1527,7 @@ class AbstractCases implements CasesInterface
$query->topTen('TOTAL', 'DESC'); $query->topTen('TOTAL', 'DESC');
} }
if (!empty($processes)) { if (!empty($processes)) {
$query->inProcesses($processes); $query->processInList($processes);
} }
return $query->get()->values()->toArray(); return $query->get()->values()->toArray();
} }
@@ -1574,7 +1573,7 @@ class AbstractCases implements CasesInterface
} }
$query->joinProcess(); $query->joinProcess();
if (!is_null($processId)) { if (!is_null($processId)) {
$query->inProcesses([$processId]); $query->processInList([$processId]);
} }
if (!is_null($dateFrom)) { if (!is_null($dateFrom)) {
$query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '>=', $dateFrom); $query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '>=', $dateFrom);

View File

@@ -30,4 +30,94 @@ class AppDelay extends Model
'APP_ENABLE_ACTION_DATE', 'APP_ENABLE_ACTION_DATE',
'APP_DISABLE_ACTION_DATE', 'APP_DISABLE_ACTION_DATE',
]; ];
/**
* Scope a query to filter a specific type
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $type
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeType($query, string $type = 'PAUSE')
{
return $query->where('APP_DELAY.APP_TYPE', $type);
}
/**
* Scope a query to filter a specific disable action
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeNotDisabled($query)
{
return $query->where('APP_DELAY.APP_DISABLE_ACTION_USER', 0);
}
/**
* Scope a query to filter a specific case
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $appNumber
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCase($query, int $appNumber)
{
return $query->where('APP_DELAY.APP_NUMBER', $appNumber);
}
/**
* Scope a query to filter a specific index
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $index
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, int $index)
{
return $query->where('APP_DELAY.APP_DEL_INDEX', $index);
}
/**
* Scope a query to filter a specific user
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $user
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDelegateUser($query, string $user)
{
return $query->where('APP_DELAY.APP_DELEGATION_USER', $user);
}
/**
* Get the thread paused
*
* @param int $appNumber
* @param int $index
* @param string $userUid
*
* @return array
*/
public static function getPaused(int $appNumber, int $index, string $userUid = '')
{
$query = AppDelay::query()->select([
'APP_NUMBER',
'APP_DEL_INDEX AS DEL_INDEX',
'PRO_UID'
]);
$query->type('PAUSE')->notDisabled();
$query->case($appNumber);
// Filter specific index
if ($index > 0) {
$query->index($index);
}
// Filter specific delegate user
if (!empty($userUid)) {
$query->delegateUser($userUid);
}
// Get the result
$results = $query->get();
return $results->values()->toArray();
}
} }

View File

@@ -173,18 +173,6 @@ class Delegation extends Model
return $query->where('DEL_INDEX', '=', 1); return $query->where('DEL_INDEX', '=', 1);
} }
/**
* Scope a query to get the in-progress
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCaseInProgress($query)
{
return $query->statusIds([Application::STATUS_DRAFT, Application::STATUS_TODO]);
}
/** /**
* Scope a query to get the to_do cases * Scope a query to get the to_do cases
* *
@@ -777,19 +765,6 @@ class Delegation extends Model
return $query->whereIn('APP_DELEGATION.PRO_ID', $processes); return $query->whereIn('APP_DELEGATION.PRO_ID', $processes);
} }
/**
* Scope where in processes
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $processes
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeInProcesses($query, array $processes)
{
return $query->whereIn('PROCESS.PRO_ID', $processes);
}
/** /**
* Scope the Inbox cases * Scope the Inbox cases
* *
@@ -812,26 +787,6 @@ class Delegation extends Model
return $query; return $query;
} }
/**
* Scope the Inbox cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeInboxWithoutUser($query)
{
// This scope is for the join with the APP_DELEGATION table
$query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Scope that establish that the DEL_THREAD_STATUS must be OPEN
$query->threadOpen();
return $query;
}
/** /**
* Scope a self service cases * Scope a self service cases
* *
@@ -1417,7 +1372,7 @@ class Delegation extends Model
* @param string $appUid * @param string $appUid
* @return array * @return array
* *
* @see \ProcessMaker\BusinessModel\Cases:getStatusInfo() * @see \ProcessMaker\BusinessModel\Cases::getStatusInfo()
*/ */
public static function getParticipatedInfo($appUid) public static function getParticipatedInfo($appUid)
{ {