Files
luos/workflow/engine/src/ProcessMaker/BusinessModel/Cases/Supervising.php

252 lines
9.5 KiB
PHP
Raw Normal View History

2020-10-22 16:34:26 -04:00
<?php
namespace ProcessMaker\BusinessModel\Cases;
2020-12-16 17:47:42 -04:00
use ProcessMaker\Model\AppNotes;
2020-10-22 16:34:26 -04:00
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\ProcessUser;
2021-07-12 11:38:27 -04:00
use ProcessMaker\Model\User;
2020-10-22 16:34:26 -04:00
class Supervising extends AbstractCases
{
2020-11-11 10:38:08 -04:00
// Columns to see in the cases list
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
2020-12-09 19:04:05 -04:00
'APP_DELEGATION.DEL_TITLE', // Case Title
2020-11-11 10:38:08 -04:00
'PROCESS.PRO_TITLE', // Process Name
2021-07-12 11:38:27 -04:00
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
'APPLICATION.APP_CREATE_DATE', // Start Date
'APPLICATION.APP_FINISH_DATE', // Finish Date
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
'APP_DELEGATION.DEL_PREVIOUS', // Previous
2021-01-12 14:48:38 -04:00
'USERS.USR_ID', // Current UserId
2020-11-11 10:38:08 -04:00
// Additional column for other functionalities
2020-11-25 18:11:22 -04:00
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
2020-12-07 17:07:26 -04:00
'APP_DELEGATION.PRO_UID', // Process Uid for Case notes
'APP_DELEGATION.TAS_UID', // Task Uid for Case notes
2020-11-11 10:38:08 -04:00
];
/**
* Get the columns related to the cases list
* @return array
*/
public function getColumnsView()
{
return $this->columnsView;
}
2020-11-25 18:11:22 -04:00
/**
* 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());
}
2021-07-08 12:55:24 -04:00
// Filter only cases by specific cases like [1,3,5]
if (!empty($this->getCasesNumbers()) && empty($this->getRangeCasesFromTo())) {
$query->specificCases($this->getCasesNumbers());
}
// Filter only cases by range of cases like ['1-5', '10-15']
if (!empty($this->getRangeCasesFromTo()) && empty($this->getCasesNumbers())) {
$query->rangeOfCases($this->getRangeCasesFromTo());
}
// Filter cases mixed by range of cases and specific cases like '1,3-5,8'
if (!empty($this->getCasesNumbers()) && !empty($this->getRangeCasesFromTo())) {
$query->casesOrRangeOfCases($this->getCasesNumbers(), $this->getRangeCasesFromTo());
}
2020-11-25 18:11:22 -04:00
// Specific case title
if (!empty($this->getCaseTitle())) {
2021-10-18 15:23:11 -04:00
// Get the result
2021-12-03 18:37:03 -04:00
$result = Delegation::casesThreadTitle($this->getCaseTitle());
2021-10-18 15:23:11 -04:00
// Add the filter
$query->specificCases($result);
2020-11-25 18:11:22 -04:00
}
// 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;
}
2020-10-22 16:34:26 -04:00
/**
* Gets the data for the Cases list Review
*
* @return array
*/
public function getData()
{
2020-11-11 10:38:08 -04:00
// Get the list of processes of the supervisor
2020-10-22 16:34:26 -04:00
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
2020-11-25 18:11:22 -04:00
// We will prepare the queries if the user is supervisor
if (!empty($processes)) {
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
2021-03-30 10:03:46 -04:00
// Join with application
$query->joinApplication();
2020-11-25 18:11:22 -04:00
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
2021-03-30 10:03:46 -04:00
// Only cases in TO_DO
2020-12-09 19:04:05 -04:00
$query->caseTodo();
2020-11-25 18:11:22 -04:00
// Scope the specific array of processes supervising
$query->processInList($processes);
2021-03-30 10:03:46 -04:00
// Get only the last thread
$query->lastThread();
2020-11-25 18:11:22 -04:00
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
//The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
//The limit clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {
// 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
$item['APP_CREATE_DATE_LABEL'] = !empty($item['APP_CREATE_DATE']) ? applyMaskDateEnvironment($item['APP_CREATE_DATE']): null;
$item['APP_FINISH_DATE_LABEL'] = !empty($item['APP_FINISH_DATE']) ? applyMaskDateEnvironment($item['APP_FINISH_DATE']): null;
// Calculate duration
$startDate = (string)$item['APP_CREATE_DATE'];
$endDate = !empty($item['APP_FINISH_DATE']) ? $item['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
2020-12-16 17:47:42 -04:00
// Get total case notes
$item['CASE_NOTES_COUNT'] = AppNotes::total($item['APP_NUMBER']);
2020-12-07 17:07:26 -04:00
// Get the detail related to the open thread
2021-03-30 10:03:46 -04:00
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
2021-08-31 11:04:07 -04:00
$result = [];
2021-09-15 13:12:48 -04:00
$result['THREAD_TASKS'] = [];
$result['THREAD_TITLES'] = [];
2021-03-30 10:03:46 -04:00
foreach ($taskPending as $thread) {
$thread['APP_STATUS'] = $item['APP_STATUS'];
2021-08-31 11:04:07 -04:00
$information = $this->threadInformation($thread);
$result['THREAD_TASKS'][] = $information['THREAD_TASK'];
$result['THREAD_TITLES'][] = $information['THREAD_TITLE'];
2020-12-07 17:07:26 -04:00
}
2021-08-31 11:04:07 -04:00
$item['PENDING'] = $result['THREAD_TASKS'];
$item['THREAD_TITLES'] = $result['THREAD_TITLES'];
// Get send by related to the previous index
2021-07-12 11:38:27 -04:00
$previousThread = Delegation::getThreadInfo($item['APP_NUMBER'], $item['DEL_PREVIOUS']);
$userInfo = !empty($previousThread) ? User::getInformation($previousThread['USR_ID']) : [];
$result = [];
$result['del_previous'] = $item['DEL_PREVIOUS'];
$result['user_tooltip'] = $userInfo;
$item['SEND_BY_INFO'] = $result;
2020-10-22 16:34:26 -04:00
2020-11-25 18:11:22 -04:00
return $item;
});
2020-11-11 10:38:08 -04:00
2020-11-25 18:11:22 -04:00
return $results->values()->toArray();
} else {
return [];
}
2020-10-22 16:34:26 -04:00
}
/**
2020-12-14 15:24:08 -04:00
* Count how many cases the user has in Supervising, does not apply filters
2020-10-22 16:34:26 -04:00
*
* @return int
*/
public function getCounter()
{
2020-12-09 23:21:32 +00:00
// Get base query
2020-11-11 10:38:08 -04:00
$query = Delegation::query()->select();
2021-01-18 10:45:24 -04:00
// Join with application
$query->joinApplication();
// Only cases in to_do
$query->caseTodo();
// Only open threads
2021-07-26 13:13:26 -04:00
$query->threadOpen();
2021-03-30 10:03:46 -04:00
// For parallel threads the distinct by APP_NUMBER is important
2020-12-09 23:21:32 +00:00
$query->distinct();
2020-11-11 10:38:08 -04:00
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// Scope the specific array of processes supervising
$query->processInList($processes);
2020-12-09 23:21:32 +00:00
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
2020-10-22 16:34:26 -04:00
}
2020-12-14 15:24:08 -04:00
2021-08-19 15:23:25 -04:00
/**
* Count if the user has at least one case in the list
*
* @return bool
*/
public function atLeastOne()
{
// This class does not require this value
return false;
}
2020-12-14 15:24:08 -04:00
/**
* Count how many cases the user has in Supervising, needs to apply filters
*
* @return int
*/
public function getPagingCounters()
{
// Get base query
$query = Delegation::query()->select();
2021-01-18 10:45:24 -04:00
// Join with application
$query->joinApplication();
// Only cases in to_do
$query->caseTodo();
// Only open threads
2021-07-26 13:13:26 -04:00
$query->threadOpen();
2021-03-30 10:03:46 -04:00
// For parallel threads the distinct by APP_NUMBER is important
2020-12-14 15:24:08 -04:00
$query->distinct();
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// Scope the specific array of processes supervising
$query->processInList($processes);
// Apply filters
$this->filters($query);
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
}
2020-10-22 16:34:26 -04:00
}