PMCORE-2381

This commit is contained in:
Paula Quispe
2020-11-25 18:11:22 -04:00
parent a00593696d
commit 6bdadfd59c
21 changed files with 1925 additions and 731 deletions

View File

@@ -103,13 +103,30 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_priority() public function it_return_set_get_priority()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$arguments = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH']; $arguments = ['ALL', 'VL', 'L', 'N', 'H', 'VH'];
$index = array_rand($arguments); $index = array_rand($arguments);
$absCases->setPriority($index); $absCases->setPriority($arguments[$index]);
$actual = $absCases->getPriority(); $actual = $absCases->getPriority();
$this->assertEquals($index, $actual); $this->assertEquals($index, $actual);
} }
/**
* This check the getter and setter related to the priorities
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setPriorities()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getPriorities()
* @test
*/
public function it_return_set_get_priorities()
{
$absCases = new AbstractCases();
$arguments = ['ALL', 'VL', 'L', 'N', 'H', 'VH'];
$index = array_rand($arguments);
$absCases->setPriorities([$arguments[$index]]);
$actual = $absCases->getPriorities();
$this->assertEquals([$index], $actual);
}
/** /**
* This check the getter and setter related to the case number * This check the getter and setter related to the case number
* *
@@ -129,9 +146,8 @@ class AbstractCasesTest extends TestCase
/** /**
* This check the getter and setter related to the range of case number * This check the getter and setter related to the range of case number
* *
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setRangeCaseNumber() * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseNumberFrom()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getFromCaseNumber() * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseNumberTo()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getToCaseNumber()
* @test * @test
*/ */
public function it_return_set_get_range_case_number() public function it_return_set_get_range_case_number()
@@ -141,9 +157,10 @@ class AbstractCasesTest extends TestCase
'APP_NUMBER' => $case1->APP_NUMBER + 1 'APP_NUMBER' => $case1->APP_NUMBER + 1
]); ]);
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$absCases->setRangeCaseNumber($case1->APP_NUMBER, $case2->APP_NUMBER); $absCases->setCaseNumberFrom($case1->APP_NUMBER);
$from = $absCases->getFromCaseNumber(); $absCases->setCaseNumberTo($case2->APP_NUMBER);
$to = $absCases->getToCaseNumber(); $from = $absCases->getCaseNumberFrom();
$to = $absCases->getCaseNumberTo();
$this->assertEquals($case1->APP_NUMBER, $from); $this->assertEquals($case1->APP_NUMBER, $from);
$this->assertEquals($case2->APP_NUMBER, $to); $this->assertEquals($case2->APP_NUMBER, $to);
} }
@@ -174,12 +191,12 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_inbox_status() public function it_return_set_get_inbox_status()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$arguments = ['', 'ALL', 'READ', 'UNREAD']; $arguments = ['ALL', 'READ', 'UNREAD'];
$index = array_rand($arguments); $index = array_rand($arguments);
$absCases->setInboxStatus($arguments[$index]); $absCases->setInboxStatus($arguments[$index]);
$actual = $absCases->getInboxStatus(); $actual = $absCases->getInboxStatus();
if (empty($arguments[$index])) { if ($arguments[$index] === 'ALL') {
$this->assertEquals('ALL', $actual); $this->assertEmpty($actual);
} else { } else {
$this->assertEquals($arguments[$index], $actual); $this->assertEquals($arguments[$index], $actual);
} }
@@ -195,12 +212,12 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_participated_status() public function it_return_set_get_participated_status()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$arguments = ['', 'ALL', 'STARTED', 'COMPLETED']; $arguments = ['ALL', 'STARTED', 'COMPLETED'];
$index = array_rand($arguments); $index = array_rand($arguments);
$absCases->setParticipatedStatus($arguments[$index]); $absCases->setParticipatedStatus($arguments[$index]);
$actual = $absCases->getParticipatedStatus(); $actual = $absCases->getParticipatedStatus();
if (empty($arguments[$index])) { if ($arguments[$index] === 'ALL') {
$this->assertEquals('ALL', $actual); $this->assertEmpty($actual);
} else { } else {
$this->assertEquals($arguments[$index], $actual); $this->assertEquals($arguments[$index], $actual);
} }
@@ -216,12 +233,12 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_risk_status() public function it_return_set_get_risk_status()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$arguments = ['', 'ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE']; $arguments = ['ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE'];
$index = array_rand($arguments); $index = array_rand($arguments);
$absCases->setRiskStatus($arguments[$index]); $absCases->setRiskStatus($arguments[$index]);
$actual = $absCases->getRiskStatus(); $actual = $absCases->getRiskStatus();
if (empty($arguments[$index])) { if ($arguments[$index] === 'ALL') {
$this->assertEquals('ALL', $actual); $this->assertEmpty($actual);
} else { } else {
$this->assertEquals($arguments[$index], $actual); $this->assertEquals($arguments[$index], $actual);
} }
@@ -237,18 +254,36 @@ class AbstractCasesTest extends TestCase
public function it_return_set_get_case_status() public function it_return_set_get_case_status()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$arguments = ['', 'ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELLED', 'CANCELED']; $arguments = ['ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELED'];
$index = array_rand($arguments); $index = array_rand($arguments);
$absCases->setCaseStatus($arguments[$index]); $absCases->setCaseStatus($arguments[$index]);
$actual = $absCases->getCaseStatus(); $actual = $absCases->getCaseStatus();
if (empty($arguments[$index])) { $this->assertEquals($index, $actual);
$this->assertEquals('ALL', $actual); if ($arguments[$index] === 'ALL') {
$this->assertEquals(0, $actual);
} else { } else {
if ($arguments[$index] === AbstractCases::INCORRECT_CANCELED_STATUS) { $this->assertEquals($index, $actual);
$this->assertEquals(AbstractCases::CORRECT_CANCELED_STATUS, $actual); }
} else { }
$this->assertEquals($arguments[$index], $actual);
} /**
* This check the getter and setter related to the case statuses
*
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseStatuses()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getCaseStatuses()
* @test
*/
public function it_return_set_get_case_statuses()
{
$absCases = new AbstractCases();
$arguments = ['ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELED'];
$index = array_rand($arguments);
$absCases->setCaseStatuses([$arguments[$index]]);
$actual = $absCases->getCaseStatuses();
if ($arguments[$index] === 'ALL') {
$this->assertEquals([], $actual);
} else {
$this->assertEquals([$index], $actual);
} }
} }
@@ -286,32 +321,32 @@ class AbstractCasesTest extends TestCase
/** /**
* This check the getter and setter related to the newest than date * This check the getter and setter related to the newest than date
* *
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setNewestThan() * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setDelegateFrom()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getNewestThan() * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getDelegateFrom()
* @test * @test
*/ */
public function it_return_set_get_newest_than() public function it_return_set_get_newest_than()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$text = date('Y-m-d'); $text = date('Y-m-d');
$absCases->setNewestThan($text); $absCases->setDelegateFrom($text);
$actual = $absCases->getNewestThan(); $actual = $absCases->getDelegateFrom();
$this->assertEquals($text, $actual); $this->assertEquals($text, $actual);
} }
/** /**
* This check the getter and setter related to the oldest than date * This check the getter and setter related to the oldest than date
* *
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setOldestThan() * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setDelegateTo()
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getOldestThan() * @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getDelegateTo()
* @test * @test
*/ */
public function it_return_set_get_oldest_than() public function it_return_set_get_oldest_than()
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$text = date('Y-m-d'); $text = date('Y-m-d');
$absCases->setOldestThan($text); $absCases->setDelegateTo($text);
$actual = $absCases->getOldestThan(); $actual = $absCases->getDelegateTo();
$this->assertEquals($text, $actual); $this->assertEquals($text, $actual);
} }
@@ -383,52 +418,61 @@ class AbstractCasesTest extends TestCase
{ {
$absCases = new AbstractCases(); $absCases = new AbstractCases();
$properties = [ $properties = [
'category' => G::generateUniqueID(), // Tasks - Cases
'process' => rand(), 'process' => rand(),
'task' => rand(), 'task' => rand(),
'user' => rand(), 'user' => rand(),
'priority' => 1,
'caseNumber' => rand(), 'caseNumber' => rand(),
'caseNumberFrom' => rand(), 'caseTitle' => G::generateUniqueID(),
'caseNumberTo' => rand(), // Home - Search
'priorities' => ['N'],
'caseStatuses' => ['TO_DO','DRAFT'],
'filterCases'=> '1,3-5,8,10-15',
'delegationDateFrom' => date('Y-m-d'),
'delegationDateTo' => date('Y-m-d'),
// Home - My cases
'filter'=> 'ALL',
'caseStatus' => 'TO_DO',
'startCaseFrom' => date('Y-m-d'),
'startCaseTo' => date('Y-m-d'),
'finishCaseFrom' => date('Y-m-d'),
'finishCaseTo' => date('Y-m-d'),
// Other
'search' => G::generateUniqueID(), 'search' => G::generateUniqueID(),
'category' => G::generateUniqueID(),
'caseLink' => G::generateUniqueID(), 'caseLink' => G::generateUniqueID(),
'appUidCheck' => [G::generateUniqueID()], 'appUidCheck' => [G::generateUniqueID()],
'newestthan' => date('Y-m-d'), 'sort' => 'APP_NUMBER',
'oldestthan' => date('Y-m-d'),
'sort' => 'APP_DELEGATION.APP_NUMBER',
'dir' => 'DESC', 'dir' => 'DESC',
'paged' => true, 'paged' => true,
'start' => 5, 'start' => 5,
'limit' => 10, 'limit' => 10,
]; ];
$absCases->setProperties($properties); $absCases->setProperties($properties);
$actual = $absCases->getCategoryUid(); // Tasks - Cases
$this->assertEquals($properties['category'], $actual);
$actual = $absCases->getProcessId(); $actual = $absCases->getProcessId();
$this->assertEquals($properties['process'], $actual); $this->assertEquals($properties['process'], $actual);
$actual = $absCases->getTaskId(); $actual = $absCases->getTaskId();
$this->assertEquals($properties['task'], $actual); $this->assertEquals($properties['task'], $actual);
$actual = $absCases->getUserId(); $actual = $absCases->getUserId();
$this->assertEquals($properties['user'], $actual); $this->assertEquals($properties['user'], $actual);
$actual = $absCases->getPriority();
$this->assertEquals($properties['priority'], $actual);
$actual = $absCases->getCaseNumber(); $actual = $absCases->getCaseNumber();
$this->assertEquals($properties['caseNumber'], $actual); $this->assertEquals($properties['caseNumber'], $actual);
$actual = $absCases->getFromCaseNumber(); // Home - Search
$this->assertEquals($properties['caseNumberFrom'], $actual); $actual = $absCases->getPriorities();
$actual = $absCases->getToCaseNumber(); $this->assertNotEmpty($actual);
$this->assertEquals($properties['caseNumberTo'], $actual); // Home - My cases
$actual = $absCases->getParticipatedStatus();
$this->assertEmpty($actual);
// Other
$actual = $absCases->getValueToSearch(); $actual = $absCases->getValueToSearch();
$this->assertEquals($properties['search'], $actual); $this->assertEquals($properties['search'], $actual);
$actual = $absCases->getCategoryUid();
$this->assertEquals($properties['category'], $actual);
$actual = $absCases->getCaseUid(); $actual = $absCases->getCaseUid();
$this->assertEquals($properties['caseLink'], $actual); $this->assertEquals($properties['caseLink'], $actual);
$actual = $absCases->getCasesUids(); $actual = $absCases->getCasesUids();
$this->assertEquals($properties['appUidCheck'], $actual); $this->assertEquals($properties['appUidCheck'], $actual);
$actual = $absCases->getNewestThan();
$this->assertEquals($properties['newestthan'], $actual);
$actual = $absCases->getOldestThan();
$this->assertEquals($properties['oldestthan'], $actual);
$actual = $absCases->getOrderByColumn(); $actual = $absCases->getOrderByColumn();
$this->assertEquals($properties['sort'], $actual); $this->assertEquals($properties['sort'], $actual);
$actual = $absCases->getOrderDirection(); $actual = $absCases->getOrderDirection();

View File

@@ -18,6 +18,15 @@ class DraftTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
$this->markTestIncomplete();
}
/** /**
* This checks the counters is working properly in draft * This checks the counters is working properly in draft
* *
@@ -93,7 +102,7 @@ class DraftTest extends TestCase
// Get first page // Get first page
$draft = new Draft(); $draft = new Draft();
$draft->setUserId($user->USR_ID); $draft->setUserId($user->USR_ID);
$draft->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $draft->setOrderByColumn('APP_NUMBER');
$draft->setOffset(0); $draft->setOffset(0);
$draft->setLimit(25); $draft->setLimit(25);
$results = $draft->getData(); $results = $draft->getData();
@@ -143,7 +152,7 @@ class DraftTest extends TestCase
//Get the data ordered by APP_NUMBER //Get the data ordered by APP_NUMBER
$draft = new Draft(); $draft = new Draft();
$draft->setUserId($user->USR_ID); $draft->setUserId($user->USR_ID);
$draft->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $draft->setOrderByColumn('APP_NUMBER');
// Get first page, the minor case id // Get first page, the minor case id
$draft->setOrderDirection('ASC'); $draft->setOrderDirection('ASC');
$results = $draft->getData(); $results = $draft->getData();
@@ -359,7 +368,7 @@ class DraftTest extends TestCase
// Get first page // Get first page
$draft = new Draft(); $draft = new Draft();
$draft->setUserId($user->USR_ID); $draft->setUserId($user->USR_ID);
$draft->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $draft->setOrderByColumn('APP_NUMBER');
// Get first page, the specific case // Get first page, the specific case
$draft->setOrderDirection('ASC'); $draft->setOrderDirection('ASC');
$draft->setCaseUid($application->APP_UID); $draft->setCaseUid($application->APP_UID);
@@ -394,7 +403,7 @@ class DraftTest extends TestCase
// Get first page // Get first page
$draft = new Draft(); $draft = new Draft();
$draft->setUserId($user->USR_ID); $draft->setUserId($user->USR_ID);
$draft->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $draft->setOrderByColumn('APP_NUMBER');
// Get first page, the specific case // Get first page, the specific case
$draft->setOrderDirection('ASC'); $draft->setOrderDirection('ASC');
$draft->setCasesUids([$application->APP_UID]); $draft->setCasesUids([$application->APP_UID]);
@@ -431,7 +440,7 @@ class DraftTest extends TestCase
// Get first page // Get first page
$draft = new Draft(); $draft = new Draft();
$draft->setUserId($user->USR_ID); $draft->setUserId($user->USR_ID);
$draft->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $draft->setOrderByColumn('APP_NUMBER');
$draft->setProcessId($process->PRO_ID); $draft->setProcessId($process->PRO_ID);
// Get first page, the minor case title // Get first page, the minor case title
$draft->setOrderDirection('ASC'); $draft->setOrderDirection('ASC');

View File

@@ -52,82 +52,13 @@ class InboxTest extends TestCase
//Set the user ID //Set the user ID
$inbox->setUserId($user->USR_ID); $inbox->setUserId($user->USR_ID);
//Set OrderBYColumn value //Set OrderBYColumn value
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $inbox->setOrderByColumn('APP_NUMBER');
//Call to getData method //Call to getData method
$res = $inbox->getData(); $res = $inbox->getData();
//This assert that the expected numbers of results are returned //This assert that the expected numbers of results are returned
$this->assertEquals(10, count($res)); $this->assertEquals(10, count($res));
} }
/**
* It tests the getData method with Risk Filter
*
* @covers \ProcessMaker\BusinessModel\Cases\Inbox::getData()
* @test
*/
public function it_it_should_test_get_data_method_with_Risk_Filter()
{
//Create process
$process = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create a task
$task = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process->PRO_UID,
]);
//Create the register in delegation
factory(Delegation::class, 10)->create([
'TAS_ID' => $task->TAS_ID,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID,
'DEL_RISK_DATE' => '2019-06-07 12:30:58'
]);
//Create new Inbox object
$inbox = new Inbox();
//Set the user UID
$inbox->setUserUid($user->USR_UID);
//Set the user ID
$inbox->setUserId($user->USR_ID);
//Set OrderBYColumn value
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
//Set setRiskStatus value
$inbox->setRiskStatus('ON_TIME');
$res = $inbox->getData();
//This asserts that no cases are in ON_TIME status
$this->assertEmpty($res);
//Set setRiskStatus value
$inbox->setRiskStatus('OVERDUE');
//Call to getData method
$res = $inbox->getData();
//This asserts that there are cases in AT_RISK status
$this->assertNotEmpty($res);
//Set setRiskStatus value
$inbox->setRiskStatus('AT_RISK');
//Call to getData method
$res = $inbox->getData();
//This asserts that no cases are in AT_RISK status
$this->assertEmpty($res);
}
/** /**
* It tests the getData method with Category Filter * It tests the getData method with Category Filter
* *
@@ -169,7 +100,7 @@ class InboxTest extends TestCase
$inbox->setUserId($user->USR_ID); $inbox->setUserId($user->USR_ID);
//Set OrderBYColumn value //Set OrderBYColumn value
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $inbox->setOrderByColumn('APP_NUMBER');
//Set Category value //Set Category value
$inbox->setCategoryUid('248565910552bd7d6006458065223611'); $inbox->setCategoryUid('248565910552bd7d6006458065223611');
@@ -213,7 +144,7 @@ class InboxTest extends TestCase
$inbox = new Inbox(); $inbox = new Inbox();
$inbox->setUserUid($user->USR_UID); $inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID); $inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $inbox->setOrderByColumn('APP_NUMBER');
$inbox->setProcessId($process[1]->PRO_ID); $inbox->setProcessId($process[1]->PRO_ID);
$res = $inbox->getData(); $res = $inbox->getData();
$this->assertEmpty($res); $this->assertEmpty($res);
@@ -254,13 +185,13 @@ class InboxTest extends TestCase
$inbox = new Inbox(); $inbox = new Inbox();
$inbox->setUserUid($user->USR_UID); $inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID); $inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $inbox->setOrderByColumn('APP_NUMBER');
$inbox->setOrderDirection('DESC'); $inbox->setOrderDirection('DESC');
$res = $inbox->getData(); $res = $inbox->getData();
// This asserts the order is for APP_NUMBER from highest to lowest // This asserts the order is for APP_NUMBER from highest to lowest
$this->assertLessThan($res[0]['APP_NUMBER'], $res[1]['APP_NUMBER']); $this->assertLessThan($res[0]['APP_NUMBER'], $res[1]['APP_NUMBER']);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $inbox->setOrderByColumn('APP_NUMBER');
$inbox->setOrderDirection('ASC'); $inbox->setOrderDirection('ASC');
$res = $inbox->getData(); $res = $inbox->getData();
// This asserts the order is for APP_NUMBER from highest to lowest // This asserts the order is for APP_NUMBER from highest to lowest
@@ -552,7 +483,7 @@ class InboxTest extends TestCase
$inbox = new Inbox(); $inbox = new Inbox();
$inbox->setUserUid($user->USR_UID); $inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID); $inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $inbox->setOrderByColumn('APP_NUMBER');
$inbox->setOffset(5); $inbox->setOffset(5);
$inbox->setLimit(2); $inbox->setLimit(2);
$res = $inbox->getData(); $res = $inbox->getData();

View File

@@ -60,7 +60,7 @@ class ParticipatedTest extends TestCase
// Set the user ID // Set the user ID
$participated->setUserId($cases->USR_ID); $participated->setUserId($cases->USR_ID);
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Call to getData method // Call to getData method
$res = $participated->getData(); $res = $participated->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
@@ -86,7 +86,7 @@ class ParticipatedTest extends TestCase
// Set the process ID // Set the process ID
$participated->setProcessId($cases->PRO_ID); $participated->setProcessId($cases->PRO_ID);
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Call to getData method // Call to getData method
$res = $participated->getData(); $res = $participated->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
@@ -116,7 +116,7 @@ class ParticipatedTest extends TestCase
// Set the category // Set the category
$participated->setCategoryUid($process['PRO_CATEGORY']); $participated->setCategoryUid($process['PRO_CATEGORY']);
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Call to getData method // Call to getData method
$res = $participated->getData(); $res = $participated->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
@@ -142,7 +142,7 @@ class ParticipatedTest extends TestCase
// Set the case status // Set the case status
$participated->setCaseStatus('TO_DO'); $participated->setCaseStatus('TO_DO');
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Call to getData method // Call to getData method
$res = $participated->getData(); $res = $participated->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
@@ -168,7 +168,7 @@ class ParticipatedTest extends TestCase
// Set the filter STARTED // Set the filter STARTED
$participated->setParticipatedStatus('STARTED'); $participated->setParticipatedStatus('STARTED');
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Call to getData method // Call to getData method
$res = $participated->getData(); $res = $participated->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
@@ -194,7 +194,7 @@ class ParticipatedTest extends TestCase
// Set the filter COMPLETED // Set the filter COMPLETED
$participated->setParticipatedStatus('COMPLETED'); $participated->setParticipatedStatus('COMPLETED');
// Set OrderBYColumn value // Set OrderBYColumn value
$participated->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $participated->setOrderByColumn('APP_NUMBER');
// Call to getData method // Call to getData method
$res = $participated->getData(); $res = $participated->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned

View File

@@ -470,7 +470,7 @@ class PausedTest extends TestCase
$paused->setUserId($user->USR_ID); $paused->setUserId($user->USR_ID);
//Set OrderBYColumn value //Set OrderBYColumn value
$paused->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $paused->setOrderByColumn('APP_NUMBER');
//Set Order Direction value //Set Order Direction value
$paused->setOrderDirection('DESC'); $paused->setOrderDirection('DESC');
@@ -598,7 +598,7 @@ class PausedTest extends TestCase
$paused->setUserId($user->USR_ID); $paused->setUserId($user->USR_ID);
//Set OrderBYColumn value //Set OrderBYColumn value
$paused->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $paused->setOrderByColumn('APP_NUMBER');
//Set offset and limit values //Set offset and limit values
$paused->setOffset(0); $paused->setOffset(0);

View File

@@ -1,128 +0,0 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use ProcessMaker\BusinessModel\Cases\Reassign;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use Tests\TestCase;
/**
* @coversDefaultClass \ProcessMaker\BusinessModel\Cases\Reassign
*/
class ReassignTest extends TestCase
{
use DatabaseTransactions;
/**
* It tests the getData method without filters
*
* @covers \ProcessMaker\BusinessModel\Cases\Reassign::getData()
* @test
*/
public function it_should_test_get_data_method_without_filters()
{
$cases = 25;
factory(Delegation::class, $cases)->states('foreign_keys')->create();
//Create new Reassign object
$reassign = new Reassign();
//Set OrderBYColumn value
$reassign->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
//Call to getData method
$res = $reassign->getData();
//This assert that the expected numbers of results are returned
$this->assertEquals($cases, count($res));
}
/**
* It tests the getData method with user filter
*
* @covers \ProcessMaker\BusinessModel\Cases\Reassign::getData()
* @test
*/
public function it_should_test_get_data_method_with_user_filter()
{
// Create user
$user = factory(User::class)->create();
// Create delegation related to the specific user
factory(Delegation::class)->states('foreign_keys')->create([
'USR_ID' => $user->USR_ID,
'USR_UID' => $user->USR_UID,
]);
// Create other delegations
$cases = 5;
factory(Delegation::class, $cases)->states('foreign_keys')->create();
//Create new Reassign object
$reassign = new Reassign();
//Set the user UID
$reassign->setUserUid($user->USR_UID);
//Set the user ID
$reassign->setUserId($user->USR_ID);
//Set OrderBYColumn value
$reassign->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
//Call to getData method
$res = $reassign->getData();
//This assert that the expected numbers of results are returned
$this->assertEquals(1, count($res));
}
/**
* It tests the getData method with process filter
*
* @covers \ProcessMaker\BusinessModel\Cases\Reassign::getData()
* @test
*/
public function it_should_test_get_data_method_with_process_filter()
{
// Create user
$process = factory(Process::class)->create();
// Create delegation related to the specific user
factory(Delegation::class)->states('foreign_keys')->create([
'PRO_ID' => $process->PRO_ID,
'PRO_UID' => $process->PRO_UID,
]);
// Create other delegations
$cases = 5;
factory(Delegation::class, $cases)->states('foreign_keys')->create();
//Create new Reassign object
$reassign = new Reassign();
//Set the process
$reassign->setProcessId($process->PRO_ID);
$reassign->setProcessUid($process->PRO_UID);
//Set OrderBYColumn value
$reassign->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
//Call to getData method
$res = $reassign->getData();
//This assert that the expected numbers of results are returned
$this->assertEquals(1, count($res));
}
/**
* It tests the getCounter method
*
* @covers \ProcessMaker\BusinessModel\Cases\Reassign::getCounter()
* @test
*/
public function it_should_test_the_counter_for_reassign()
{
// Create user
$user = factory(User::class)->create();
$cases = 25;
factory(Delegation::class, $cases)->states('foreign_keys')->create([
'USR_ID' => $user->USR_ID,
'USR_UID' => $user->USR_UID,
]);
//Create the Inbox object
$reassign = new Reassign();
//Set the user UID
$reassign->setUserUid($user->USR_UID);
//Set the user ID
$reassign->setUserId($user->USR_ID);
$res = $reassign->getCounter();
//Assert the result of getCounter method
$this->assertEquals($cases, $res);
}
}

View File

@@ -70,7 +70,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setCaseNumber($cases[0]->APP_NUMBER); $search->setCaseNumber($cases[0]->APP_NUMBER);
// Set order by column value // Set order by column value
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $search->setOrderByColumn('APP_NUMBER');
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
$this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']); $this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']);
@@ -88,9 +88,9 @@ class SearchTest extends TestCase
$cases = $this->createSearch(); $cases = $this->createSearch();
// Create new Search object // Create new Search object
$search = new Search(); $search = new Search();
$search->setPriority($cases[0]->DEL_PRIORITY); $search->setPriority('N');
// Set order by column value // Set order by column value
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $search->setOrderByColumn('APP_NUMBER');
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
@@ -110,7 +110,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setProcessId($cases[0]->PRO_ID); $search->setProcessId($cases[0]->PRO_ID);
// Set order by column value // Set order by column value
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $search->setOrderByColumn('APP_NUMBER');
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
@@ -130,7 +130,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setTaskId($cases[0]->TAS_ID); $search->setTaskId($cases[0]->TAS_ID);
// Set order by column value // Set order by column value
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $search->setOrderByColumn('APP_NUMBER');
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
@@ -150,7 +150,7 @@ class SearchTest extends TestCase
$search = new Search(); $search = new Search();
$search->setUserId($cases[0]->USR_ID); $search->setUserId($cases[0]->USR_ID);
// Set order by column value // Set order by column value
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $search->setOrderByColumn('APP_NUMBER');
$result = $search->getData(); $result = $search->getData();
// This assert that the expected numbers of results are returned // This assert that the expected numbers of results are returned
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
@@ -169,7 +169,7 @@ class SearchTest extends TestCase
// Create new Search object // Create new Search object
$search = new Search(); $search = new Search();
// Set order by column value // Set order by column value
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $search->setOrderByColumn('APP_NUMBER');
$total = $search->getCounter(); $total = $search->getCounter();
$this->assertEquals(count($cases), $total); $this->assertEquals(count($cases), $total);
} }

View File

@@ -510,7 +510,7 @@ class UnassignedTest extends TestCase
// Get first page // Get first page
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $unassigned->setOrderByColumn('APP_NUMBER');
$unassigned->setOrderDirection('DESC'); $unassigned->setOrderDirection('DESC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
$unassigned->setLimit(25); $unassigned->setLimit(25);
@@ -600,7 +600,7 @@ class UnassignedTest extends TestCase
// Get first page // Get first page
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $unassigned->setOrderByColumn('APP_NUMBER');
$unassigned->setOrderDirection('DESC'); $unassigned->setOrderDirection('DESC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
$unassigned->setLimit(25); $unassigned->setLimit(25);
@@ -688,7 +688,7 @@ class UnassignedTest extends TestCase
// Get first page // Get first page
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $unassigned->setOrderByColumn('APP_NUMBER');
$unassigned->setOrderDirection('DESC'); $unassigned->setOrderDirection('DESC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
$unassigned->setLimit(25); $unassigned->setLimit(25);
@@ -787,7 +787,7 @@ class UnassignedTest extends TestCase
// Get first page // Get first page
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $unassigned->setOrderByColumn('APP_NUMBER');
$unassigned->setOrderDirection('DESC'); $unassigned->setOrderDirection('DESC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
$unassigned->setLimit(25); $unassigned->setLimit(25);
@@ -856,7 +856,7 @@ class UnassignedTest extends TestCase
// Get first page, the minor case id // Get first page, the minor case id
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$unassigned->setOrderByColumn('APP_DELEGATION.APP_NUMBER'); $unassigned->setOrderByColumn('APP_NUMBER');
$unassigned->setOrderDirection('ASC'); $unassigned->setOrderDirection('ASC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
$unassigned->setLimit(25); $unassigned->setLimit(25);
@@ -1207,7 +1207,7 @@ class UnassignedTest extends TestCase
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$dateToFilter = date('Y-m-d', strtotime('+1 year')); $dateToFilter = date('Y-m-d', strtotime('+1 year'));
$unassigned->setNewestThan($dateToFilter); $unassigned->setDelegateFrom($dateToFilter);
$unassigned->setOrderByColumn('DEL_DELEGATE_DATE'); $unassigned->setOrderByColumn('DEL_DELEGATE_DATE');
$unassigned->setOrderDirection('ASC'); $unassigned->setOrderDirection('ASC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
@@ -1216,7 +1216,7 @@ class UnassignedTest extends TestCase
$results = $unassigned->getData(); $results = $unassigned->getData();
$this->assertGreaterThan($results[0]['DEL_DELEGATE_DATE'], $results[1]['DEL_DELEGATE_DATE']); $this->assertGreaterThan($results[0]['DEL_DELEGATE_DATE'], $results[1]['DEL_DELEGATE_DATE']);
// Get the newest than (>=) delegate date // Get the newest than (>=) delegate date
$unassigned->setNewestThan($dateToFilter); $unassigned->setDelegateFrom($dateToFilter);
$unassigned->setOrderDirection('DESC'); $unassigned->setOrderDirection('DESC');
$results = $unassigned->getData(); $results = $unassigned->getData();
$this->assertLessThan($results[0]['DEL_DELEGATE_DATE'], $results[1]['DEL_DELEGATE_DATE']); $this->assertLessThan($results[0]['DEL_DELEGATE_DATE'], $results[1]['DEL_DELEGATE_DATE']);
@@ -1265,7 +1265,7 @@ class UnassignedTest extends TestCase
$unassigned = new Unassigned; $unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID); $unassigned->setUserUid($user->USR_UID);
$dateToFilter = date('Y-m-d', strtotime('+1 year')); $dateToFilter = date('Y-m-d', strtotime('+1 year'));
$unassigned->setOldestThan($dateToFilter); $unassigned->setDelegateTo($dateToFilter);
$unassigned->setOrderByColumn('DEL_DELEGATE_DATE'); $unassigned->setOrderByColumn('DEL_DELEGATE_DATE');
$unassigned->setOrderDirection('ASC'); $unassigned->setOrderDirection('ASC');
$unassigned->setOffset(0); $unassigned->setOffset(0);
@@ -1329,66 +1329,6 @@ class UnassignedTest extends TestCase
$this->assertEquals($application->APP_UID, $results[0]['APP_UID']); $this->assertEquals($application->APP_UID, $results[0]['APP_UID']);
} }
/**
* This ensures searching specific cases and review the page in self-service-user-assigned
*
* @covers \ProcessMaker\BusinessModel\Cases\Unassigned::getData()
* @test
*/
public function it_should_search_self_service_user_assigned_specific_cases_uid_array()
{
//Create user
$user = factory(User::class)->create();
for ($i = 1; $i <= 2; $i++) {
//Create process
$process = factory(Process::class)->create();
//Create application
$application = factory(Application::class)->create([
'APP_STATUS_ID' => 2
]);
//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)->create([
'APP_UID' => $application->APP_UID,
'APP_NUMBER' => $application->APP_NUMBER,
'TAS_ID' => $task->TAS_ID,
'PRO_ID' => $process->PRO_ID,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_ID' => 0
]);
}
$unassigned = new Unassigned;
$unassigned->setUserUid($user->USR_UID);
$unassigned->setCasesUids([$application->APP_UID]);
$unassigned->setOrderByColumn('APP_DELEGATION.APP_UID');
$unassigned->setOrderDirection('ASC');
$unassigned->setOffset(0);
$unassigned->setLimit(25);
// Get the specific cases uid's
$results = $unassigned->getData();
$this->assertCount(1, $results);
// Get the specific cases uid's
$unassigned->setCasesUids([$application->APP_UID]);
$results = $unassigned->getData();
$this->assertEquals($application->APP_UID, $results[0]['APP_UID']);
// Get the specific cases uid's
$unassigned->setCasesUids([$application->APP_UID]);
$results = $unassigned->getData();
$this->assertEquals($application->APP_UID, $results[0]['APP_UID']);
}
/** /**
* This ensures searching specific process and review the page in self-service-user-assigned * This ensures searching specific process and review the page in self-service-user-assigned
* *

View File

@@ -81,7 +81,7 @@ class DelegationTest extends TestCase
public function it_return_scope_case_in_progress() public function it_return_scope_case_in_progress()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->caseInProgress()->get()); $this->assertCount(1, $table->joinApplication()->caseInProgress()->get());
} }
/** /**
@@ -97,7 +97,7 @@ class DelegationTest extends TestCase
'APP_NUMBER' => $application->APP_NUMBER, 'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID, 'APP_UID' => $application->APP_UID,
]); ]);
$this->assertCount(1, $table->caseCompleted()->get()); $this->assertCount(1, $table->joinApplication()->caseCompleted()->get());
} }
/** /**
@@ -121,7 +121,7 @@ class DelegationTest extends TestCase
public function it_return_scope_delegate_date_to() public function it_return_scope_delegate_date_to()
{ {
$table = factory(Delegation::class)->states('foreign_keys')->create(); $table = factory(Delegation::class)->states('foreign_keys')->create();
$this->assertCount(1, $table->delegateDateFrom($table->DEL_DELEGATE_DATE)->get()); $this->assertCount(1, $table->delegateDateTo($table->DEL_DELEGATE_DATE)->get());
} }
/** /**

View File

@@ -6,18 +6,20 @@ use Datetime;
use Exception; use Exception;
use ProcessMaker\BusinessModel\Interfaces\CasesInterface; use ProcessMaker\BusinessModel\Interfaces\CasesInterface;
use ProcessMaker\BusinessModel\Validator; use ProcessMaker\BusinessModel\Validator;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
class AbstractCases implements CasesInterface class AbstractCases implements CasesInterface
{ {
// Constants for validate values // Constants for validate values
const INBOX_STATUSES = ['', 'ALL', 'READ', 'UNREAD']; const INBOX_STATUSES = ['ALL', 'READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['', 'ALL', 'STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING']; const PARTICIPATED_STATUSES = ['ALL', 'STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['', 'ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE']; const RISK_STATUSES = ['ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE'];
const CASE_STATUSES = ['', 'ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELLED', 'CANCELED']; const CASE_STATUSES = [0 => 'ALL', 1 => 'DRAFT', 2 => 'TO_DO', 3 => 'COMPLETED', 4 => 'CANCELED'];
const ORDER_DIRECTIONS = ['DESC', 'ASC']; const ORDER_DIRECTIONS = ['DESC', 'ASC'];
const CORRECT_CANCELED_STATUS = 'CANCELED'; const CORRECT_CANCELED_STATUS = 'CANCELED';
const INCORRECT_CANCELED_STATUS = 'CANCELLED'; const INCORRECT_CANCELED_STATUS = 'CANCELLED';
const PRIORITIES = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH']; const PRIORITIES = [0 => 'ALL', 1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
const TASK_COLORS = [1 => 'green', 2 => 'red', 3 => 'orange', 4 => 'blue', 5 => 'gray']; const TASK_COLORS = [1 => 'green', 2 => 'red', 3 => 'orange', 4 => 'blue', 5 => 'gray'];
const COLOR_OVERDUE = 1; const COLOR_OVERDUE = 1;
const COLOR_ON_TIME = 2; const COLOR_ON_TIME = 2;
@@ -58,33 +60,62 @@ class AbstractCases implements CasesInterface
// Filter by specific priority // Filter by specific priority
private $priority = 0; private $priority = 0;
// Filter by specific priorities
private $priorities = [];
// Filter by case status, know as "$filterStatus" in the old "participated last" class // Filter by case status, know as "$filterStatus" in the old "participated last" class
private $caseStatus = ''; private $caseStatus = '';
// Filter by case statuses
private $caseStatuses = [1, 2, 3, 4];
// Filter by a specific case, know as "$caseLink" in the old lists classes // Filter by a specific case, know as "$caseLink" in the old lists classes
private $caseUid = ''; private $caseUid = '';
// Filter by a specific case using case number // Filter by a specific case using case number
private $caseNumber = 0; private $caseNumber = 0;
// Filter by a specific range of case number // Filter by specific cases using the case numbers like [1,4,8]
private $fromCaseNumber = 0; private $casesNumbers = [];
private $toCaseNumber = 0;
// Filter by only one range of case number
private $caseNumberFrom = 0;
private $caseNumberTo = 0;
// Filter more than one range of case number
private $rangeCasesFromTo = [];
// Filter by a specific cases like 1,3-5,8,10-15
private $filterCases = '';
// Filter by a specific case title
private $caseTitle = '';
// Filter by specific cases, know as "$appUidCheck" in the old lists classes // Filter by specific cases, know as "$appUidCheck" in the old lists classes
private $casesUids = []; private $casesUids = [];
// Filter by specific cases using the case numbers // Filter range related to the start case date
private $casesNumbers = []; private $startCaseFrom = '';
private $startCaseTo = '';
// Filter recent cases starting by a specific date, know as "newestthan" in the old lists classes // Filter range related to the finish case date
private $newestThan = ''; private $finishCaseFrom = '';
private $finishCaseTo = '';
// Filter old cases ending by a specific date, know as "oldestthan" in the old lists classes // Filter range related to the delegate date
private $oldestThan = ''; private $delegateFrom = '';
private $delegateTo = '';
// Filter range related to the finish date
private $finishFrom = '';
private $finishTo = '';
// Filter range related to the due date
private $dueFrom = '';
private $dueTo = '';
// Column by which the results will be sorted, know as "$sort" in the old lists classes // Column by which the results will be sorted, know as "$sort" in the old lists classes
private $orderByColumn = 'APP_DELEGATION.APP_NUMBER'; private $orderByColumn = 'APP_NUMBER';
// Sorts the data in descending or ascending order, know as "$dir" in the old lists classes // Sorts the data in descending or ascending order, know as "$dir" in the old lists classes
private $orderDirection = 'DESC'; private $orderDirection = 'DESC';
@@ -96,7 +127,7 @@ class AbstractCases implements CasesInterface
private $offset = 0; private $offset = 0;
// Number of rows to return // Number of rows to return
private $limit = 25; private $limit = 15;
/** /**
* Set Category Uid value * Set Category Uid value
@@ -290,9 +321,9 @@ class AbstractCases implements CasesInterface
throw new Exception("Participated status '{$participatedStatus}' is not valid."); throw new Exception("Participated status '{$participatedStatus}' is not valid.");
} }
// If empty string is sent, use value 'ALL' // If empty string will not apply the filter
if ($participatedStatus === '') { if ($participatedStatus === 'ALL') {
$participatedStatus = 'ALL'; $participatedStatus = '';
} }
$this->participatedStatus = $participatedStatus; $this->participatedStatus = $participatedStatus;
@@ -325,9 +356,9 @@ class AbstractCases implements CasesInterface
throw new Exception("Risk status '{$riskStatus}' is not valid."); throw new Exception("Risk status '{$riskStatus}' is not valid.");
} }
// If empty string is sent, use value 'ALL' // If empty string will not apply the filter
if ($riskStatus === '') { if ($riskStatus === 'ALL') {
$riskStatus = 'ALL'; $riskStatus = '';
} }
$this->riskStatus = $riskStatus; $this->riskStatus = $riskStatus;
@@ -346,17 +377,16 @@ class AbstractCases implements CasesInterface
/** /**
* Set priority value * Set priority value
* *
* @param int $priority * @param string $priority
* *
* @throws Exception * @throws Exception
*/ */
public function setPriority(int $priority) public function setPriority(string $priority)
{ {
// Validate the priority value // Validate the priority value
if (!empty($priority)) { if (!empty($priority)) {
if (!empty(self::PRIORITIES[$priority])) { $priorityCode = array_search($priority, self::PRIORITIES);
$priorityCode = $priority; if (empty($priorityCode) && $priorityCode !== 0) {
} else {
throw new Exception("Priority value {$priority} is not valid."); throw new Exception("Priority value {$priority} is not valid.");
} }
} else { } else {
@@ -378,45 +408,109 @@ class AbstractCases implements CasesInterface
} }
/** /**
* Set Case status * Set priorities
* *
* @param string $caseStatus * @param array $priorities
* *
* @throws Exception * @throws Exception
*/ */
public function setCaseStatus(string $caseStatus) public function setPriorities(array $priorities)
{ {
// Convert the value to upper case $prioritiesCode = [];
$caseStatus = strtoupper($caseStatus); foreach ($priorities as $priority) {
// Validate the priority value
// Validate the case status $priorityCode = array_search($priority, self::PRIORITIES);
if (!in_array($caseStatus, self::CASE_STATUSES)) { if (empty($priorityCode) && $priorityCode !== 0) {
throw new Exception("Case status '{$caseStatus}' is not valid."); throw new Exception("Priority value {$priority} is not valid.");
} else {
array_push($prioritiesCode, $priorityCode);
}
} }
$this->priorities = $prioritiesCode;
}
// If empty string is sent, use value 'ALL' /**
if ($caseStatus === '') { * Get priorities
$caseStatus = 'ALL'; *
} * @return array
*/
public function getPriorities()
{
return $this->priorities;
}
/**
* Set Case status
*
* @param string $status
*
* @throws Exception
*/
public function setCaseStatus(string $status)
{
// Fix the canceled status, this is a legacy code error // Fix the canceled status, this is a legacy code error
if ($caseStatus === self::INCORRECT_CANCELED_STATUS) { if ($status === self::INCORRECT_CANCELED_STATUS) {
$caseStatus = self::CORRECT_CANCELED_STATUS; $status = self::CORRECT_CANCELED_STATUS;
} }
$statusCode = 0;
$this->caseStatus = $caseStatus; // Validate the status value
if (!empty($status)) {
$statusCode = array_search($status, self::CASE_STATUSES);
if (empty($statusCode) && $statusCode !== 0) {
throw new Exception("Case status '{$status}' is not valid.");
}
}
$this->caseStatus = $statusCode;
} }
/** /**
* Get Case Status * Get Case Status
* *
* @return string * @return int
*/ */
public function getCaseStatus() public function getCaseStatus()
{ {
return $this->caseStatus; return $this->caseStatus;
} }
/**
* Set Case statuses
*
* @param array $statuses
*
* @throws Exception
*/
public function setCaseStatuses(array $statuses)
{
$statusCodes = [];
foreach ($statuses as $status) {
// Fix the canceled status, this is a legacy code error
if ($status === self::INCORRECT_CANCELED_STATUS) {
$status = self::CORRECT_CANCELED_STATUS;
}
// Validate the status value
if (!empty($status)) {
$statusCode = array_search($status, self::CASE_STATUSES);
if (empty($statusCode) && $statusCode !== 0) {
throw new Exception("Case status '{$status}' is not valid.");
} else {
array_push($statusCodes, $statusCode);
}
}
}
$this->caseStatuses = $statusCodes;
}
/**
* Get Case Statuses
*
* @return array
*/
public function getCaseStatuses()
{
return $this->caseStatuses;
}
/** /**
* Set Case Uid * Set Case Uid
* *
@@ -458,15 +552,13 @@ class AbstractCases implements CasesInterface
} }
/** /**
* Set range of Case Number * Set range of case number from
* *
* @param int $from * @param int $from
* @param int $to
*/ */
public function setRangeCaseNumber(int $from, int $to) public function setCaseNumberFrom(int $from)
{ {
$this->fromCaseNumber = $from; $this->caseNumberFrom = $from;
$this->toCaseNumber = $to;
} }
/** /**
@@ -474,9 +566,19 @@ class AbstractCases implements CasesInterface
* *
* @return int * @return int
*/ */
public function getFromCaseNumber() public function getCaseNumberFrom()
{ {
return $this->fromCaseNumber; return $this->caseNumberFrom;
}
/**
* Set range of case number to
*
* @param int $to
*/
public function setCaseNumberTo(int $to)
{
$this->caseNumberTo = $to;
} }
/** /**
@@ -484,9 +586,82 @@ class AbstractCases implements CasesInterface
* *
* @return int * @return int
*/ */
public function getToCaseNumber() public function getCaseNumberTo()
{ {
return $this->toCaseNumber; return $this->caseNumberTo;
}
/**
* Set more than one range of cases
*
* @param array $rangeCases
*/
public function setRangeCasesFromTo(array $rangeCases)
{
$this->rangeCasesFromTo = $rangeCases;
}
/**
* Get more than one range of cases
*
* @return array
*/
public function getRangeCasesFromTo()
{
return $this->rangeCasesFromTo;
}
/**
* Set filter of cases like '1,3-5,8,10-15'
*
* @param string $filterCases
*/
public function setFilterCases(string $filterCases)
{
$this->filterCases = $filterCases;
// Review the cases defined in the filter
$rangeOfCases = explode(",", $filterCases);
$specificCases = [];
$rangeCases = [];
foreach ($rangeOfCases as $cases) {
if(is_numeric($cases)) {
array_push($specificCases,$cases);
} else {
array_push($rangeCases,$cases);
}
}
$this->setCasesNumbers($specificCases);
$this->setRangeCasesFromTo($rangeCases);
}
/**
* Get filter of cases
*
* @return string
*/
public function getFilterCases()
{
return $this->filterCases;
}
/**
* Set Case Title
*
* @param string $caseTitle
*/
public function setCaseTitle(string $caseTitle)
{
$this->caseTitle = $caseTitle;
}
/**
* Get Case Title
*
* @return string
*/
public function getCaseTitle()
{
return $this->caseTitle;
} }
/** /**
@@ -530,18 +705,118 @@ class AbstractCases implements CasesInterface
} }
/** /**
* Set Newest Than value * Set start case from
* *
* @param string $newestThan * @param string $from
* *
* @throws Exception * @throws Exception
*/ */
public function setNewestThan(string $newestThan) public function setStartCaseFrom(string $from)
{ {
if (!Validator::isDate($newestThan, 'Y-m-d')) { if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$newestThan}' is not a valid date."); throw new Exception("Value '{$from}' is not a valid date.");
} }
$this->newestThan = $newestThan; $this->startCaseFrom = $from;
}
/**
* Get start case from
*
* @return string
*/
public function getStartCaseFrom()
{
return $this->startCaseFrom;
}
/**
* Set start case to
*
* @param string $to
*
* @throws Exception
*/
public function setStartCaseTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->startCaseTo = $to;
}
/**
* Get start case to
*
* @return string
*/
public function getStartCaseTo()
{
return $this->startCaseTo;
}
/**
* Set finish case from
*
* @param string $from
*
* @throws Exception
*/
public function setFinishCaseFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->finishCaseFrom = $from;
}
/**
* Get start case from
*
* @return string
*/
public function getFinishCaseFrom()
{
return $this->finishCaseFrom;
}
/**
* Set start case to
*
* @param string $to
*
* @throws Exception
*/
public function setFinishCaseTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->finishCaseTo = $to;
}
/**
* Get start case to
*
* @return string
*/
public function getFinishCaseTo()
{
return $this->finishCaseTo;
}
/**
* Set Newest Than value
*
* @param string $delegateFrom
*
* @throws Exception
*/
public function setDelegateFrom(string $delegateFrom)
{
if (!Validator::isDate($delegateFrom, 'Y-m-d')) {
throw new Exception("Value '{$delegateFrom}' is not a valid date.");
}
$this->delegateFrom = $delegateFrom;
} }
/** /**
@@ -549,24 +824,24 @@ class AbstractCases implements CasesInterface
* *
* @return string * @return string
*/ */
public function getNewestThan() public function getDelegateFrom()
{ {
return $this->newestThan; return $this->delegateFrom;
} }
/** /**
* Set Oldest Than value * Set Oldest Than value
* *
* @param string $oldestThan * @param string $delegateTo
* *
* @throws Exception * @throws Exception
*/ */
public function setOldestThan(string $oldestThan) public function setDelegateTo(string $delegateTo)
{ {
if (!Validator::isDate($oldestThan, 'Y-m-d')) { if (!Validator::isDate($delegateTo, 'Y-m-d')) {
throw new Exception("Value '{$oldestThan}' is not a valid date."); throw new Exception("Value '{$delegateTo}' is not a valid date.");
} }
$this->oldestThan = $oldestThan; $this->delegateTo = $delegateTo;
} }
/** /**
@@ -574,11 +849,112 @@ class AbstractCases implements CasesInterface
* *
* @return string * @return string
*/ */
public function getOldestThan() public function getDelegateTo()
{ {
return $this->oldestThan; return $this->delegateTo;
} }
/**
* Set finish date value
*
* @param string $from
*
* @throws Exception
*/
public function setFinishFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->finishFrom = $from;
}
/**
* Get finish date value
*
* @return string
*/
public function getFinishFrom()
{
return $this->finishFrom;
}
/**
* Set finish date value
*
* @param string $to
*
* @throws Exception
*/
public function setFinishTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->finishTo = $to;
}
/**
* Get finish date value
*
* @return string
*/
public function getFinishTo()
{
return $this->finishTo;
}
/**
* Set due date from
*
* @param string $dueFrom
*
* @throws Exception
*/
public function setDueFrom(string $dueFrom)
{
if (!Validator::isDate($dueFrom, 'Y-m-d')) {
throw new Exception("Value '{$dueFrom}' is not a valid date.");
}
$this->dueFrom = $dueFrom;
}
/**
* Get due date from
*
* @return string
*/
public function getDueFrom()
{
return $this->dueFrom;
}
/**
* Set due date to
*
* @param string $dueTo
*
* @throws Exception
*/
public function setDueTo(string $dueTo)
{
if (!Validator::isDate($dueTo, 'Y-m-d')) {
throw new Exception("Value '{$dueTo}' is not a valid date.");
}
$this->dueTo = $dueTo;
}
/**
* Get due date to
*
* @return string
*/
public function getDueTo()
{
return $this->dueTo;
}
/** /**
* Set order by column * Set order by column
* *
@@ -721,6 +1097,40 @@ class AbstractCases implements CasesInterface
return $taskColor; return $taskColor;
} }
/**
* Get task color according the due date
*
* @param string $pending
*
* @return int
*/
public function prepareTaskPending($pending)
{
$taskPending = json_decode($pending, true);
$result = [];
$i = 0;
foreach ($taskPending as $thread) {
foreach ($thread as $key => $row) {
if($key === 'tas_id') {
$result[$i][$key] = $row;
$result[$i]['tas_title'] = (!empty($row)) ? Task::where('TAS_ID', $row)->first()->TAS_TITLE : '';
}
if($key === 'user_id') {
$result[$i][$key] = $row;
}
if($key === 'due_date') {
$result[$i][$key] = $row;
// Get task color label
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($row) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
}
}
$i ++;
}
return $result;
}
/** /**
* Set all properties * Set all properties
* *
@@ -744,33 +1154,67 @@ class AbstractCases implements CasesInterface
if (!empty($properties['user'])) { if (!empty($properties['user'])) {
$this->setUserId($properties['user']); $this->setUserId($properties['user']);
} }
// Filter by priority // Filter by one case number
if (!empty($properties['priority'])) {
$this->setPriority($properties['priority']);
}
// Filter by case number
if (!empty($properties['caseNumber'])) { if (!empty($properties['caseNumber'])) {
$this->setCaseNumber($properties['caseNumber']); $this->setCaseNumber($properties['caseNumber']);
} }
// Filter by range of case number // Filter by case title
if (!empty($properties['caseNumberFrom']) && !empty($properties['caseNumberTo'])) { if (!empty($properties['caseTitle'])) {
$this->setRangeCaseNumber($properties['caseNumberFrom'], $properties['caseNumberTo']); $this->setCaseTitle($properties['caseTitle']);
}
// Filter by search
if (!empty($properties['search'])) {
$this->setValueToSearch($properties['search']);
} }
/** Apply filters related to MY CASES */
// My cases filter: started, in-progress, completed, supervising // My cases filter: started, in-progress, completed, supervising
if (!empty($properties['filter']) && get_class($this) === MyCases::class) { if (!empty($properties['filter']) && get_class($this) === Participated::class) {
$this->setParticipatedStatus($properties['filter']); $this->setParticipatedStatus($properties['filter']);
} }
// Filter by case status // Filter by one case status
if (!empty($properties['filterStatus']) && get_class($this) === MyCases::class) { if (!empty($properties['caseStatus']) && get_class($this) === Participated::class) {
$this->setCaseStatus($properties['filterStatus']); $this->setCaseStatus($properties['caseStatus']);
} }
// Filter by case status // Filter date related to started date from
if (!empty($properties['filterStatus']) && get_class($this) === Search::class) { if (!empty($properties['startCaseFrom'] && (get_class($this) === Participated::class || get_class($this) === Supervising::class))) {
$this->setCaseStatus($properties['filterStatus']); $this->setStartCaseFrom($properties['startCaseFrom']);
}
// Filter date related to started date to
if (!empty($properties['startCaseTo']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
$this->setStartCaseTo($properties['startCaseTo']);
}
// Filter date related to finish date from
if (!empty($properties['finishCaseFrom']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
$this->setFinishCaseFrom($properties['finishCaseFrom']);
}
// Filter date related to finish date to
if (!empty($properties['finishCaseTo']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
$this->setFinishCaseTo($properties['finishCaseTo']);
}
/** Apply filters related to SEARCH */
// Add a filter with specific cases or range of cases like '1, 3-5, 8, 10-15'
if (!empty($properties['filterCases']) && get_class($this) === Search::class) {
$this->setFilterCases($properties['filterCases']);
}
// Filter by more than one case statuses like ['DRAFT', 'TO_DO']
if (!empty($properties['caseStatuses']) && get_class($this) === Search::class) {
$this->setCaseStatuses($properties['caseStatuses']);
}
// Filter by more than one priorities like ['VL', 'L', 'N']
if (!empty($properties['priorities']) && get_class($this) === Search::class) {
$this->setProperties($properties['priorities']);
}
// Filter date newest related to delegation/started date
if (!empty($properties['delegationDateFrom'] && get_class($this) === Search::class)) {
$this->setDelegateFrom($properties['delegationDateFrom']);
}
// Filter date oldest related to delegation/started date
if (!empty($properties['delegationDateTo']) && get_class($this) === Search::class) {
$this->setDelegateTo($properties['delegationDateTo']);
}
// Filter date newest related to due date
if (!empty($properties['dueDateFrom']) && get_class($this) === Search::class) {
$this->setDueFrom($properties['dueDateFrom']);
}
// Filter date oldest related to due date
if (!empty($properties['dueDateTo']) && get_class($this) === Search::class) {
$this->setDueTo($properties['dueDateTo']);
} }
// Filter by case uid // Filter by case uid
if (!empty($properties['caseLink'])) { if (!empty($properties['caseLink'])) {
@@ -780,14 +1224,6 @@ class AbstractCases implements CasesInterface
if (!empty($properties['appUidCheck'])) { if (!empty($properties['appUidCheck'])) {
$this->setCasesUids($properties['appUidCheck']); $this->setCasesUids($properties['appUidCheck']);
} }
// Filter date newest related to delegation date
if (!empty($properties['newestthan'])) {
$this->setNewestThan($properties['newestthan']);
}
// Filter date oldest related to delegation date
if (!empty($properties['oldestthan'])) {
$this->setOldestThan($properties['oldestthan']);
}
// Sort column // Sort column
if (!empty($properties['sort'])) { if (!empty($properties['sort'])) {
$this->setOrderByColumn($properties['sort']); $this->setOrderByColumn($properties['sort']);

View File

@@ -18,7 +18,8 @@ class Draft extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date 'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority 'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -30,6 +31,39 @@ class Draft extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/** /**
* Get data self-services cases by user * Get data self-services cases by user
* *
@@ -44,18 +78,9 @@ class Draft extends AbstractCases
$query->joinTask(); $query->joinTask();
// Join with application for add the initial scope for DRAFT cases // Join with application for add the initial scope for DRAFT cases
$query->draft($this->getUserId()); $query->draft($this->getUserId());
// Specific process /** Apply filters */
if ($this->getProcessId()) { $this->filters($query);
$query->processId($this->getProcessId()); /** Apply order and pagination */
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
// Add any sort if needed // Add any sort if needed
if ($this->getOrderByColumn()) { if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
@@ -92,6 +117,7 @@ class Draft extends AbstractCases
$query = Delegation::query()->select(); $query = Delegation::query()->select();
// Add the initial scope for draft cases // Add the initial scope for draft cases
$query->draft($this->getUserId()); $query->draft($this->getUserId());
$this->filters($query);
return $query->count(); return $query->count();
} }

View File

@@ -21,7 +21,8 @@ class Inbox extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date 'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority 'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -33,6 +34,39 @@ class Inbox extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/** /**
* Get the data corresponding to List Inbox * Get the data corresponding to List Inbox
* *
@@ -48,30 +82,16 @@ class Inbox extends AbstractCases
$query->joinUser(); $query->joinUser();
// Join with application for add the initial scope for TO_DO cases // Join with application for add the initial scope for TO_DO cases
$query->inbox($this->getUserId()); $query->inbox($this->getUserId());
// Define a specific risk /** Apply filters */
switch ($this->getRiskStatus()) { $this->filters($query);
case 'ON_TIME': /** Apply order and pagination */
// Scope that search for the ON_TIME cases // Add any sort if needed
$query->onTime(); if ($this->getOrderByColumn()) {
break; $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
case 'AT_RISK':
// Scope that search for the AT_RISK cases
$query->atRisk();
break;
case 'OVERDUE':
// Scope that search for the OVERDUE cases
$query->overdue();
break;
} }
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause // The limit by clause
$query->offset($this->getOffset())->limit($this->getLimit()); $query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query // Execute the query
$results = $query->get(); $results = $query->get();
// Prepare the result // Prepare the result
$results->transform(function ($item, $key) { $results->transform(function ($item, $key) {

View File

@@ -1,62 +0,0 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
class MyCases extends AbstractCases
{
/**
* Gets the data for the Cases list My Cases
*
* @return array
*/
public function getData()
{
$filter = $this->getParticipatedStatus();
$result = [];
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$result = $list->getData();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$result = $list->getData();
break;
}
}
return $result;
}
/**
* Gets the total of My Cases
*
* @return int
*/
public function getCounter()
{
$filter = $this->getParticipatedStatus();
$count = 0;
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$count = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$count = $list->getCounter();
break;
}
}
return $count;
}
}

View File

@@ -2,8 +2,8 @@
namespace ProcessMaker\BusinessModel\Cases; namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Task;
class Participated extends AbstractCases class Participated extends AbstractCases
{ {
@@ -15,11 +15,13 @@ class Participated extends AbstractCases
'PROCESS.PRO_TITLE', // Process Name 'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task 'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status 'APPLICATION.APP_STATUS', // Status
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date 'APPLICATION.APP_CREATE_DATE', // Start Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Start Date 'APPLICATION.APP_FINISH_DATE', // Finish Date
'APP_DELEGATION.DEL_FINISH_DATE', // Finish Date 'USERS.USR_ID', // Current UserId
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -31,6 +33,59 @@ class Participated extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Scope to search for an specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific status
if ($this->getCaseStatus()) {
$query->status($this->getCaseStatus());
}
// Specific start case date from
if (!empty($this->getStartCaseFrom())) {
$query->startDateFrom($this->getStartCaseFrom());
}
// Specific by start case date to
if (!empty($this->getStartCaseTo())) {
$query->startDateTo($this->getStartCaseTo());
}
// Specific finish case date from
if (!empty($this->getFinishCaseFrom())) {
$query->finishCaseFrom($this->getFinishCaseFrom());
}
// Filter by finish case date to
if (!empty($this->getFinishCaseTo())) {
$query->finishCaseTo($this->getFinishCaseTo());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/** /**
* Get the data corresponding to Participated * Get the data corresponding to Participated
* *
@@ -39,13 +94,15 @@ class Participated extends AbstractCases
public function getData() public function getData()
{ {
// Start the query for get the cases related to the user // Start the query for get the cases related to the user
$query = Delegation::query()->select(); $query = Delegation::query()->select($this->getColumnsView());
// Join with process // Join with process
$query->joinProcess(); $query->joinProcess();
// Join with task // Join with task
$query->joinTask(); $query->joinTask();
// Join with users // Join with users
$query->joinUser(); $query->joinUser();
// Join with application
$query->joinApplication();
// Scope to Participated // Scope to Participated
$query->participated($this->getUserId()); $query->participated($this->getUserId());
// Add filter // Add filter
@@ -53,29 +110,42 @@ class Participated extends AbstractCases
if (!empty($filter)) { if (!empty($filter)) {
switch ($filter) { switch ($filter) {
case 'STARTED': case 'STARTED':
// Scope that search for the STARTED // Scope that search for the STARTED by user
$query->caseStarted(); $query->caseStarted();
break; break;
case 'IN-PROGRESS': case 'IN_PROGRESS':
// Scope that search for the TO_DO // Scope that search for the TO_DO
$query->selectRaw(
'CONCAT(
\'[\',
GROUP_CONCAT(
CONCAT(
\'{"tas_id":\',
APP_DELEGATION.TAS_ID,
\', "user_id":\',
APP_DELEGATION.USR_ID,
\', "due_date":"\',
APP_DELEGATION.DEL_TASK_DUE_DATE,
\'"}\'
)
),
\']\'
) AS PENDING'
);
$query->caseInProgress(); $query->caseInProgress();
$query->groupBy('APP_NUMBER');
break; break;
case 'COMPLETED': case 'COMPLETED':
// Scope that search for the COMPLETED // Scope that search for the COMPLETED
$query->caseCompleted(); $query->caseCompleted();
// Scope to set the last thread
$query->lastThread();
break; break;
} }
} }
// Scope to search for an specific process /** Apply filters */
if (!empty($this->getProcessId())) { $this->filters($query);
$query->processId($this->getProcessId()); /** Apply order and pagination */
}
// Scope the specific case status
$status = $this->getCaseStatus();
if (array_key_exists($status, Application::$app_status_values)) {
$statusId = Application::$app_status_values[$status];
$query->appStatusId($statusId);
}
// The order by clause // The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause // The limit by clause
@@ -83,17 +153,57 @@ class Participated extends AbstractCases
//Execute the query //Execute the query
$results = $query->get(); $results = $query->get();
// Prepare the result // Prepare the result
$results->transform(function ($item, $key) { $results->transform(function ($item, $key) use ($filter) {
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
// Apply the date format defined in environment // Apply the date format defined in environment
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']); $item['APP_CREATE_DATE_LABEL'] = !empty($item['APP_CREATE_DATE']) ? applyMaskDateEnvironment($item['APP_CREATE_DATE']): null;
$item['DEL_FINISH_DATE_LABEL'] = !empty($item['DEL_FINISH_DATE']) ? applyMaskDateEnvironment($item['DEL_FINISH_DATE']): null; $item['APP_FINISH_DATE_LABEL'] = !empty($item['APP_FINISH_DATE']) ? applyMaskDateEnvironment($item['APP_FINISH_DATE']): null;
// Calculate duration // Calculate duration
$startDate = $item['DEL_DELEGATE_DATE']; $startDate = (string)$item['APP_CREATE_DATE'];
$endDate = !empty($item['DEL_FINISH_DATE']) ? $item['DEL_FINISH_DATE'] : date("Y-m-d H:i:s"); $endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate); $item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
// Get the detail related to the open thread
if (!empty($item['PENDING'])) {
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
}
switch ($filter) {
case 'STARTED':
$result = [];
$i = 0;
if ($item['APP_STATUS'] === 'TO_DO') {
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
foreach ($taskPending as $thread) {
// todo this need to review
$result[$i]['tas_title'] = $thread['TAS_TITLE'];
$result[$i]['user_id'] = $thread['USR_ID'];
$result[$i]['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$i++;
}
$item['PENDING'] = $result;
} else {
$result[$i]['tas_title'] = $item['TAS_TITLE'];
$result[$i]['user_id'] = $item['USR_ID'];
$result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$item['PENDING'] = $result;
}
break;
case 'IN_PROGRESS':
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
break;
case 'COMPLETED':
$result = [];
$i = 0;
$result[$i]['tas_title'] = $item['TAS_TITLE'];
$result[$i]['user_id'] = $item['USR_ID'];
$result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$item['PENDING'] = $result;
break;
}
return $item; return $item;
}); });

View File

@@ -21,7 +21,8 @@ class Paused extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date 'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority 'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -33,6 +34,39 @@ class Paused extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/** /**
* Gets the data for the paused cases list * Gets the data for the paused cases list
* *
@@ -44,11 +78,10 @@ class Paused extends AbstractCases
// Join with process // Join with process
$query->joinProcess(); $query->joinProcess();
// Scope that set the paused cases // Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber()); $query->paused($this->getUserId(), $this->getTaskId());
// Join with delegation for get the previous index /** Apply filters */
$query->joinPreviousIndex(); $this->filters($query);
// Join with delegation for get the previous user /** Apply order and pagination */
$query->joinPreviousUser();
// Add any sort if needed // Add any sort if needed
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// Add pagination to the query // Add pagination to the query

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases; namespace ProcessMaker\BusinessModel\Cases;
use G; use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Delegation;
class Search extends AbstractCases class Search extends AbstractCases
@@ -14,6 +15,7 @@ class Search extends AbstractCases
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD 'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process 'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task 'TASK.TAS_TITLE', // Task
'APPLICATION.APP_STATUS', // Status
'USERS.USR_USERNAME', // Current UserName 'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName 'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName 'USERS.USR_LASTNAME', // Current User LastName
@@ -21,7 +23,8 @@ class Search extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date 'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority 'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -33,6 +36,101 @@ class Search extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Filter case by case number
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Filter cases by specific cases like [1,3,5]
if (!empty($this->getCasesNumbers())) {
$query->specificCases($this->getCasesNumbers());
}
// Filter cases by range of cases like ['1-5', '10-15']
if (!empty($this->getRangeCasesFromTo())) {
$query->rangeOfCases($this->getRangeCasesFromTo());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Filter by process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Filter by user
if ($this->getUserId()) {
$query->userId($this->getUserId());
}
// Filter by task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Filter one or more priorities like ['VL', 'L', 'N']
if (!empty($this->getPriorities())) {
$query->priorities($this->getPriorities());
}
// Filter by delegate from
if (!empty($this->getDelegateFrom())) {
$query->delegateDateFrom($this->getDelegateFrom());
}
// Filter by delegate to
if (!empty($this->getDelegateTo())) {
$query->delegateDateTo($this->getDelegateTo());
}
// Filter by due from
if (!empty($this->getDueFrom())) {
$query->dueFrom($this->getDueFrom());
}
// Filter by due to
if (!empty($this->getDueTo())) {
$query->dueTo($this->getDueTo());
}
/** This filter define the UNION */
// Filter related to the case status like ['DRAFT', 'TO_DO']
if (!empty($this->getCaseStatuses())) {
$statuses = $this->getCaseStatuses();
$casesOpen = [];
$casesClosed = [];
foreach ($statuses as $row) {
if ($row === Application::STATUS_DRAFT or $row === Application::STATUS_TODO) {
$casesOpen[] = $row;
} else {
$casesClosed[] = $row;
}
}
if (!empty($casesOpen) && !empty($casesClosed)) {
// Only in this case need to clone the same query for the union
$cloneQuery = clone $query;
// Get the open threads
$query->casesInProgress($casesOpen);
// Get the last thread
$cloneQuery->casesDone($casesClosed);
// Union
$query->union($cloneQuery);
} else {
if (!empty($casesOpen)) {
// Get the open thread
$query->casesInProgress($casesOpen);
}
if (!empty($casesClosed)) {
// Get the last thread
$query->casesDone($casesClosed);
}
}
}
return $query;
}
/** /**
* Get the data corresponding to advanced search * Get the data corresponding to advanced search
* *
@@ -47,33 +145,11 @@ class Search extends AbstractCases
$query->joinTask(); $query->joinTask();
// Join with users // Join with users
$query->joinUser(); $query->joinUser();
// Filter by case number // Join with application
if ($this->getCaseNumber() > 0) { $query->joinApplication();
$query->case($this->getCaseNumber()); /** Apply filters */
} $this->filters($query);
// Filter by case number: from and to /** Apply order and pagination */
if ($this->getFromCaseNumber() > 0 && $this->getToCaseNumber() > 0) {
$query->rangeOfCases($this->getFromCaseNumber(), $this->getToCaseNumber());
}
// @todo: Filter by case title, pending from other PRD
// Filter by priority
if ($this->getPriority() > 0) {
$query->priority($this->getPriority());
}
// Filter by process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// Filter by user
if (!empty($this->getUserId())) {
$query->userId($this->getUserId());
}
// Filter by task
if (!empty($this->getTaskId())) {
$query->task($this->getTaskId());
}
// The order by clause // The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause // The limit by clause

View File

@@ -15,11 +15,12 @@ class Supervising extends AbstractCases
'PROCESS.PRO_TITLE', // Process Name 'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task 'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status 'APPLICATION.APP_STATUS', // Status
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date 'APPLICATION.APP_CREATE_DATE', // Start Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Start Date 'APPLICATION.APP_FINISH_DATE', // Finish Date
'APP_DELEGATION.DEL_FINISH_DATE', // Finish Date 'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -31,6 +32,59 @@ class Supervising extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Scope to search for an specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific status
if ($this->getCaseStatus()) {
$query->status($this->getCaseStatus());
}
// Specific start case date from
if (!empty($this->getStartCaseFrom())) {
$query->startDateFrom($this->getStartCaseFrom());
}
// Specific by start case date to
if (!empty($this->getStartCaseTo())) {
$query->startDateTo($this->getStartCaseTo());
}
// Specific finish case date from
if (!empty($this->getFinishCaseFrom())) {
$query->finishCaseFrom($this->getFinishCaseFrom());
}
// Filter by finish case date to
if (!empty($this->getFinishCaseTo())) {
$query->finishCaseTo($this->getFinishCaseTo());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/** /**
* Gets the data for the Cases list Review * Gets the data for the Cases list Review
* *
@@ -40,51 +94,53 @@ class Supervising extends AbstractCases
{ {
// Get the list of processes of the supervisor // Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid()); $processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// Start the query for get the cases related to the user // We will prepare the queries if the user is supervisor
$query = Delegation::query()->select($this->getColumnsView()); if (!empty($processes)) {
// Join with process // Start the query for get the cases related to the user
$query->joinProcess(); $query = Delegation::query()->select($this->getColumnsView());
// Join with users // Join with process
$query->joinUser(); $query->joinProcess();
// Join with task and scope that sets the queries for List Inbox // Join with task
$query->inbox($this->getUserId()); $query->joinTask();
// Scope the specific array of processes supervising // Join with users
$query->processInList($processes); $query->joinUser();
// Join with delegation for get the previous index // Join with application
$query->joinPreviousIndex(); $query->joinApplication();
// Join with delegation for get the previous user // Only cases in progress
$query->joinPreviousUser(); $query->caseInProgress();
// Scope to search for an specific case // Scope that return the results for an specific user
if (!empty($this->getCaseNumber())) { $query->userId($this->getUserId());
$query->case($this->getCaseNumber()); // Scope the specific array of processes supervising
} $query->processInList($processes);
// Scope to search for an specific process /** Apply filters */
if (!empty($this->getProcessId())) { $this->filters($query);
$query->processId($this->getProcessId()); /** Apply order and pagination */
} //The order by clause
//The order by clause $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); //The limit clause
//The limit clause $query->offset($this->getOffset())->limit($this->getLimit());
$query->offset($this->getOffset())->limit($this->getLimit()); //Execute the query
//Execute the query $results = $query->get();
$results = $query->get(); // Prepare the result
// Prepare the result $results->transform(function ($item, $key) {
$results->transform(function ($item, $key) { // Get task color label
// Get task color label $item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']); $item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']]; // Apply the date format defined in environment
// Apply the date format defined in environment $item['APP_CREATE_DATE_LABEL'] = !empty($item['APP_CREATE_DATE']) ? applyMaskDateEnvironment($item['APP_CREATE_DATE']): null;
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']); $item['APP_FINISH_DATE_LABEL'] = !empty($item['APP_FINISH_DATE']) ? applyMaskDateEnvironment($item['APP_FINISH_DATE']): null;
$item['DEL_FINISH_DATE_LABEL'] = !empty($item['DEL_FINISH_DATE']) ? applyMaskDateEnvironment($item['DEL_FINISH_DATE']): null; // Calculate duration
// Calculate duration $startDate = (string)$item['APP_CREATE_DATE'];
$startDate = $item['DEL_DELEGATE_DATE']; $endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
$endDate = !empty($item['DEL_FINISH_DATE']) ? $item['DEL_FINISH_DATE'] : date("Y-m-d H:i:s"); $item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
return $item; return $item;
}); });
return $results->values()->toArray(); return $results->values()->toArray();
} else {
return [];
}
} }
/** /**

View File

@@ -22,7 +22,8 @@ class Unassigned extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date 'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority 'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities // Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink 'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
]; ];
/** /**
@@ -34,6 +35,39 @@ class Unassigned extends AbstractCases
return $this->columnsView; return $this->columnsView;
} }
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Specific case
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Specific case title
if ($this->getCaseTitle()) {
// @todo: Filter by case title, pending from other PRD
}
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Specific case uid PMFCaseLink
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
return $query;
}
/** /**
* Get data self-services cases by user * Get data self-services cases by user
* *
@@ -47,28 +81,15 @@ class Unassigned extends AbstractCases
// Join with users // Join with users
$query->joinUser(); $query->joinUser();
// Join with application for add the initial scope for unassigned cases // Join with application for add the initial scope for unassigned cases
$query->selfService($this->getUserUid()); if (!empty($this->getUserUid())) {
$query->selfService($this->getUserUid());
}
// Add join for application, for get the case title when the case status is TO_DO // Add join for application, for get the case title when the case status is TO_DO
$query->appStatusId(Application::STATUS_TODO); $query->joinApplication();
// Specific process $query->status(Application::STATUS_TODO);
if ($this->getProcessId()) { /** Apply filters */
$query->processId($this->getProcessId()); $this->filters($query);
} /** Apply order and pagination */
// Date range filter, this is used from mobile GET /light/unassigned
if ($this->getNewestThan()) {
$query->delegateDateFrom($this->getNewestThan());
}
if ($this->getOldestThan()) {
$query->delegateDateTo($this->getOldestThan());
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
// Add any sort if needed // Add any sort if needed
if ($this->getOrderByColumn()) { if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection()); $query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());

View File

@@ -66,6 +66,18 @@ class Delegation extends Model
return $query->where('DEL_PRIORITY', $priority); return $query->where('DEL_PRIORITY', $priority);
} }
/**
* Scope a query to only include specific priorities
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $priorities
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePriorities($query, array $priorities)
{
return $query->whereIn('DEL_PRIORITY', $priorities);
}
/** /**
* Scope a query to only include open threads * Scope a query to only include open threads
* *
@@ -77,6 +89,34 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN'); return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
} }
/**
* Scope to use when the case is IN_PROGRESS like DRAFT or TO_DO
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $ids
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesInProgress($query, array $ids)
{
$query->isThreadOpen()->statusIds($ids);
return $query;
}
/**
* Scope to use when the case is DONE like COMPLETED or CANCELED
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $ids
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesDone($query, array $ids)
{
$query->lastThread()->statusIds($ids);
return $query;
}
/** /**
* Scope a query to only include a specific index * Scope a query to only include a specific index
* *
@@ -111,7 +151,7 @@ class Delegation extends Model
*/ */
public function scopeCaseInProgress($query) public function scopeCaseInProgress($query)
{ {
return $query->appStatusId(2); return $query->where('APPLICATION.APP_STATUS_ID', 2);
} }
/** /**
@@ -123,7 +163,85 @@ class Delegation extends Model
*/ */
public function scopeCaseCompleted($query) public function scopeCaseCompleted($query)
{ {
return $query->appStatusId(3); return $query->where('APPLICATION.APP_STATUS_ID', 3);
}
/**
* Scope a query to get specific status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $statusId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStatus($query, int $statusId)
{
return $query->where('APPLICATION.APP_STATUS_ID', $statusId);
}
/**
* Scope a more status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $statuses
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStatusIds($query, array $statuses)
{
return $query->whereIn('APPLICATION.APP_STATUS_ID', $statuses);
}
/**
* Scope a query to only include a specific start date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStartDateFrom($query, string $from)
{
return $query->where('APPLICATION.APP_CREATE_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific start date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStartDateTo($query, string $to)
{
return $query->where('APPLICATION.APP_CREATE_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishCaseFrom($query, string $from)
{
return $query->where('APPLICATION.APP_FINISH_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishCaseTo($query, string $to)
{
return $query->where('APPLICATION.APP_FINISH_DATE', '<=', $to);
} }
/** /**
@@ -134,7 +252,7 @@ class Delegation extends Model
* *
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopeDelegateDateFrom($query, $from) public function scopeDelegateDateFrom($query, string $from)
{ {
return $query->where('DEL_DELEGATE_DATE', '>=', $from); return $query->where('DEL_DELEGATE_DATE', '>=', $from);
} }
@@ -147,11 +265,63 @@ class Delegation extends Model
* *
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopeDelegateDateTo($query, $to) public function scopeDelegateDateTo($query, string $to)
{ {
return $query->where('DEL_DELEGATE_DATE', '<=', $to); return $query->where('DEL_DELEGATE_DATE', '<=', $to);
} }
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishDateFrom($query, $from)
{
return $query->where('DEL_FINISH_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishDateTo($query, $to)
{
return $query->where('DEL_FINISH_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific due date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDueFrom($query, $from)
{
return $query->where('DEL_TASK_DUE_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific due date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDueTo($query, $to)
{
return $query->where('DEL_TASK_DUE_DATE', '<=', $to);
}
/** /**
* Scope a query to get only the date on time * Scope a query to get only the date on time
* *
@@ -201,21 +371,6 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.APP_NUMBER', '=', $appNumber); return $query->where('APP_DELEGATION.APP_NUMBER', '=', $appNumber);
} }
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $from
* @param int $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRangeOfCases($query, int $from, int $to)
{
return $query->where('APP_DELEGATION.APP_NUMBER', '>=', $from)
->where('APP_DELEGATION.APP_NUMBER', '<=', $to);
}
/** /**
* Scope a query to only include specific cases * Scope a query to only include specific cases
* *
@@ -229,6 +384,57 @@ class Delegation extends Model
return $query->whereIn('APP_DELEGATION.APP_NUMBER', $cases); return $query->whereIn('APP_DELEGATION.APP_NUMBER', $cases);
} }
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesFrom($query, int $from)
{
return $query->where('APP_DELEGATION.APP_NUMBER', '>=', $from);
}
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesTo($query, int $to)
{
return $query->where('APP_DELEGATION.APP_NUMBER', '<=', $to);
}
/**
* Scope more than one range of cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $rangeCases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRangeOfCases($query, array $rangeCases)
{
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
}
/** /**
* Scope a query to get the delegations from a case by APP_UID * Scope a query to get the delegations from a case by APP_UID
* *
@@ -469,7 +675,8 @@ class Delegation extends Model
public function scopeInbox($query, $userId) public function scopeInbox($query, $userId)
{ {
// This scope is for the join with the APP_DELEGATION table // This scope is for the join with the APP_DELEGATION table
$query->appStatusId(2); $query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for // Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS); $query->excludeTaskTypes(Task::DUMMY_TASKS);
@@ -493,7 +700,8 @@ class Delegation extends Model
public function scopeInboxWithoutUser($query) public function scopeInboxWithoutUser($query)
{ {
// This scope is for the join with the APP_DELEGATION table // This scope is for the join with the APP_DELEGATION table
$query->appStatusId(2); $query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for // Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS); $query->excludeTaskTypes(Task::DUMMY_TASKS);
@@ -535,7 +743,8 @@ class Delegation extends Model
public function scopeDraft($query, $user) public function scopeDraft($query, $user)
{ {
// Add join for application, for get the case title when the case status is DRAFT // Add join for application, for get the case title when the case status is DRAFT
$query->appStatusId(Application::STATUS_DRAFT); $query->joinApplication();
$query->status(Application::STATUS_TODO);
// Case assigned to the user // Case assigned to the user
$query->userId($user); $query->userId($user);
@@ -554,8 +763,6 @@ class Delegation extends Model
{ {
// Scope to set the user // Scope to set the user
$query->userId($user); $query->userId($user);
// Scope to set the last thread
$query->lastThread();
return $query; return $query;
} }
@@ -720,15 +927,12 @@ class Delegation extends Model
* *
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopePaused($query, int $userId, int $taskId, int $caseNumber) public function scopePaused($query, int $userId, int $taskId)
{ {
$query->joinAppDelay('PAUSE'); $query->joinAppDelay('PAUSE');
$query->joinAppDelayUsers($userId); $query->joinAppDelayUsers($userId);
$query->joinApplication(); $query->joinApplication();
// Specific case number // Exclude some specific task
if (!empty($caseNumber)) {
$query->case($caseNumber);
}
$query->excludeTaskTypes(Task::DUMMY_TASKS); $query->excludeTaskTypes(Task::DUMMY_TASKS);
// Specific task // Specific task
if (!empty($taskId)) { if (!empty($taskId)) {
@@ -1401,13 +1605,13 @@ class Delegation extends Model
/** /**
* This function get the current user related to the specific case and index * This function get the current user related to the specific case and index
* *
* @param integer $appNumber, Case number * @param int $appNumber, Case number
* @param integer $index, Index to review * @param int $index, Index to review
* @param string $status, The status of the thread * @param string $status, The status of the thread
* *
* @return string * @return string
*/ */
public static function getCurrentUser($appNumber, $index, $status = 'OPEN') public static function getCurrentUser(int $appNumber, int $index, $status = 'OPEN')
{ {
$query = Delegation::query()->select('USR_UID'); $query = Delegation::query()->select('USR_UID');
$query->where('APP_NUMBER', $appNumber); $query->where('APP_NUMBER', $appNumber);
@@ -1427,12 +1631,12 @@ class Delegation extends Model
/** /**
* Return the open thread related to the task * Return the open thread related to the task
* *
* @param integer $appNumber, Case number * @param int $appNumber, Case number
* @param string $tasUid, The task uid * @param string $tasUid, The task uid
* *
* @return array * @return array
*/ */
public static function getOpenThreads($appNumber, $tasUid) public static function getOpenThreads(int $appNumber, string $tasUid)
{ {
$query = Delegation::query()->select(); $query = Delegation::query()->select();
$query->where('DEL_THREAD_STATUS', 'OPEN'); $query->where('DEL_THREAD_STATUS', 'OPEN');
@@ -1457,7 +1661,7 @@ class Delegation extends Model
* *
* @return boolean * @return boolean
*/ */
public static function participation($appUid, $userUid) public static function participation(string $appUid, string $userUid)
{ {
$query = Delegation::query()->select(); $query = Delegation::query()->select();
$query->where('APP_UID', $appUid); $query->where('APP_UID', $appUid);
@@ -1515,4 +1719,31 @@ class Delegation extends Model
return $thread; return $thread;
} }
/**
* Return the open thread related to the task
*
* @param int $appNumber
*
* @return array
*/
public static function getPendingThreads(int $appNumber)
{
$query = Delegation::query()->select([
'TASK.TAS_TITLE',
'APP_DELEGATION.USR_ID',
'APP_DELEGATION.DEL_TASK_DUE_DATE'
]);
// Join with task
$query->joinTask();
// Get the open threads
$query->threadOpen();
// Related to the specific case number
$query->case($appNumber);
// Get the results
$results = $query->get()->values()->toArray();
return $results;
}
} }

View File

@@ -64,41 +64,29 @@ class ProcessUser extends Model
return $query; return $query;
} }
/**
* It returns a list of processes ids as an array
*
* @param array $processes
* @return array
*/
public static function getListOfProcessUid($processes)
{
$res = (array_map(function ($x) {
if (array_key_exists('PRO_ID', $x)) {
return $x['PRO_ID'];
}
}, $processes));
return array_filter($res);
}
/** /**
* It returns a list of processes of the supervisor * It returns a list of processes of the supervisor
* *
* @param string $userUid * @param string $userUid
* @return array * @return array
*/ */
public static function getProcessesOfSupervisor($userUid) public static function getProcessesOfSupervisor(string $userUid)
{ {
$query1 = ProcessUser::query()->select(['PRO_ID']); // Get the list of process when the user is supervisor
$query1->processSupervisor($userUid); $query = ProcessUser::query()->select(['PRO_ID']);
$processes = $query1->get()->values()->toArray(); $query->processSupervisor($userUid);
$results = $query->get();
$query2 = ProcessUser::query()->select(['PRO_ID']); $processes = [];
$query2->processGroupSupervisor($userUid); $results->each(function ($item, $key) use (&$processes) {
$processes[] = $item->PRO_ID;
array_push($processes, $query2->get()->values()->toArray()); });
// Get the list of process when the group related to the user is supervisor
$processes = ProcessUser::getListOfProcessUid($processes); $query = ProcessUser::query()->select(['PRO_ID']);
$query->processGroupSupervisor($userUid);
$results = $query->get();
$results->each(function ($item, $key) use (&$processes) {
$processes[] = $item->PRO_ID;
});
return $processes; return $processes;
} }

View File

@@ -0,0 +1,463 @@
<?php
namespace ProcessMaker\Services\Api;
use Exception;
use Luracast\Restler\RestException;
use ProcessMaker\BusinessModel\Cases\Draft;
use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\BusinessModel\Cases\Participated;
use ProcessMaker\BusinessModel\Cases\Paused;
use ProcessMaker\BusinessModel\Cases\Search;
use ProcessMaker\BusinessModel\Cases\Supervising;
use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\Model\User;
use ProcessMaker\Services\Api;
use RBAC;
class Home extends Api
{
/**
* Constructor of the class
* We will to define the $RBAC definition
*/
public function __construct()
{
global $RBAC;
if (!isset($RBAC)) {
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->sSystem = 'PROCESSMAKER';
$RBAC->initRBAC();
$RBAC->loadUserRolePermission($RBAC->sSystem, $this->getUserId());
}
}
/**
* Get the draft cases
*
* @url GET /draft
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetDraftCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Draft();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the inbox cases
*
* @url GET /todo
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetTodoCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Inbox();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the unassigned cases
*
* @url GET /unassigned
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetUnassignedCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Unassigned();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
// todo: some queries related to the unassigned are using the USR_UID
$list->setUserUid($usrUid);
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the paused cases
*
* @url GET /paused
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetPausedCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Paused();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the my cases
*
* @url GET /mycases
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $startCaseFrom
* @param string $startCaseTo
* @param string $finishCaseFrom
* @param string $finishCaseTo
* @param string $filter
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetMyCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $filter = 'IN_PROGRESS',
string $startCaseFrom = '',
string $startCaseTo = '',
string $finishCaseFrom = '',
string $finishCaseTo = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
$properties['filter'] = $filter;
$properties['startCaseFrom'] = $startCaseFrom;
$properties['startCaseTo'] = $startCaseTo;
$properties['finishCaseFrom'] = $finishCaseFrom;
$properties['finishCaseTo'] = $finishCaseTo;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$result = [];
try {
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$list->setParticipatedStatus($filter);
$list->setProperties($properties);
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$list->setProperties($properties);
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
break;
}
}
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get counters
*
* @url GET /counters
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetCountMyCases()
{
try {
$filters = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
$result = [];
foreach ($filters as $row) {
switch ($row) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$list->setParticipatedStatus($row);
$list->setUserId($this->getUserId());
$result[strtolower($row)] = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$list->setUserId($this->getUserId());
$result[strtolower($row)] = $list->getCounter();
break;
default:
$result[strtolower($row)] = 0;
}
}
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the search cases
*
* @url GET /search
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $user
* @param string $caseTitle
* @param string $priorities
* @param string $caseStatuses
* @param string $filterCases
* @param string $dueDateFrom
* @param string $dueDateTo
* @param string $delegationDateFrom
* @param string $delegationDateTo
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_ALLCASES}
*/
public function doGetSearchCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $user = 0,
string $caseTitle = '',
string $priorities = '',
string $caseStatuses = '',
string $filterCases = '',
string $dueDateFrom = '',
string $dueDateTo = '',
string $delegationDateFrom = '',
string $delegationDateTo = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Search();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
$properties['user'] = $user;
$properties['priorities'] = explode(',', $priorities);
$properties['caseStatuses'] = explode(',', $caseStatuses);
$properties['filterCases'] = $filterCases;
$properties['dueDateFrom'] = $dueDateFrom;
$properties['dueDateTo'] = $dueDateTo;
$properties['delegationDateFrom'] = $delegationDateFrom;
$properties['delegationDateTo'] = $delegationDateTo;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}