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

1587 lines
42 KiB
PHP
Raw Normal View History

<?php
namespace ProcessMaker\BusinessModel\Cases;
2020-11-11 10:38:08 -04:00
use Datetime;
2021-07-21 16:18:36 -04:00
use DB;
use Exception;
use ProcessMaker\BusinessModel\Interfaces\CasesInterface;
use ProcessMaker\BusinessModel\Validator;
2020-12-15 11:37:58 -04:00
use ProcessMaker\Model\Delegation;
2020-11-25 18:11:22 -04:00
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
class AbstractCases implements CasesInterface
{
// Constants for validate values
2020-12-09 19:04:05 -04:00
const INBOX_STATUSES = ['READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['ON_TIME', 'AT_RISK', 'OVERDUE'];
2020-12-07 17:07:26 -04:00
const CASE_STATUSES = [1 => 'DRAFT', 2 => 'TO_DO', 3 => 'COMPLETED', 4 => 'CANCELED'];
const ORDER_DIRECTIONS = ['DESC', 'ASC'];
const CORRECT_CANCELED_STATUS = 'CANCELED';
const INCORRECT_CANCELED_STATUS = 'CANCELLED';
2020-12-07 17:07:26 -04:00
const PRIORITIES = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
2020-12-09 19:04:05 -04:00
// Task Colors
2020-11-11 10:38:08 -04:00
const TASK_COLORS = [1 => 'green', 2 => 'red', 3 => 'orange', 4 => 'blue', 5 => 'gray'];
2021-01-19 09:39:18 -04:00
const TASK_STATUS = [1 => 'ON_TIME', 2 => 'OVERDUE', 3 => 'DRAFT', 4 => 'PAUSED', 5 => 'UNASSIGNED'];
const COLOR_ON_TIME = 1; // green
const COLOR_OVERDUE = 2; // red
const COLOR_DRAFT = 3; // orange
const COLOR_PAUSED = 4; // blue
const COLOR_UNASSIGNED = 5; // gray
2020-12-09 19:04:05 -04:00
// Status values
const STATUS_DRAFT = 1;
const STATUS_TODO = 2;
const STATUS_COMPLETED = 3;
const STATUS_CANCELED = 4;
2021-07-09 15:43:44 -04:00
// Order by column allowed
const ORDER_BY_COLUMN_ALLOWED = ['APP_NUMBER', 'DEL_TITLE', 'PRO_TITLE'];
2021-07-14 11:14:48 -04:00
// Filter by category using the Id field
private $categoryId = 0;
// Filter by category from a process, know as "$category" in the old lists classes
private $categoryUid = '';
// Filter by process, know as "$process" in the old lists classes
private $processUid = '';
// Filter by process using the Id field
private $processId = 0;
2020-11-05 17:50:41 -04:00
// Filter by task using the Id field
private $taskId = 0;
// Filter by user, know as "$user" in the old lists classes
private $userUid = '';
// Filter by user using the Id field
private $userId = 0;
2021-07-15 12:27:44 -04:00
// Filter by user who completed using the Id field
private $userCompleted = 0;
// Filter by user who started using the Id field
private $userStarted = 0;
// Value to search, can be a text or an application number, know as "$search" in the old lists classes
private $valueToSearch = '';
// Filter cases depending if were read or not, know as "$filter" in the old lists classes
private $inboxStatus = '';
// Filter cases depending if the case was started or completed by the current user, know as "$filter" in the old lists classes
private $participatedStatus = '';
// Filter by risk status, know as "$filterStatus" in the old list "inbox" class
private $riskStatus = '';
2020-11-05 17:50:41 -04:00
// Filter by specific priority
private $priority = 0;
2020-11-25 18:11:22 -04:00
// Filter by specific priorities
private $priorities = [];
// Filter by case status, know as "$filterStatus" in the old "participated last" class
private $caseStatus = '';
2020-11-25 18:11:22 -04:00
// Filter by case statuses
private $caseStatuses = [1, 2, 3, 4];
// Filter by a specific case, know as "$caseLink" in the old lists classes
private $caseUid = '';
// Filter by a specific case using case number
private $caseNumber = 0;
2020-11-25 18:11:22 -04:00
// Filter by specific cases using the case numbers like [1,4,8]
private $casesNumbers = [];
// Filter by only one range of case number
private $caseNumberFrom = 0;
private $caseNumberTo = 0;
// Filter more than one range of case number
private $rangeCasesFromTo = [];
// Filter by a specific cases like 1,3-5,8,10-15
private $filterCases = '';
// Filter by a specific case title
private $caseTitle = '';
2020-11-05 17:50:41 -04:00
// Filter by specific cases, know as "$appUidCheck" in the old lists classes
private $casesUids = [];
2020-11-25 18:11:22 -04:00
// Filter range related to the start case date
private $startCaseFrom = '';
private $startCaseTo = '';
// Filter range related to the finish case date
private $finishCaseFrom = '';
private $finishCaseTo = '';
2020-11-25 18:11:22 -04:00
// Filter range related to the delegate date
private $delegateFrom = '';
private $delegateTo = '';
2020-11-25 18:11:22 -04:00
// Filter range related to the finish date
private $finishFrom = '';
private $finishTo = '';
// Filter range related to the due date
private $dueFrom = '';
private $dueTo = '';
// Column by which the results will be sorted, know as "$sort" in the old lists classes
2020-11-25 18:11:22 -04:00
private $orderByColumn = 'APP_NUMBER';
// Sorts the data in descending or ascending order, know as "$dir" in the old lists classes
private $orderDirection = 'DESC';
// Results should be paged?
private $paged = true;
// Offset is used to identify the starting point to return rows from a result set, know as "$start" in the old lists classes
private $offset = 0;
// Number of rows to return
2020-11-25 18:11:22 -04:00
private $limit = 15;
2021-07-14 11:14:48 -04:00
/**
* Set Category Uid value
*
* @param int $category
*/
public function setCategoryId(int $category)
{
$this->categoryId = $category;
}
/**
* Get Category Id value
*
* @return string
*/
public function getCategoryId()
{
return $this->categoryId;
}
/**
* Set Category Uid value
*
* @param string $categoryUid
*/
2020-11-11 10:38:08 -04:00
public function setCategoryUid(string $categoryUid)
{
$this->categoryUid = $categoryUid;
}
/**
* Get Category Uid value
*
* @return string
*/
public function getCategoryUid()
{
return $this->categoryUid;
}
/**
* Set Process Uid value
*
* @param string $processUid
*/
2020-11-11 10:38:08 -04:00
public function setProcessUid(string $processUid)
{
$this->processUid = $processUid;
}
/**
* Get Process Uid value
*
* @return string
*/
public function getProcessUid()
{
return $this->processUid;
}
/**
* Set Process Id value
*
* @param int $processId
*/
2020-11-11 10:38:08 -04:00
public function setProcessId(int $processId)
{
$this->processId = $processId;
}
/**
* Get Process Id value
*
* @return int
*/
public function getProcessId()
{
return $this->processId;
}
2020-11-05 17:50:41 -04:00
/**
* 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
*
* @param string $userUid
*/
2020-11-11 10:38:08 -04:00
public function setUserUid(string $userUid)
{
$this->userUid = $userUid;
}
/**
* Get User Uid value
*
* @return string
*/
public function getUserUid()
{
return $this->userUid;
}
/**
* Set User Id value
*
* @param int $userId
*/
2020-11-11 10:38:08 -04:00
public function setUserId(int $userId)
{
$this->userId = $userId;
}
/**
* Get User Id value
*
* @return int
*/
public function getUserId()
{
return $this->userId;
}
2021-07-15 12:27:44 -04:00
/**
* Set User Id value
*
* @param int $userId
*/
public function setUserCompletedId(int $userId)
{
$this->userCompleted = $userId;
}
/**
* Get User Id value
*
* @return int
*/
public function getUserCompletedId()
{
return $this->userCompleted;
}
/**
* Set User Id value
*
* @param int $userId
*/
public function setUserStartedId(int $userId)
{
$this->userStarted = $userId;
}
/**
* Get User Id value
*
* @return int
*/
public function getUserStartedId()
{
return $this->userStarted;
}
/**
* Set value to search
*
* @param string $valueToSearch
*/
2020-11-11 10:38:08 -04:00
public function setValueToSearch(string $valueToSearch)
{
$this->valueToSearch = $valueToSearch;
}
/**
* Get value to search
*
* @return string
*/
public function getValueToSearch()
{
return $this->valueToSearch;
}
/**
* Set inbox status
*
* @param string $inboxStatus
*
* @throws Exception
*/
2020-11-11 10:38:08 -04:00
public function setInboxStatus(string $inboxStatus)
{
// Convert the value to upper case
$inboxStatus = strtoupper($inboxStatus);
// Validate the inbox status
if (!in_array($inboxStatus, self::INBOX_STATUSES)) {
throw new Exception("Inbox status '{$inboxStatus}' is not valid.");
}
$this->inboxStatus = $inboxStatus;
}
/**
* Get inbox status
*
* @return string
*/
public function getInboxStatus()
{
return $this->inboxStatus;
}
/**
* Set participated status
*
* @param string $participatedStatus
*
* @throws Exception
*/
2020-11-11 10:38:08 -04:00
public function setParticipatedStatus(string $participatedStatus)
{
// Convert the value to upper case
$participatedStatus = strtoupper($participatedStatus);
// Validate the participated status
if (!in_array($participatedStatus, self::PARTICIPATED_STATUSES)) {
throw new Exception("Participated status '{$participatedStatus}' is not valid.");
}
$this->participatedStatus = $participatedStatus;
}
/**
* Get participated status
*
* @return string
*/
public function getParticipatedStatus()
{
return $this->participatedStatus;
}
/**
* Set risk status
*
* @param string $riskStatus
*
* @throws Exception
*/
2020-11-11 10:38:08 -04:00
public function setRiskStatus(string $riskStatus)
{
// Convert the value to upper case
$riskStatus = strtoupper($riskStatus);
// Validate the risk status
if (!in_array($riskStatus, self::RISK_STATUSES)) {
throw new Exception("Risk status '{$riskStatus}' is not valid.");
}
$this->riskStatus = $riskStatus;
}
/**
2020-11-05 17:50:41 -04:00
* Get risk value
*
* @return string
*/
public function getRiskStatus()
{
return $this->riskStatus;
}
2020-11-05 17:50:41 -04:00
/**
* Set priority value
*
2020-11-25 18:11:22 -04:00
* @param string $priority
2020-11-05 17:50:41 -04:00
*
* @throws Exception
*/
2020-11-25 18:11:22 -04:00
public function setPriority(string $priority)
2020-11-05 17:50:41 -04:00
{
// Validate the priority value
if (!empty($priority)) {
2020-11-25 18:11:22 -04:00
$priorityCode = array_search($priority, self::PRIORITIES);
if (empty($priorityCode) && $priorityCode !== 0) {
2020-11-05 17:50:41 -04:00
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;
}
/**
2020-11-25 18:11:22 -04:00
* Set priorities
*
2020-11-25 18:11:22 -04:00
* @param array $priorities
*
* @throws Exception
*/
2020-11-25 18:11:22 -04:00
public function setPriorities(array $priorities)
{
2020-11-25 18:11:22 -04:00
$prioritiesCode = [];
foreach ($priorities as $priority) {
// Validate the priority value
$priorityCode = array_search($priority, self::PRIORITIES);
if (empty($priorityCode) && $priorityCode !== 0) {
throw new Exception("Priority value {$priority} is not valid.");
} else {
array_push($prioritiesCode, $priorityCode);
}
}
2020-11-25 18:11:22 -04:00
$this->priorities = $prioritiesCode;
}
2020-11-25 18:11:22 -04:00
/**
* Get priorities
*
* @return array
*/
public function getPriorities()
{
return $this->priorities;
}
2020-11-25 18:11:22 -04:00
/**
* Set Case status
*
* @param string $status
*
* @throws Exception
*/
public function setCaseStatus(string $status)
{
// Fix the canceled status, this is a legacy code error
2020-11-25 18:11:22 -04:00
if ($status === self::INCORRECT_CANCELED_STATUS) {
$status = self::CORRECT_CANCELED_STATUS;
}
2020-11-25 18:11:22 -04:00
$statusCode = 0;
// Validate the status value
if (!empty($status)) {
$statusCode = array_search($status, self::CASE_STATUSES);
if (empty($statusCode) && $statusCode !== 0) {
throw new Exception("Case status '{$status}' is not valid.");
}
}
$this->caseStatus = $statusCode;
}
/**
* Get Case Status
*
2020-11-25 18:11:22 -04:00
* @return int
*/
public function getCaseStatus()
{
return $this->caseStatus;
}
2020-11-25 18:11:22 -04:00
/**
* Set Case statuses
*
* @param array $statuses
*
* @throws Exception
*/
public function setCaseStatuses(array $statuses)
{
$statusCodes = [];
foreach ($statuses as $status) {
// Fix the canceled status, this is a legacy code error
if ($status === self::INCORRECT_CANCELED_STATUS) {
$status = self::CORRECT_CANCELED_STATUS;
}
// Validate the status value
if (!empty($status)) {
$statusCode = array_search($status, self::CASE_STATUSES);
if (empty($statusCode) && $statusCode !== 0) {
throw new Exception("Case status '{$status}' is not valid.");
} else {
array_push($statusCodes, $statusCode);
}
}
}
$this->caseStatuses = $statusCodes;
}
/**
* Get Case Statuses
*
* @return array
*/
public function getCaseStatuses()
{
return $this->caseStatuses;
}
/**
* Set Case Uid
*
* @param string $caseUid
*/
2020-11-11 10:38:08 -04:00
public function setCaseUid(string $caseUid)
{
$this->caseUid = $caseUid;
}
/**
* Get Case Uid
*
* @return string
*/
public function getCaseUid()
{
return $this->caseUid;
}
/**
* Set Case Number
*
* @param int $caseNumber
*/
2020-11-11 10:38:08 -04:00
public function setCaseNumber(int $caseNumber)
{
$this->caseNumber = $caseNumber;
}
/**
* Get Case Number
*
* @return int
*/
public function getCaseNumber()
{
return $this->caseNumber;
}
2020-11-05 17:50:41 -04:00
/**
2020-11-25 18:11:22 -04:00
* Set range of case number from
2020-11-05 17:50:41 -04:00
*
* @param int $from
*/
2020-11-25 18:11:22 -04:00
public function setCaseNumberFrom(int $from)
2020-11-05 17:50:41 -04:00
{
2020-11-25 18:11:22 -04:00
$this->caseNumberFrom = $from;
2020-11-05 17:50:41 -04:00
}
/**
* Get from Case Number
*
* @return int
*/
2020-11-25 18:11:22 -04:00
public function getCaseNumberFrom()
{
return $this->caseNumberFrom;
}
/**
* Set range of case number to
*
* @param int $to
*/
public function setCaseNumberTo(int $to)
2020-11-05 17:50:41 -04:00
{
2020-11-25 18:11:22 -04:00
$this->caseNumberTo = $to;
2020-11-05 17:50:41 -04:00
}
/**
* Get to Case Number
*
* @return int
*/
2020-11-25 18:11:22 -04:00
public function getCaseNumberTo()
2020-11-05 17:50:41 -04:00
{
2020-11-25 18:11:22 -04:00
return $this->caseNumberTo;
}
/**
* Set more than one range of cases
*
* @param array $rangeCases
*/
public function setRangeCasesFromTo(array $rangeCases)
{
$this->rangeCasesFromTo = $rangeCases;
}
/**
* Get more than one range of cases
*
* @return array
*/
public function getRangeCasesFromTo()
{
return $this->rangeCasesFromTo;
}
/**
* Set filter of cases like '1,3-5,8,10-15'
*
* @param string $filterCases
*/
public function setFilterCases(string $filterCases)
{
$this->filterCases = $filterCases;
// Review the cases defined in the filter
$rangeOfCases = explode(",", $filterCases);
$specificCases = [];
$rangeCases = [];
foreach ($rangeOfCases as $cases) {
2021-07-13 11:26:05 -04:00
if (is_numeric($cases)) {
array_push($specificCases, $cases);
2020-11-25 18:11:22 -04:00
} else {
2021-07-13 11:26:05 -04:00
array_push($rangeCases, $cases);
2020-11-25 18:11:22 -04:00
}
}
$this->setCasesNumbers($specificCases);
$this->setRangeCasesFromTo($rangeCases);
}
/**
* Get filter of cases
*
* @return string
*/
public function getFilterCases()
{
return $this->filterCases;
}
/**
* Set Case Title
*
* @param string $caseTitle
*/
public function setCaseTitle(string $caseTitle)
{
$this->caseTitle = $caseTitle;
}
/**
* Get Case Title
*
* @return string
*/
public function getCaseTitle()
{
return $this->caseTitle;
2020-11-05 17:50:41 -04:00
}
/**
* Set Cases Uids
*
* @param array $casesUid
*/
public function setCasesUids(array $casesUid)
{
$this->casesUids = $casesUid;
}
/**
* Get Cases Uids
*
* @return array
*/
public function getCasesUids()
{
return $this->casesUids;
}
/**
* Set Cases Numbers
*
* @param array $casesNumbers
*/
public function setCasesNumbers(array $casesNumbers)
{
$this->casesNumbers = $casesNumbers;
}
/**
* Get Cases Numbers
*
* @return array
*/
public function getCasesNumbers()
{
return $this->casesNumbers;
}
2020-11-25 18:11:22 -04:00
/**
* Set start case from
*
* @param string $from
*
* @throws Exception
*/
public function setStartCaseFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->startCaseFrom = $from;
}
/**
* Get start case from
*
* @return string
*/
public function getStartCaseFrom()
{
return $this->startCaseFrom;
}
/**
* Set start case to
*
* @param string $to
*
* @throws Exception
*/
public function setStartCaseTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->startCaseTo = $to;
}
/**
* Get start case to
*
* @return string
*/
public function getStartCaseTo()
{
return $this->startCaseTo;
}
/**
* Set finish case from
*
* @param string $from
*
* @throws Exception
*/
public function setFinishCaseFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->finishCaseFrom = $from;
}
/**
* Get start case from
*
* @return string
*/
public function getFinishCaseFrom()
{
return $this->finishCaseFrom;
}
/**
* Set start case to
*
* @param string $to
*
* @throws Exception
*/
public function setFinishCaseTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->finishCaseTo = $to;
}
/**
* Get start case to
*
* @return string
*/
public function getFinishCaseTo()
{
return $this->finishCaseTo;
}
/**
* Set Newest Than value
*
2020-11-25 18:11:22 -04:00
* @param string $delegateFrom
*
* @throws Exception
*/
2020-11-25 18:11:22 -04:00
public function setDelegateFrom(string $delegateFrom)
{
2020-11-25 18:11:22 -04:00
if (!Validator::isDate($delegateFrom, 'Y-m-d')) {
throw new Exception("Value '{$delegateFrom}' is not a valid date.");
}
2020-11-25 18:11:22 -04:00
$this->delegateFrom = $delegateFrom;
}
/**
* Get Newest Than value
*
* @return string
*/
2020-11-25 18:11:22 -04:00
public function getDelegateFrom()
{
2020-11-25 18:11:22 -04:00
return $this->delegateFrom;
}
/**
* Set Oldest Than value
*
2020-11-25 18:11:22 -04:00
* @param string $delegateTo
*
* @throws Exception
*/
2020-11-25 18:11:22 -04:00
public function setDelegateTo(string $delegateTo)
{
2020-11-25 18:11:22 -04:00
if (!Validator::isDate($delegateTo, 'Y-m-d')) {
throw new Exception("Value '{$delegateTo}' is not a valid date.");
}
2020-11-25 18:11:22 -04:00
$this->delegateTo = $delegateTo;
}
2020-10-16 15:53:54 -04:00
/**
* Get Oldest Than value
*
* @return string
*/
2020-11-25 18:11:22 -04:00
public function getDelegateTo()
2020-10-16 15:53:54 -04:00
{
2020-11-25 18:11:22 -04:00
return $this->delegateTo;
2020-10-16 15:53:54 -04:00
}
2020-11-25 18:11:22 -04:00
/**
* Set finish date value
*
* @param string $from
*
* @throws Exception
*/
public function setFinishFrom(string $from)
{
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->finishFrom = $from;
}
/**
* Get finish date value
*
* @return string
*/
public function getFinishFrom()
{
return $this->finishFrom;
}
/**
* Set finish date value
*
* @param string $to
*
* @throws Exception
*/
public function setFinishTo(string $to)
{
if (!Validator::isDate($to, 'Y-m-d')) {
throw new Exception("Value '{$to}' is not a valid date.");
}
$this->finishTo = $to;
}
/**
* Get finish date value
*
* @return string
*/
public function getFinishTo()
{
return $this->finishTo;
}
/**
* Set due date from
*
* @param string $dueFrom
*
* @throws Exception
*/
public function setDueFrom(string $dueFrom)
{
if (!Validator::isDate($dueFrom, 'Y-m-d')) {
throw new Exception("Value '{$dueFrom}' is not a valid date.");
}
$this->dueFrom = $dueFrom;
}
/**
* Get due date from
*
* @return string
*/
public function getDueFrom()
{
return $this->dueFrom;
}
/**
* Set due date to
*
* @param string $dueTo
*
* @throws Exception
*/
public function setDueTo(string $dueTo)
{
if (!Validator::isDate($dueTo, 'Y-m-d')) {
throw new Exception("Value '{$dueTo}' is not a valid date.");
}
$this->dueTo = $dueTo;
}
/**
* Get due date to
*
* @return string
*/
public function getDueTo()
{
return $this->dueTo;
}
/**
* Set order by column
*
* @param string $orderByColumn
*/
2020-11-11 10:38:08 -04:00
public function setOrderByColumn(string $orderByColumn)
{
// Convert the value to upper case
$orderByColumn = strtoupper($orderByColumn);
2021-07-09 15:43:44 -04:00
// Validate the order by column
if (!in_array($orderByColumn, self::ORDER_BY_COLUMN_ALLOWED)) {
throw new Exception("Order by column '{$orderByColumn}' is not valid.");
}
$this->orderByColumn = $orderByColumn;
}
/**
* Get order by column
*
* @return string
*/
public function getOrderByColumn()
{
return $this->orderByColumn;
}
/**
* Set order direction
*
* @param string $orderDirection
*
* @throws Exception
*/
2020-11-11 10:38:08 -04:00
public function setOrderDirection(string $orderDirection)
{
// Convert the value to upper case
$orderDirection = strtoupper($orderDirection);
// Validate the order direction
if (!in_array($orderDirection, self::ORDER_DIRECTIONS)) {
throw new Exception("Order direction '{$orderDirection}' is not valid.");
}
$this->orderDirection = $orderDirection;
}
/**
* Get order direction
*
* @return string
*/
public function getOrderDirection()
{
return $this->orderDirection;
}
/**
* Set if is paged
*
* @param bool $paged
*/
2020-11-11 10:38:08 -04:00
public function setPaged(bool $paged)
{
$this->paged = (bool) $paged;
}
/**
* Get if is paged
*
* @return bool
*/
public function getPaged()
{
return $this->paged;
}
/**
* Set offset value
*
* @param int $offset
*/
2020-11-11 10:38:08 -04:00
public function setOffset(int $offset)
{
$this->offset = (int) $offset;
}
/**
* Get offset value
*
* @return int
*/
public function getOffset()
{
return $this->offset;
}
/**
* Set limit value
*
* @param int $limit
*/
2020-11-11 10:38:08 -04:00
public function setLimit(int $limit)
{
$this->limit = (int) $limit;
}
/**
* Get limit value
*
* @return int
*/
public function getLimit()
{
return $this->limit;
}
2020-11-11 10:38:08 -04:00
/**
* Get task color according the due date
*
* @param string $dueDate
2021-01-19 18:05:16 -04:00
* @param string $statusThread
2021-01-26 17:37:40 -04:00
* @param string $dateToCompare
2020-11-11 10:38:08 -04:00
*
* @return int
*/
2021-01-26 17:37:40 -04:00
public function getTaskColor(string $dueDate, string $statusThread = '', $dateToCompare = 'now')
2020-11-11 10:38:08 -04:00
{
2021-01-26 17:37:40 -04:00
$currentDate = new DateTime($dateToCompare);
2020-11-11 10:38:08 -04:00
$dueDate = new DateTime($dueDate);
2021-01-19 09:39:18 -04:00
if ($currentDate > $dueDate) {
// Overdue: When the current date is mayor to the due date of the case
2020-11-11 10:38:08 -04:00
$taskColor = self::COLOR_OVERDUE;
} else {
2021-01-19 09:39:18 -04:00
// OnTime
2020-11-11 10:38:08 -04:00
$taskColor = self::COLOR_ON_TIME;
2021-01-19 18:05:16 -04:00
if (get_class($this) === Draft::class || $statusThread === self::TASK_STATUS[3]) {
2020-11-11 10:38:08 -04:00
$taskColor = self::COLOR_DRAFT;
}
2021-01-19 18:05:16 -04:00
if (get_class($this) === Paused::class || $statusThread === self::TASK_STATUS[4]) {
2020-11-11 10:38:08 -04:00
$taskColor = self::COLOR_PAUSED;
}
2021-01-19 18:05:16 -04:00
if (get_class($this) === Unassigned::class || $statusThread === self::TASK_STATUS[5]) {
2020-11-11 10:38:08 -04:00
$taskColor = self::COLOR_UNASSIGNED;
}
}
return $taskColor;
}
2020-11-25 18:11:22 -04:00
/**
* Get task color according the due date
*
2020-12-15 11:37:58 -04:00
* @param string $pendingJson
* @param bool $onlyTask
2021-01-27 09:55:52 -04:00
* @param string $statusThread
* @param string $dateToCompare
2020-11-25 18:11:22 -04:00
*
* @return int
*/
2021-01-27 09:55:52 -04:00
public function prepareTaskPending($pendingJson, $onlyTask = true, $statusThread = '', $dateToCompare = '')
2020-11-25 18:11:22 -04:00
{
2020-12-15 11:37:58 -04:00
$taskPending = json_decode($pendingJson, true);
2020-11-25 18:11:22 -04:00
$result = [];
2020-12-15 11:37:58 -04:00
$threadTasks = [];
$threadUsers = [];
$threadTitles = [];
2020-11-25 18:11:22 -04:00
$i = 0;
foreach ($taskPending as $thread) {
foreach ($thread as $key => $row) {
2020-12-15 11:37:58 -04:00
// Thread tasks
if ($key === 'tas_id') {
$threadTasks[$i][$key] = $row;
$threadTasks[$i]['tas_title'] = (!empty($row)) ? Task::where('TAS_ID', $row)->first()->TAS_TITLE : '';
2020-11-25 18:11:22 -04:00
}
2020-12-15 11:37:58 -04:00
if ($key === 'due_date') {
$threadTasks[$i][$key] = $row;
2021-01-27 09:55:52 -04:00
// Get the end date for calculate the delay
$endDate = ($dateToCompare !== 'now') ? $endDate = $dateToCompare : date("Y-m-d H:i:s");
$threadTasks[$i]['delay'] = getDiffBetweenDates($row, $endDate);
2020-11-25 18:11:22 -04:00
// Get task color label
2021-01-27 09:55:52 -04:00
$threadTasks[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($row, $statusThread, $dateToCompare) : '';
2020-12-15 11:37:58 -04:00
$threadTasks[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$threadTasks[$i]['tas_color']] : '';
2021-01-19 09:39:18 -04:00
$threadTasks[$i]['tas_status'] = self::TASK_STATUS[$threadTasks[$i]['tas_color']];
2020-12-15 11:37:58 -04:00
}
// Review if require other information
if ($onlyTask) {
// Thread tasks
2021-07-13 11:26:05 -04:00
if ($key === 'user_id') {
2020-12-15 11:37:58 -04:00
$threadTasks[$i][$key] = $row;
2021-01-13 12:41:53 -04:00
// Get the user tooltip information
2021-01-21 13:55:02 -04:00
$threadTasks[$i]['user_tooltip'] = User::getInformation($row);
2020-12-15 11:37:58 -04:00
}
} else {
// Thread users
if ($key === 'user_id') {
$threadUsers[$i][$key] = $row;
2021-01-14 09:53:58 -04:00
// Get user information
$userInfo = User::getInformation($row);
$threadUsers[$i]['usr_username'] = !empty($userInfo) ? $userInfo['usr_username'] : '';
$threadUsers[$i]['usr_lastname'] = !empty($userInfo) ? $userInfo['usr_lastname'] : '';
$threadUsers[$i]['usr_firstname'] = !empty($userInfo) ? $userInfo['usr_firstname'] : '';
2021-01-21 13:55:02 -04:00
$threadUsers[$i]['user_tooltip'] = User::getInformation($row);
2020-12-15 11:37:58 -04:00
}
// Thread titles
if ($key === 'del_id') {
$threadTitles[$i][$key] = $row;
$threadTitles[$i]['thread_title'] = (!empty($row)) ? Delegation::where('DELEGATION_ID', $row)->first()->DEL_TITLE : '';
}
2020-11-25 18:11:22 -04:00
}
}
2021-07-13 11:26:05 -04:00
$i++;
2020-11-25 18:11:22 -04:00
}
2020-12-15 11:37:58 -04:00
// Define the array responses
$result['THREAD_TASKS'] = $threadTasks;
$result['THREAD_USERS'] = $threadUsers;
$result['THREAD_TITLES'] = $threadTitles;
2020-11-25 18:11:22 -04:00
return $result;
}
2021-01-19 18:05:16 -04:00
/**
* Get the thread information
*
* @param array $thread
2021-03-30 10:03:46 -04:00
* @param bool $addUserInfo
* @param bool $addThreadInfo
2021-01-19 18:05:16 -04:00
*
* @return array
*/
2021-03-30 10:03:46 -04:00
public function threadInformation(array $thread, $addUserInfo = false, $addThreadInfo = false)
2021-01-19 18:05:16 -04:00
{
$status = '';
2021-01-26 17:37:40 -04:00
$finishDate = 'now';
$dateToCompare = date("Y-m-d H:i:s");
2021-01-19 18:05:16 -04:00
// Define the task status
if ($thread['TAS_ASSIGN_TYPE'] === 'SELF_SERVICE') {
$status = 'UNASSIGNED';
}
if ($thread['APP_STATUS'] === 'DRAFT') {
$status = 'DRAFT';
}
2021-07-26 13:13:26 -04:00
if (isset($thread['DEL_THREAD_STATUS']) && $thread['DEL_THREAD_STATUS'] === 'PAUSED') {
$status = 'PAUSED';
}
2021-01-26 17:37:40 -04:00
if ($thread['APP_STATUS'] === 'COMPLETED') {
2021-03-30 10:03:46 -04:00
$finishDate = !empty($thread['APP_FINISH_DATE']) ? $thread['APP_FINISH_DATE'] : date("Y-m-d H:i:s");
2021-01-26 17:37:40 -04:00
$dateToCompare = $finishDate;
}
2021-03-30 10:03:46 -04:00
// Variables of results
$threadTask = [];
$threadUser = [];
$threadTitle = [];
2021-01-19 18:05:16 -04:00
// Define the thread information
2021-03-30 10:03:46 -04:00
$threadTask['tas_uid'] = !empty($thread['TAS_UID']) ? $thread['TAS_UID'] : '';
$threadTask['tas_title'] = $thread['TAS_TITLE'];
$threadTask['user_id'] = $thread['USR_ID'];
$threadTask['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$threadTask['delay'] = getDiffBetweenDates($thread['DEL_TASK_DUE_DATE'], $dateToCompare);
$threadTask['tas_color'] = (!empty($thread['DEL_TASK_DUE_DATE'])) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE'], $status, $finishDate) : '';
$threadTask['tas_color_label'] = (!empty($threadTask['tas_color'])) ? self::TASK_COLORS[$threadTask['tas_color']] : '';
$threadTask['tas_status'] = self::TASK_STATUS[$threadTask['tas_color']];
$threadTask['unassigned'] = ($status === 'UNASSIGNED' ? true : false);
$userInfo = User::getInformation($thread['USR_ID']);
$threadTask['user_tooltip'] = $userInfo;
// Get user information
if ($addUserInfo) {
$threadUser['user_tooltip'] = $userInfo;
$threadUser['user_id'] = $thread['USR_ID'];
$threadUser['usr_username'] = !empty($userInfo['usr_username']) ? $userInfo['usr_username'] : '';
$threadUser['usr_lastname'] = !empty($userInfo['usr_lastname']) ? $userInfo['usr_lastname'] : '';
$threadUser['usr_firstname'] = !empty($userInfo['usr_firstname']) ? $userInfo['usr_firstname'] : '';
}
// Get thread titles
if ($addThreadInfo) {
$threadTitle['del_id'] = $thread['DELEGATION_ID'];
$threadTitle['del_index'] = $thread['DEL_INDEX'];
$threadTitle['thread_title'] = $thread['DEL_TITLE'];
}
// Define the array responses
$result = [];
$result['THREAD_TASK'] = $threadTask;
$result['THREAD_USER'] = $threadUser;
$result['THREAD_TITLE'] = $threadTitle;
2021-01-19 18:05:16 -04:00
2021-03-30 10:03:46 -04:00
if (!$addUserInfo && !$addThreadInfo) {
// Only will return the pending task info
return $threadTask;
} else {
return $result;
}
2021-01-19 18:05:16 -04:00
}
/**
* Set all properties
*
* @param array $properties
*/
public function setProperties(array $properties)
{
2020-11-11 10:38:08 -04:00
// Filter by process
if (!empty($properties['process'])) {
2020-11-11 10:38:08 -04:00
$this->setProcessId($properties['process']);
}
2020-11-11 10:38:08 -04:00
// Filter by task
2020-11-05 17:50:41 -04:00
if (!empty($properties['task'])) {
$this->setTaskId($properties['task']);
}
2020-11-11 10:38:08 -04:00
// Filter by user
if (!empty($properties['user'])) {
2020-11-11 10:38:08 -04:00
$this->setUserId($properties['user']);
}
2020-11-25 18:11:22 -04:00
// Filter by one case number
2020-11-05 17:50:41 -04:00
if (!empty($properties['caseNumber'])) {
$this->setCaseNumber($properties['caseNumber']);
}
2021-07-08 12:55:24 -04:00
// Add a filter with specific cases or range of cases like '1, 3-5, 8, 10-15'
if (!empty($properties['filterCases'])) {
$this->setFilterCases($properties['filterCases']);
}
2020-11-25 18:11:22 -04:00
// Filter by case title
if (!empty($properties['caseTitle'])) {
$this->setCaseTitle($properties['caseTitle']);
}
2021-07-15 12:27:44 -04:00
// Filter by case uid
if (!empty($properties['caseLink'])) {
$this->setCaseUid($properties['caseLink']);
}
// Filter by array of case uids
if (!empty($properties['appUidCheck'])) {
$this->setCasesUids($properties['appUidCheck']);
}
// Sort column
if (!empty($properties['sort'])) {
$this->setOrderByColumn($properties['sort']);
}
// Direction column
if (!empty($properties['dir'])) {
$this->setOrderDirection($properties['dir']);
}
// Paged
if (!empty($properties['paged'])) {
$this->setPaged($properties['paged']);
}
// Start
if (!empty($properties['start'])) {
$this->setOffset($properties['start']);
}
// Limit
if (!empty($properties['limit'])) {
$this->setLimit($properties['limit']);
}
2021-07-13 17:16:21 -04:00
/** Apply filters related to INBOX */
// Filter date related to delegate from
if (get_class($this) === Inbox::class && !empty($properties['delegateFrom'])) {
$this->setDelegateFrom($properties['delegateFrom']);
}
// Filter date related to delegate to
if (get_class($this) === Inbox::class && !empty($properties['delegateTo'])) {
$this->setDelegateTo($properties['delegateTo']);
}
/** Apply filters related to PAUSED */
// Filter date related to delegate from
if (get_class($this) === Paused::class && !empty($properties['delegateFrom'])) {
$this->setDelegateFrom($properties['delegateFrom']);
}
// Filter date related to delegate to
if (get_class($this) === Paused::class && !empty($properties['delegateTo'])) {
$this->setDelegateTo($properties['delegateTo']);
}
/** Apply filters related to UNASSIGNED */
// Filter date related to delegate from
if (get_class($this) === Unassigned::class && !empty($properties['delegateFrom'])) {
$this->setDelegateFrom($properties['delegateFrom']);
}
// Filter date related to delegate to
if (get_class($this) === Unassigned::class && !empty($properties['delegateTo'])) {
$this->setDelegateTo($properties['delegateTo']);
}
2020-11-25 18:11:22 -04:00
/** Apply filters related to MY CASES */
2020-11-11 10:38:08 -04:00
// My cases filter: started, in-progress, completed, supervising
2020-12-07 17:07:26 -04:00
if (get_class($this) === Participated::class && !empty($properties['filter'])) {
$this->setParticipatedStatus($properties['filter']);
}
2020-11-25 18:11:22 -04:00
// Filter by one case status
2020-12-07 17:07:26 -04:00
if (get_class($this) === Participated::class && !empty($properties['caseStatus'])) {
2020-11-25 18:11:22 -04:00
$this->setCaseStatus($properties['caseStatus']);
}
// Filter date related to started date from
2020-12-07 17:07:26 -04:00
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['startCaseFrom'])) {
2020-11-25 18:11:22 -04:00
$this->setStartCaseFrom($properties['startCaseFrom']);
}
// Filter date related to started date to
2020-12-07 17:07:26 -04:00
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['startCaseTo'])) {
2020-11-25 18:11:22 -04:00
$this->setStartCaseTo($properties['startCaseTo']);
}
// Filter date related to finish date from
2020-12-07 17:07:26 -04:00
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['finishCaseFrom'])) {
2020-11-25 18:11:22 -04:00
$this->setFinishCaseFrom($properties['finishCaseFrom']);
}
// Filter date related to finish date to
2020-12-07 17:07:26 -04:00
if ((get_class($this) === Participated::class || get_class($this) === Supervising::class) && !empty($properties['finishCaseTo'])) {
2020-11-25 18:11:22 -04:00
$this->setFinishCaseTo($properties['finishCaseTo']);
}
2020-11-25 18:11:22 -04:00
/** Apply filters related to SEARCH */
2021-07-14 11:14:48 -04:00
// Filter by category
if (get_class($this) === Search::class && !empty($properties['category'])) {
$this->setCategoryId($properties['category']);
}
2020-11-25 18:11:22 -04:00
// Filter by more than one case statuses like ['DRAFT', 'TO_DO']
2020-12-07 17:07:26 -04:00
if (get_class($this) === Search::class && !empty($properties['caseStatuses'])) {
2020-11-25 18:11:22 -04:00
$this->setCaseStatuses($properties['caseStatuses']);
}
2020-12-15 11:37:58 -04:00
// Filter date related to started date from
if (get_class($this) === Search::class && !empty($properties['startCaseFrom'])) {
$this->setStartCaseFrom($properties['startCaseFrom']);
2020-11-25 18:11:22 -04:00
}
2020-12-15 11:37:58 -04:00
// Filter date related to started date to
if (get_class($this) === Search::class && !empty($properties['startCaseTo'])) {
$this->setStartCaseTo($properties['startCaseTo']);
2020-11-25 18:11:22 -04:00
}
2020-12-15 11:37:58 -04:00
// Filter date related to finish date from
if (get_class($this) === Search::class && !empty($properties['finishCaseFrom'])) {
$this->setFinishCaseFrom($properties['finishCaseFrom']);
2020-11-25 18:11:22 -04:00
}
2020-12-15 11:37:58 -04:00
// Filter date related to finish date to
if (get_class($this) === Search::class && !empty($properties['finishCaseTo'])) {
$this->setFinishCaseTo($properties['finishCaseTo']);
}
2021-07-15 12:27:44 -04:00
// Filter date related to user who started
if (get_class($this) === Search::class && !empty($properties['userCompleted'])) {
$this->setUserCompletedId($properties['userCompleted']);
}
2021-07-15 12:27:44 -04:00
// Filter date related to user who completed
if (get_class($this) === Search::class && !empty($properties['userStarted'])) {
$this->setUserStartedId($properties['userStarted']);
}
}
/**
* Get the list data
*
* @throws Exception
*/
public function getData()
{
throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'.");
}
/**
* Get the list counter
*
* @throws Exception
*/
public function getCounter()
{
throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'.");
}
2020-12-14 15:24:08 -04:00
/**
* Get the list counter
*
* @throws Exception
*/
public function getPagingCounters()
{
throw new Exception("Method '" . __FUNCTION__ . "' should be implemented in the extended class '" . get_class($this) . "'.");
}
2021-07-13 11:26:05 -04:00
/**
* Count how many cases has each process
2021-08-02 13:06:17 -04:00
*
2021-07-13 11:26:05 -04:00
* @param int $category
* @param bool $topTen
* @param array $processes
*
* @return array
*/
public function getCountersByProcesses($category = null, $topTen = false, $processes = [])
{
$query = Delegation::selectRaw('count(APP_DELEGATION.DELEGATION_ID) as TOTAL, APP_DELEGATION.PRO_ID, PROCESS.PRO_TITLE')
->groupBy('APP_DELEGATION.PRO_UID');
$listArray = explode("\\", get_class($this));
$list = end($listArray);
switch ($list) {
case 'Inbox':
$query->inbox($this->getUserId());
break;
case 'Draft':
$query->draft($this->getUserId());
break;
case 'Paused':
$query->paused($this->getUserId());
break;
case 'Unassigned':
$query->selfService($this->getUserUid());
break;
}
$query->joinProcess();
if (!is_null($category)) {
$query->categoryId($category);
}
if ($topTen) {
$query->topTen('TOTAL', 'DESC');
}
if (!empty($processes)) {
2021-08-02 13:06:17 -04:00
$query->processInList($processes);
2021-07-13 11:26:05 -04:00
}
return $query->get()->values()->toArray();
}
2021-07-21 16:18:36 -04:00
/**
* Count how many cases has each process by range of dates
*
* @param int $processId
* @param string $dateFrom
* @param string $dateTo
* @param string $groupBy
*
* @return array
*/
public function getCountersByRange($processId = null, $dateFrom = null, $dateTo = null, $groupBy = 'day')
{
$rawQuery = 'count(APP_DELEGATION.DELEGATION_ID) as TOTAL, APP_DELEGATION.PRO_ID, PROCESS.PRO_TITLE, DATE(APP_DELEGATION.DEL_DELEGATE_DATE) as dateGroup';
switch ($groupBy) {
case 'month':
$rawQuery = 'count(APP_DELEGATION.DELEGATION_ID) as TOTAL, APP_DELEGATION.PRO_ID, PROCESS.PRO_TITLE, EXTRACT(YEAR_MONTH From APP_DELEGATION.DEL_DELEGATE_DATE) as dateGroup';
break;
case 'year':
$rawQuery = 'count(APP_DELEGATION.DELEGATION_ID) as TOTAL, APP_DELEGATION.PRO_ID, PROCESS.PRO_TITLE, YEAR(APP_DELEGATION.DEL_DELEGATE_DATE) as dateGroup';
break;
}
$query = Delegation::selectRaw($rawQuery);
$query->groupBy('dateGroup');
$listArray = explode("\\", get_class($this));
$list = end($listArray);
switch ($list) {
case 'Inbox':
$query->inbox($this->getUserId());
break;
case 'Draft':
$query->draft($this->getUserId());
break;
case 'Paused':
$query->paused($this->getUserId());
break;
case 'Unassigned':
$query->selfService($this->getUserUid());
break;
}
$query->joinProcess();
if (!is_null($processId)) {
2021-08-02 13:06:17 -04:00
$query->processInList([$processId]);
2021-07-21 16:18:36 -04:00
}
if (!is_null($dateFrom)) {
$query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '>=', $dateFrom);
}
if (!is_null($dateTo)) {
$query->where('APP_DELEGATION.DEL_DELEGATE_DATE', '<=', $dateTo);
}
return $query->get()->values()->toArray();
}
}