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

@@ -2,7 +2,73 @@
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Task;
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|
* 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
@@ -283,11 +283,11 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSpecificTaskTypes($query, array $taskTypes)
public function scopeExcludeTaskTypes($query, array $taskTypes)
{
$query->join('TASK', function ($join) use ($taskTypes) {
$join->on('APP_DELEGATION.TAS_ID', '=', 'TASK.TAS_ID')
->whereNotIn('TASK.TAS_TYPE', '=', $taskTypes);
->whereNotIn('TASK.TAS_TYPE', $taskTypes);
});
return $query;
@@ -331,6 +331,31 @@ class Delegation extends Model
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
*
@@ -593,7 +618,7 @@ class Delegation extends Model
}
// Add any sort if needed
if($sort) {
if ($sort) {
switch ($sort) {
case 'APP_NUMBER':
$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
$item = json_decode(json_encode($item), true);
// If it's assigned, fetch the user
if($item['USR_ID']) {
if ($item['USR_ID']) {
$user = User::where('USR_ID', $item['USR_ID'])->first();
} else {
} else {
$user = null;
}
$process = Process::where('PRO_ID', $item['PRO_ID'])->first();
@@ -717,8 +742,10 @@ class Delegation extends Model
// Build the main array to return
$arrayData = [
'APP_STATUS' => 'PARTICIPATED', // Value hardcoded because we need to return the same structure previously sent
'DEL_INDEX' => [], // Initialize this item like an array
'APP_STATUS' => 'PARTICIPATED',
// 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
];

View File

@@ -23,6 +23,17 @@ class Task extends Model
"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()
{
return $this->belongsTo(Process::class, 'PRO_UID', 'PRO_UID');