This commit is contained in:
Andrea Adamczyk
2019-06-11 07:51:19 -04:00
committed by Paula Quispe
parent e1e6ae3fcd
commit 9e16fc0bd8
5 changed files with 784 additions and 8 deletions

View File

@@ -28,6 +28,7 @@ $factory->define(\ProcessMaker\Model\Process::class, function(Faker $faker) {
// Create a process with the foreign keys // Create a process with the foreign keys
$factory->state(\ProcessMaker\Model\Process::class, 'foreign_keys', function (Faker $faker) { $factory->state(\ProcessMaker\Model\Process::class, 'foreign_keys', function (Faker $faker) {
$user = factory(\ProcessMaker\Model\User::class)->create(); $user = factory(\ProcessMaker\Model\User::class)->create();
return [ return [
'PRO_UID' => G::generateUniqueID(), 'PRO_UID' => G::generateUniqueID(),
'PRO_TITLE' => $faker->sentence(3), 'PRO_TITLE' => $faker->sentence(3),

View File

@@ -0,0 +1,671 @@
<?php
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases;
use Tests\TestCase;
use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
/**
* Class InboxTest
*
* @coversDefaultClass ProcessMaker\BusinessModel\Cases\Inbox
* @package Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel\Cases
*/
class InboxTest extends TestCase
{
use DatabaseTransactions;
/**
* It tests the getData method without filters
*
* @covers ::getData()
* @test
*/
public function it_should_test_get_data_method_without_filters()
{
//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
]);
//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');
//Count how many results are expected
$count = Application::where('APP_STATUS', 'TO_DO')->count();
//Call to getData method
$res = $inbox->getData();
//This assert that the expected numbers of results are returned
$this->assertEquals($count, count($res));
}
/**
* It tests the getData method with Risk Filter
*
* @covers ::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
*
* @covers ::getData()
* @test
*/
public function it_it_should_test_get_data_method_with_Category_Filter()
{
//Create process
$process = factory(Process::class)->create(
['PRO_CATEGORY' => '248565910552bd7d6006458065223611']
);
//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
]);
//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 Category value
$inbox->setCategoryUid('248565910552bd7d6006458065223611');
//Count how many results are expected
$count = Application::where('APP_STATUS', 'TO_DO')->where('PRO_UID', $process->PRO_UID)->count();
//Call to getData method
$res = $inbox->getData();
//
$this->assertEquals($count, count($res));
}
/**
* It tests the getData method with Process Filter
*
* @covers ::getData()
* @test
*/
public function it_it_should_test_get_data_method_with_Process_Filter()
{
//Create process
$process = factory(Process::class, 2)->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[0]->PRO_UID,
]);
//Create the register in delegation relate to self-service
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[0]->PRO_ID
]);
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
$inbox->setProcessId($process[1]->PRO_ID);
$res = $inbox->getData();
$this->assertEmpty($res);
$inbox->setProcessId($process[0]->PRO_ID);
$count = Application::where('APP_STATUS', 'TO_DO')->count();
$res = $inbox->getData();
$this->assertEquals($count, count($res));
}
/**
* It tests the getData method using OrderBy
*
* @covers ::getData()
* @test
*/
public function it_should_return_inbox_sort_by_case_number()
{
//Create process
$process = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create tasks
$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
]);
$count = Application::where('APP_STATUS', 'TO_DO')->count();
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
$inbox->setOrderDirection('DESC');
$res = $inbox->getData();
// This asserts the order is for APP_NUMBER from highest to lowest
$this->assertGreaterThan($res[$count - 1]['APP_NUMBER'], $res[0]['APP_NUMBER']);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
$inbox->setOrderDirection('ASC');
$res = $inbox->getData();
// This asserts the order is for APP_NUMBER from highest to lowest
$this->assertLessThan($res[$count - 1]['APP_NUMBER'], $res[0]['APP_NUMBER']);
}
/**
* It tests the getData method using OrderBy
*
* @covers ::getData()
* @test
*/
public function it_should_return_inbox_sort_by_task_title()
{
//Create process
$process = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create tasks
$task = factory(Task::class)->create([
'TAS_ID' => 20,
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process->PRO_UID,
]);
$task = factory(Task::class)->create([
'TAS_ID' => 10,
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process->PRO_UID,
]);
//Create the register in delegation
factory(Delegation::class, 10)->create([
'TAS_ID' => 20,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID
]);
factory(Delegation::class, 10)->create([
'TAS_ID' => 10,
'DEL_THREAD_STATUS' => 'OPEN',
'USR_UID' => $user->USR_UID,
'USR_ID' => $user->USR_ID,
'PRO_ID' => $process->PRO_ID
]);
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('TASK.TAS_ID');
$inbox->setOrderDirection('DESC');
$res = $inbox->getData();
// This asserts the order is for TAS_ID from highest to lowest
$this->assertEquals(20, $res[0]['TAS_ID']);
$this->assertEquals(10, $res[count($res) - 1]['TAS_ID']);
$inbox->setOrderByColumn('TASK.TAS_ID');
$inbox->setOrderDirection('ASC');
$res = $inbox->getData();
// This asserts the order is for TAS_ID from lowest to highest
$this->assertEquals(10, $res[0]['TAS_ID']);
$this->assertEquals(20, $res[count($res) - 1]['TAS_ID']);
}
/**
* It tests the getData method using OrderBy
*
* @covers ::getData()
* @test
*/
public function it_should_return_inbox_sort_by_case_title()
{
//Create process
$process = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create tasks
$task = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process->PRO_UID,
]);
//Create the register in delegation
factory(Delegation::class, 20)->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
]);
$count = Application::where('APP_STATUS', 'TO_DO')->count();
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_TITLE');
$inbox->setOrderDirection('DESC');
$res = $inbox->getData();
// This asserts the order is for APP_TITLE from highest to lowest
$this->assertGreaterThan($res[$count - 1]['APP_TITLE'], $res[0]['APP_TITLE']);
$inbox->setOrderByColumn('APP_TITLE');
$inbox->setOrderDirection('ASC');
$res = $inbox->getData();
// This asserts the order is for APP_TITLE from highest to lowest
$this->assertLessThan($res[$count - 1]['APP_TITLE'], $res[0]['APP_TITLE']);
}
/**
* It tests the getData method using OrderBy
*
* @covers ::getData()
* @test
*/
public function it_should_return_inbox_sort_by_process()
{
//Create process
$process1 = factory(Process::class)->create();
$process2 = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create tasks
$task = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->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' => $process1->PRO_ID
]);
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' => $process2->PRO_ID
]);
$count = Application::where('APP_STATUS', 'TO_DO')->count();
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('PROCESS.PRO_ID');
$inbox->setOrderDirection('DESC');
$res = $inbox->getData();
// This asserts the order is for PRO_ID from highest to lowest
$this->assertGreaterThan($res[$count - 1]['PRO_ID'], $res[0]['PRO_ID']);
$inbox->setOrderByColumn('PROCESS.PRO_ID');
$inbox->setOrderDirection('ASC');
$res = $inbox->getData();
// This asserts the order is for PRO_ID from highest to lowest
$this->assertLessThan($res[$count - 1]['PRO_ID'], $res[0]['PRO_ID']);
}
/**
* It tests the getData method using OrderBy
*
* @covers ::getData()
* @test
*/
public function it_should_return_inbox_sort_by_due_date()
{
//Create process
$process1 = factory(Process::class)->create();
$process2 = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create tasks
$task = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->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' => $process1->PRO_ID
]);
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' => $process2->PRO_ID
]);
$count = Application::where('APP_STATUS', 'TO_DO')->count();
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('DEL_TASK_DUE_DATE');
$inbox->setOrderDirection('DESC');
$res = $inbox->getData();
// This asserts the order is for DEL_TASK_DUE_DATE from highest to lowest
$this->assertGreaterThan($res[$count - 1]['DEL_TASK_DUE_DATE'], $res[0]['DEL_TASK_DUE_DATE']);
$inbox->setOrderByColumn('DEL_TASK_DUE_DATE');
$inbox->setOrderDirection('ASC');
$res = $inbox->getData();
// This asserts the order is for DEL_TASK_DUE_DATE from highest to lowest
$this->assertLessThan($res[$count - 1]['DEL_TASK_DUE_DATE'], $res[0]['DEL_TASK_DUE_DATE']);
}
/**
* It tests the getData method using OrderBy
*
* @covers ::getData()
* @test
*/
public function it_should_return_inbox_sort_by_last_modified()
{
//Create process
$process1 = factory(Process::class)->create();
$process2 = factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
//Create tasks
$task = factory(Task::class)->create([
'TAS_ASSIGN_TYPE' => '',
'TAS_GROUP_VARIABLE' => '',
'PRO_UID' => $process1->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' => $process1->PRO_ID
]);
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' => $process2->PRO_ID
]);
$count = Application::where('APP_STATUS', 'TO_DO')->count();
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_UPDATE_DATE');
$inbox->setOrderDirection('DESC');
$res = $inbox->getData();
// This asserts the order is for APP_UPDATE_DATE from highest to lowest
$this->assertGreaterThan($res[$count - 1]['APP_UPDATE_DATE'], $res[0]['APP_UPDATE_DATE']);
$inbox->setOrderByColumn('APP_UPDATE_DATE');
$inbox->setOrderDirection('ASC');
$res = $inbox->getData();
// This asserts the order is for APP_UPDATE_DATE from highest to lowest
$this->assertLessThan($res[$count - 1]['APP_UPDATE_DATE'], $res[0]['APP_UPDATE_DATE']);
}
/**
* It tests the getData method with pager
*
* @covers ::getData()
* @test
*/
public function it_it_should_test_get_data_method_with_pager()
{
//Create process
$process = factory(Process::class)->create(
['PRO_CATEGORY' => '248565910552bd7d6006458065223611']
);
//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 relate to self-service
factory(Delegation::class, 50)->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
]);
$inbox = new Inbox();
$inbox->setUserUid($user->USR_UID);
$inbox->setUserId($user->USR_ID);
$inbox->setOrderByColumn('APP_DELEGATION.APP_NUMBER');
$inbox->setOffset(5);
$inbox->setLimit(2);
$res = $inbox->getData();
$this->assertEquals(2, count($res));
}
/**
* It tests the getCounter method
*
* @covers @covers ::getCounter()
* @test
*/
public function it_should_test_the_counter_for_list_inbox()
{
//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 relate to self-service
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
]);
//Create the value to compare with the result
$count = Application::where('APP_STATUS', 'TO_DO')->count();
//Create the Inbox object
$inbox = new Inbox();
$inbox->setUserId($user->USR_ID);
$res = $inbox->getCounter();
//Assert the result of getCounter method
$this->assertEquals($count, $res);
}
}

View File

@@ -2,7 +2,73 @@
namespace ProcessMaker\BusinessModel\Cases; namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Task;
class Inbox extends AbstractCases class Inbox extends AbstractCases
{ {
/**
* Get the data corresponding to List Inbox
*
* @return array
*/
public function getData()
{
// Start the query for get the cases related to the user
$query = Delegation::query()->select();
// Scope that sets the queries for List Inbox
$query->inbox($this->getUserId());
// Scope that joins with the process and/or for an specific category in the process
$query->categoryProcess($this->getCategoryUid());
switch ($this->getRiskStatus()) {
case 'ON_TIME':
// Scope that search for the ON_TIME cases
$query->onTime();
break;
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;
}
if ($this->getProcessId() != '') {
// Scope to search for an specific process
$query->processId($this->getProcessId());
}
// 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 List Inbox
*
* @return int
*/
public function getCounter()
{
$query = Delegation::query()->select();
// Scope that sets the queries for List Inbox
$query->inbox($this->getUserId());
// Return the number of rows
return $query->count();
}
} }

View File

@@ -273,7 +273,7 @@ class Delegation extends Model
} }
/** /**
* Scope a join with task and include a specific task assign type: * Scope a join with task and exclude a specific task assign type:
* NORMAL|ADHOC|SUBPROCESS|HIDDEN|GATEWAYTOGATEWAY|WEBENTRYEVENT|END-MESSAGE-EVENT|START-MESSAGE-EVENT| * NORMAL|ADHOC|SUBPROCESS|HIDDEN|GATEWAYTOGATEWAY|WEBENTRYEVENT|END-MESSAGE-EVENT|START-MESSAGE-EVENT|
* INTERMEDIATE-THROW-MESSAGE-EVENT|INTERMEDIATE-CATCH-MESSAGE-EVENT|SCRIPT-TASK|START-TIMER-EVENT| * INTERMEDIATE-THROW-MESSAGE-EVENT|INTERMEDIATE-CATCH-MESSAGE-EVENT|SCRIPT-TASK|START-TIMER-EVENT|
* INTERMEDIATE-CATCH-TIMER-EVENT|END-EMAIL-EVENT|INTERMEDIATE-THROW-EMAIL-EVENT|SERVICE-TASK * INTERMEDIATE-CATCH-TIMER-EVENT|END-EMAIL-EVENT|INTERMEDIATE-THROW-EMAIL-EVENT|SERVICE-TASK
@@ -283,11 +283,11 @@ class Delegation extends Model
* *
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function scopeSpecificTaskTypes($query, array $taskTypes) public function scopeExcludeTaskTypes($query, array $taskTypes)
{ {
$query->join('TASK', function ($join) use ($taskTypes) { $query->join('TASK', function ($join) use ($taskTypes) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID') $join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->whereNotIn('TASK.TAS_TYPE', '=', $taskTypes); ->whereNotIn('TASK.TAS_TYPE', $taskTypes);
}); });
return $query; return $query;
@@ -331,6 +331,31 @@ class Delegation extends Model
return $query; return $query;
} }
/**
* Scope the Inbox cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $userId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeInbox($query, $userId)
{
// This scope is for the join with the APP_DELEGATION table
$query->appStatusId(2);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Scope that establish that the DEL_THREAD_STATUS must be OPEN
$query->threadOpen();
// Scope that return the results for an specific user
$query->userId($userId);
return $query;
}
/** /**
* Scope a self service cases * Scope a self service cases
* *
@@ -593,7 +618,7 @@ class Delegation extends Model
} }
// Add any sort if needed // Add any sort if needed
if($sort) { if ($sort) {
switch ($sort) { switch ($sort) {
case 'APP_NUMBER': case 'APP_NUMBER':
$query->orderBy('APP_DELEGATION.APP_NUMBER', $dir); $query->orderBy('APP_DELEGATION.APP_NUMBER', $dir);
@@ -628,9 +653,9 @@ class Delegation extends Model
// Convert to an array as our results must be an array // Convert to an array as our results must be an array
$item = json_decode(json_encode($item), true); $item = json_decode(json_encode($item), true);
// If it's assigned, fetch the user // If it's assigned, fetch the user
if($item['USR_ID']) { if ($item['USR_ID']) {
$user = User::where('USR_ID', $item['USR_ID'])->first(); $user = User::where('USR_ID', $item['USR_ID'])->first();
} else { } else {
$user = null; $user = null;
} }
$process = Process::where('PRO_ID', $item['PRO_ID'])->first(); $process = Process::where('PRO_ID', $item['PRO_ID'])->first();
@@ -717,8 +742,10 @@ class Delegation extends Model
// Build the main array to return // Build the main array to return
$arrayData = [ $arrayData = [
'APP_STATUS' => 'PARTICIPATED', // Value hardcoded because we need to return the same structure previously sent 'APP_STATUS' => 'PARTICIPATED',
'DEL_INDEX' => [], // Initialize this item like an array // Value hardcoded because we need to return the same structure previously sent
'DEL_INDEX' => [],
// Initialize this item like an array
'PRO_UID' => $first->PRO_UID 'PRO_UID' => $first->PRO_UID
]; ];

View File

@@ -23,6 +23,17 @@ class Task extends Model
"INTERMEDIATE-CATCH-TIMER-EVENT" "INTERMEDIATE-CATCH-TIMER-EVENT"
]; ];
const DUMMY_TASKS = [
'END-EMAIL-EVENT',
'INTERMEDIATE-CATCH-TIMER-EVENT',
'INTERMEDIATE-THROW-EMAIL-EVENT',
'START-TIMER-EVENT',
'SCRIPT-TASK',
'WEBENTRYEVENT',
'END-MESSAGE-EVENT',
'GATEWAYTOGATEWAY'
];
public function process() public function process()
{ {
return $this->belongsTo(Process::class, 'PRO_UID', 'PRO_UID'); return $this->belongsTo(Process::class, 'PRO_UID', 'PRO_UID');