Merged in feature/PMCORE-1214 (pull request #7548)
PMCORE-1214 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -3,10 +3,12 @@
|
|||||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
|
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
|
||||||
|
|
||||||
use G;
|
use G;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use ProcessMaker\BusinessModel\Cases\AbstractCases;
|
use ProcessMaker\BusinessModel\Cases\AbstractCases;
|
||||||
use ProcessMaker\Model\Application;
|
use ProcessMaker\Model\Application;
|
||||||
use ProcessMaker\Model\Process;
|
use ProcessMaker\Model\Process;
|
||||||
use ProcessMaker\Model\ProcessCategory;
|
use ProcessMaker\Model\ProcessCategory;
|
||||||
|
use ProcessMaker\Model\Task;
|
||||||
use ProcessMaker\Model\User;
|
use ProcessMaker\Model\User;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -15,6 +17,8 @@ use Tests\TestCase;
|
|||||||
*/
|
*/
|
||||||
class AbstractCasesTest extends TestCase
|
class AbstractCasesTest extends TestCase
|
||||||
{
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This check the getter and setter related to the category
|
* This check the getter and setter related to the category
|
||||||
*
|
*
|
||||||
@@ -52,6 +56,22 @@ class AbstractCasesTest extends TestCase
|
|||||||
$this->assertEquals($process->PRO_ID, $actual);
|
$this->assertEquals($process->PRO_ID, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This check the getter and setter related to the task
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setTaskId()
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getTaskId()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_return_set_get_task()
|
||||||
|
{
|
||||||
|
$task = factory(Task::class)->create();
|
||||||
|
$absCases = new AbstractCases();
|
||||||
|
$absCases->setTaskId($task->TAS_ID);
|
||||||
|
$actual = $absCases->getTaskId();
|
||||||
|
$this->assertEquals($task->TAS_ID, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This check the getter and setter related to the user
|
* This check the getter and setter related to the user
|
||||||
*
|
*
|
||||||
@@ -73,6 +93,61 @@ class AbstractCasesTest extends TestCase
|
|||||||
$this->assertEquals($users->USR_ID, $actual);
|
$this->assertEquals($users->USR_ID, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This check the getter and setter related to the priority
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setPriority()
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getPriority()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_return_set_get_priority()
|
||||||
|
{
|
||||||
|
$absCases = new AbstractCases();
|
||||||
|
$arguments = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
|
||||||
|
$index = array_rand($arguments);
|
||||||
|
$absCases->setPriority($index);
|
||||||
|
$actual = $absCases->getPriority();
|
||||||
|
$this->assertEquals($index, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This check the getter and setter related to the case number
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setCaseNumber()
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getCaseNumber()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_return_set_get_case_number()
|
||||||
|
{
|
||||||
|
$case = factory(Application::class)->create();
|
||||||
|
$absCases = new AbstractCases();
|
||||||
|
$absCases->setCaseNumber($case->APP_NUMBER);
|
||||||
|
$actual = $absCases->getCaseNumber();
|
||||||
|
$this->assertEquals($case->APP_NUMBER, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This check the getter and setter related to the range of case number
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::setRangeCaseNumber()
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getFromCaseNumber()
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\AbstractCases::getToCaseNumber()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_return_set_get_range_case_number()
|
||||||
|
{
|
||||||
|
$case1 = factory(Application::class)->create();
|
||||||
|
$case2 = factory(Application::class)->create([
|
||||||
|
'APP_NUMBER' => $case1->APP_NUMBER + 1
|
||||||
|
]);
|
||||||
|
$absCases = new AbstractCases();
|
||||||
|
$absCases->setRangeCaseNumber($case1->APP_NUMBER, $case2->APP_NUMBER);
|
||||||
|
$from = $absCases->getFromCaseNumber();
|
||||||
|
$to = $absCases->getToCaseNumber();
|
||||||
|
$this->assertEquals($case1->APP_NUMBER, $from);
|
||||||
|
$this->assertEquals($case2->APP_NUMBER, $to);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This check the getter and setter related to the search
|
* This check the getter and setter related to the search
|
||||||
*
|
*
|
||||||
@@ -306,7 +381,12 @@ class AbstractCasesTest extends TestCase
|
|||||||
$properties = [
|
$properties = [
|
||||||
'category' => G::generateUniqueID(),
|
'category' => G::generateUniqueID(),
|
||||||
'process' => G::generateUniqueID(),
|
'process' => G::generateUniqueID(),
|
||||||
|
'task' => rand(),
|
||||||
'user' => G::generateUniqueID(),
|
'user' => G::generateUniqueID(),
|
||||||
|
'priority' => 1,
|
||||||
|
'caseNumber' => rand(),
|
||||||
|
'caseNumberFrom' => rand(),
|
||||||
|
'caseNumberTo' => rand(),
|
||||||
'search' => G::generateUniqueID(),
|
'search' => G::generateUniqueID(),
|
||||||
'caseLink' => G::generateUniqueID(),
|
'caseLink' => G::generateUniqueID(),
|
||||||
'appUidCheck' => [G::generateUniqueID()],
|
'appUidCheck' => [G::generateUniqueID()],
|
||||||
@@ -323,8 +403,18 @@ class AbstractCasesTest extends TestCase
|
|||||||
$this->assertEquals($properties['category'], $actual);
|
$this->assertEquals($properties['category'], $actual);
|
||||||
$actual = $absCases->getProcessUid();
|
$actual = $absCases->getProcessUid();
|
||||||
$this->assertEquals($properties['process'], $actual);
|
$this->assertEquals($properties['process'], $actual);
|
||||||
|
$actual = $absCases->getTaskId();
|
||||||
|
$this->assertEquals($properties['task'], $actual);
|
||||||
$actual = $absCases->getUserUid();
|
$actual = $absCases->getUserUid();
|
||||||
$this->assertEquals($properties['user'], $actual);
|
$this->assertEquals($properties['user'], $actual);
|
||||||
|
$actual = $absCases->getPriority();
|
||||||
|
$this->assertEquals($properties['priority'], $actual);
|
||||||
|
$actual = $absCases->getCaseNumber();
|
||||||
|
$this->assertEquals($properties['caseNumber'], $actual);
|
||||||
|
$actual = $absCases->getFromCaseNumber();
|
||||||
|
$this->assertEquals($properties['caseNumberFrom'], $actual);
|
||||||
|
$actual = $absCases->getToCaseNumber();
|
||||||
|
$this->assertEquals($properties['caseNumberTo'], $actual);
|
||||||
$actual = $absCases->getValueToSearch();
|
$actual = $absCases->getValueToSearch();
|
||||||
$this->assertEquals($properties['search'], $actual);
|
$this->assertEquals($properties['search'], $actual);
|
||||||
$actual = $absCases->getCaseUid();
|
$actual = $absCases->getCaseUid();
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use ProcessMaker\BusinessModel\Cases\Search;
|
||||||
|
use ProcessMaker\Model\Delegation;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InboxTest
|
||||||
|
*
|
||||||
|
* @coversDefaultClass \ProcessMaker\BusinessModel\Cases\Search
|
||||||
|
*/
|
||||||
|
class SearchTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up function.
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Delegation::truncate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create participated cases factories
|
||||||
|
*
|
||||||
|
* @param int
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function createSearch($rows = 10)
|
||||||
|
{
|
||||||
|
$delegation = factory(Delegation::class, $rows)->states('foreign_keys')->create();
|
||||||
|
|
||||||
|
return $delegation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getData method without filters
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_get_data_method_without_filters()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
$result = $search->getData();
|
||||||
|
// This assert that the expected numbers of results are returned
|
||||||
|
$this->assertEquals(count($cases), count($result));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getData with case number
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_get_data_method_with_specific_case_number()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
$search->setCaseNumber($cases[0]->APP_NUMBER);
|
||||||
|
// Set order by column value
|
||||||
|
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||||
|
$result = $search->getData();
|
||||||
|
// This assert that the expected numbers of results are returned
|
||||||
|
$this->assertEquals($cases[0]->APP_NUMBER, $result[0]['APP_NUMBER']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getData with priority
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_get_data_method_with_specific_priority()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
$search->setPriority(3);
|
||||||
|
// Set order by column value
|
||||||
|
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||||
|
$result = $search->getData();
|
||||||
|
// This assert that the expected numbers of results are returned
|
||||||
|
$this->assertEquals(3, $result[0]['DEL_PRIORITY']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getData with process
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_get_data_method_with_specific_process()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
$search->setProcessId($cases[0]->PRO_ID);
|
||||||
|
// Set order by column value
|
||||||
|
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||||
|
$result = $search->getData();
|
||||||
|
// This assert that the expected numbers of results are returned
|
||||||
|
$this->assertEquals($cases[0]->PRO_ID, $result[0]['PRO_ID']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getData with task
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_get_data_method_with_specific_task()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
$search->setTaskId($cases[0]->TAS_ID);
|
||||||
|
// Set order by column value
|
||||||
|
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||||
|
$result = $search->getData();
|
||||||
|
// This assert that the expected numbers of results are returned
|
||||||
|
$this->assertEquals($cases[0]->TAS_ID, $result[0]['TAS_ID']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getData with user
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getData()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_get_data_method_with_specific_user()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
$search->setUserId($cases[0]->USR_ID);
|
||||||
|
// Set order by column value
|
||||||
|
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||||
|
$result = $search->getData();
|
||||||
|
// This assert that the expected numbers of results are returned
|
||||||
|
$this->assertEquals($cases[0]->USR_ID, $result[0]['USR_ID']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the getCounter method
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases\Search::getCounter()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_the_counter_for_search()
|
||||||
|
{
|
||||||
|
// Create factories related to the delegation cases
|
||||||
|
$cases = $this->createSearch();
|
||||||
|
// Create new Search object
|
||||||
|
$search = new Search();
|
||||||
|
// Set order by column value
|
||||||
|
$search->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
|
||||||
|
$total = $search->getCounter();
|
||||||
|
$this->assertEquals(count($cases), $total);;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ class AbstractCases implements CasesInterface
|
|||||||
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'];
|
||||||
|
|
||||||
// Filter by category from a process, know as "$category" in the old lists classes
|
// Filter by category from a process, know as "$category" in the old lists classes
|
||||||
private $categoryUid = '';
|
private $categoryUid = '';
|
||||||
@@ -26,6 +27,9 @@ class AbstractCases implements CasesInterface
|
|||||||
// Filter by process using the Id field
|
// Filter by process using the Id field
|
||||||
private $processId = 0;
|
private $processId = 0;
|
||||||
|
|
||||||
|
// Filter by task using the Id field
|
||||||
|
private $taskId = 0;
|
||||||
|
|
||||||
// Filter by user, know as "$user" in the old lists classes
|
// Filter by user, know as "$user" in the old lists classes
|
||||||
private $userUid = '';
|
private $userUid = '';
|
||||||
|
|
||||||
@@ -44,6 +48,9 @@ class AbstractCases implements CasesInterface
|
|||||||
// Filter by risk status, know as "$filterStatus" in the old list "inbox" class
|
// Filter by risk status, know as "$filterStatus" in the old list "inbox" class
|
||||||
private $riskStatus = '';
|
private $riskStatus = '';
|
||||||
|
|
||||||
|
// Filter by specific priority
|
||||||
|
private $priority = 0;
|
||||||
|
|
||||||
// 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 = '';
|
||||||
|
|
||||||
@@ -53,6 +60,10 @@ class AbstractCases implements CasesInterface
|
|||||||
// 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
|
||||||
|
private $fromCaseNumber = 0;
|
||||||
|
private $toCaseNumber = 0;
|
||||||
|
|
||||||
// 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 = [];
|
||||||
|
|
||||||
@@ -143,6 +154,26 @@ class AbstractCases implements CasesInterface
|
|||||||
return $this->processId;
|
return $this->processId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set task Id value
|
||||||
|
*
|
||||||
|
* @param int $taskId
|
||||||
|
*/
|
||||||
|
public function setTaskId(int $taskId)
|
||||||
|
{
|
||||||
|
$this->taskId = $taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get task Id value
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTaskId()
|
||||||
|
{
|
||||||
|
return $this->taskId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set User Uid value
|
* Set User Uid value
|
||||||
*
|
*
|
||||||
@@ -299,7 +330,7 @@ class AbstractCases implements CasesInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get risk status
|
* Get risk value
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -308,6 +339,40 @@ class AbstractCases implements CasesInterface
|
|||||||
return $this->riskStatus;
|
return $this->riskStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set priority value
|
||||||
|
*
|
||||||
|
* @param int $priority
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function setPriority(int $priority)
|
||||||
|
{
|
||||||
|
// Validate the priority value
|
||||||
|
if (!empty($priority)) {
|
||||||
|
if (!empty(self::PRIORITIES[$priority])) {
|
||||||
|
$priorityCode = $priority;
|
||||||
|
} else {
|
||||||
|
throw new Exception("Priority value {$priority} is not valid.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// List all priorities
|
||||||
|
$priorityCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->priority = $priorityCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get priority status
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPriority()
|
||||||
|
{
|
||||||
|
return $this->priority;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Case status
|
* Set Case status
|
||||||
*
|
*
|
||||||
@@ -388,6 +453,38 @@ class AbstractCases implements CasesInterface
|
|||||||
return $this->caseNumber;
|
return $this->caseNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set range of Case Number
|
||||||
|
*
|
||||||
|
* @param int $from
|
||||||
|
* @param int $to
|
||||||
|
*/
|
||||||
|
public function setRangeCaseNumber(int $from, int $to)
|
||||||
|
{
|
||||||
|
$this->fromCaseNumber = $from;
|
||||||
|
$this->toCaseNumber = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get from Case Number
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getFromCaseNumber()
|
||||||
|
{
|
||||||
|
return $this->fromCaseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get to Case Number
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getToCaseNumber()
|
||||||
|
{
|
||||||
|
return $this->toCaseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Cases Uids
|
* Set Cases Uids
|
||||||
*
|
*
|
||||||
@@ -626,10 +723,26 @@ class AbstractCases implements CasesInterface
|
|||||||
$this->setProcessUid($properties['process']);
|
$this->setProcessUid($properties['process']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($properties['task'])) {
|
||||||
|
$this->setTaskId($properties['task']);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($properties['user'])) {
|
if (!empty($properties['user'])) {
|
||||||
$this->setUserUid($properties['user']);
|
$this->setUserUid($properties['user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($properties['priority'])) {
|
||||||
|
$this->setPriority($properties['priority']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($properties['caseNumber'])) {
|
||||||
|
$this->setCaseNumber($properties['caseNumber']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($properties['caseNumberFrom']) && !empty($properties['caseNumberTo'])) {
|
||||||
|
$this->setRangeCaseNumber($properties['caseNumberFrom'], $properties['caseNumberTo']);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($properties['search'])) {
|
if (!empty($properties['search'])) {
|
||||||
$this->setValueToSearch($properties['search']);
|
$this->setValueToSearch($properties['search']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ProcessMaker\BusinessModel\Cases;
|
||||||
|
|
||||||
|
use ProcessMaker\Model\Delegation;
|
||||||
|
|
||||||
|
class Search extends AbstractCases
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the data corresponding to advanced search
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getData()
|
||||||
|
{
|
||||||
|
$query = Delegation::query()->select();
|
||||||
|
|
||||||
|
// Filter by case number
|
||||||
|
$query->case($this->getCaseNumber());
|
||||||
|
|
||||||
|
// Filter by case number: from and to
|
||||||
|
if ($this->getFromCaseNumber() > 0 && $this->getToCaseNumber() > 0) {
|
||||||
|
$query->rangeOfCases($this->getFromCaseNumber(), $this->getToCaseNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo: Filter by case title, pending from other PRD
|
||||||
|
|
||||||
|
// Filter by category
|
||||||
|
$query->categoryProcess($this->getCategoryUid());
|
||||||
|
|
||||||
|
// 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
|
||||||
|
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
|
||||||
|
|
||||||
|
// The limit by clause
|
||||||
|
$query->offset($this->getOffset())->limit($this->getLimit());
|
||||||
|
|
||||||
|
//Execute the query
|
||||||
|
$results = $query->get();
|
||||||
|
|
||||||
|
//Return the values as an array format
|
||||||
|
return $results->values()->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of rows corresponding to the advanced search
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getCounter()
|
||||||
|
{
|
||||||
|
$query = Delegation::query()->select();
|
||||||
|
|
||||||
|
// Return the number of rows
|
||||||
|
return $query->count();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,18 @@ class Delegation extends Model
|
|||||||
return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID');
|
return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope a query to only include specific priority
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @param int $priority
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopePriority($query, int $priority)
|
||||||
|
{
|
||||||
|
return $query->where('DEL_PRIORITY', $priority);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scope a query to only include open threads
|
* Scope a query to only include open threads
|
||||||
*
|
*
|
||||||
@@ -73,7 +85,7 @@ class Delegation extends Model
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Builder
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
*/
|
*/
|
||||||
public function scopeIndex($query, $index)
|
public function scopeIndex($query, int $index)
|
||||||
{
|
{
|
||||||
return $query->where('DEL_INDEX', '=', $index);
|
return $query->where('DEL_INDEX', '=', $index);
|
||||||
}
|
}
|
||||||
@@ -177,6 +189,21 @@ 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
|
||||||
*
|
*
|
||||||
@@ -305,7 +332,7 @@ class Delegation extends Model
|
|||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Builder
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
*/
|
*/
|
||||||
public function scopeTask($query, $task)
|
public function scopeTask($query, int $task)
|
||||||
{
|
{
|
||||||
return $query->where('APP_DELEGATION.TAS_ID', '=', $task);
|
return $query->where('APP_DELEGATION.TAS_ID', '=', $task);
|
||||||
}
|
}
|
||||||
@@ -1457,37 +1484,4 @@ class Delegation extends Model
|
|||||||
|
|
||||||
return $thread;
|
return $thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper to get the priority code from a given value
|
|
||||||
*
|
|
||||||
* @param int $priorityValue
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static function getPriorityCode($priorityValue)
|
|
||||||
{
|
|
||||||
if (!empty(self::PRIORITIES_MAP[$priorityValue])) {
|
|
||||||
$priorityCode = self::PRIORITIES_MAP[$priorityValue];
|
|
||||||
} else {
|
|
||||||
throw new Exception("Priority value {$priorityValue} is not valid.");
|
|
||||||
}
|
|
||||||
return $priorityCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper to get the priority label from a given value
|
|
||||||
*
|
|
||||||
* @param int $priorityValue
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getPriorityLabel($priorityValue)
|
|
||||||
{
|
|
||||||
$priorityCode = self::getPriorityCode($priorityValue);
|
|
||||||
|
|
||||||
return G::LoadTranslation("ID_PRIORITY_{$priorityCode}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user