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

170 lines
6.0 KiB
PHP
Raw Normal View History

<?php
namespace ProcessMaker\BusinessModel\Cases;
2020-11-11 10:38:08 -04:00
use G;
2021-03-30 10:03:46 -04:00
use ProcessMaker\Model\Application;
2019-06-14 13:05:21 -04:00
use ProcessMaker\Model\Delegation;
2021-07-12 11:38:27 -04:00
use ProcessMaker\Model\User;
2019-06-14 13:05:21 -04:00
class Draft 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
2021-07-12 11:38:27 -04:00
'TASK.TAS_TITLE', // Task
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
'APP_DELEGATION.DEL_PREVIOUS', // Previous
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())) {
2020-12-09 19:04:05 -04:00
$query->title($this->getCaseTitle());
2020-11-25 18:11:22 -04:00
}
// 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;
}
2019-06-14 13:05:21 -04:00
/**
* Get data self-services cases by user
*
* @return array
*/
public function getData()
{
2020-11-11 10:38:08 -04:00
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with application for add the initial scope for DRAFT cases
2019-06-14 13:05:21 -04:00
$query->draft($this->getUserId());
2020-11-25 18:11:22 -04:00
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
2019-06-14 13:05:21 -04:00
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
}
// Add pagination to the query
$query->offset($this->getOffset())->limit($this->getLimit());
// Get the data
$results = $query->get();
2020-11-11 10:38:08 -04:00
// Prepare the result
$results->transform(function ($item, $key) {
// Get priority label
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
// Get task color label
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
2021-01-21 13:55:02 -04:00
// Get task status
2021-01-19 09:39:18 -04:00
$item['TAS_STATUS'] = self::TASK_STATUS[$item['TAS_COLOR']];
2021-01-21 13:55:02 -04:00
// Get delay
$item['DELAY'] = getDiffBetweenDates($item['DEL_TASK_DUE_DATE'], date("Y-m-d H:i:s"));
2020-11-11 10:38:08 -04:00
// Apply the date format defined in environment
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
2021-07-12 11:38:27 -04:00
// Get the send by related to the previous index
$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-11-11 10:38:08 -04:00
return $item;
});
2019-06-14 13:05:21 -04:00
return $results->values()->toArray();
}
/**
2020-12-14 15:24:08 -04:00
* Count how many cases the user has in DRAFT, does not apply filters
2019-06-14 13:05:21 -04:00
*
* @return int
*/
public function getCounter()
{
2021-03-30 10:03:46 -04:00
$query = Application::query()->select();
2019-06-14 13:05:21 -04:00
// Add the initial scope for draft cases
2021-03-30 10:03:46 -04:00
$query->statusId(Application::STATUS_DRAFT);
// Filter the creator
$query->creator($this->getUserUid());
2020-12-14 15:24:08 -04:00
// Return the number of rows
2021-03-30 10:03:46 -04:00
return $query->count(['APPLICATION.APP_NUMBER']);
2020-12-14 15:24:08 -04:00
}
2020-12-14 15:24:08 -04:00
/**
* Count how many cases the user has in DRAFT, needs to apply filters
*
* @return int
*/
public function getPagingCounters()
{
$query = Delegation::query()->select();
// Add the initial scope for draft cases
$query->draft($this->getUserId());
// Apply filters
$this->filters($query);
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
2019-06-14 13:05:21 -04:00
}
}