Merged in feature/PMCORE-639 (pull request #7588)

PMCORE-2381
This commit is contained in:
Paula Quispe
2020-12-07 17:52:19 +00:00
21 changed files with 1925 additions and 731 deletions

View File

@@ -6,18 +6,20 @@ use Datetime;
use Exception;
use ProcessMaker\BusinessModel\Interfaces\CasesInterface;
use ProcessMaker\BusinessModel\Validator;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
class AbstractCases implements CasesInterface
{
// Constants for validate values
const INBOX_STATUSES = ['', 'ALL', 'READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['', 'ALL', 'STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['', 'ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE'];
const CASE_STATUSES = ['', 'ALL', 'DRAFT', 'TO_DO', 'COMPLETED', 'CANCELLED', 'CANCELED'];
const INBOX_STATUSES = ['ALL', 'READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['ALL', 'STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['ALL', 'ON_TIME', 'AT_RISK', 'OVERDUE'];
const CASE_STATUSES = [0 => 'ALL', 1 => 'DRAFT', 2 => 'TO_DO', 3 => 'COMPLETED', 4 => 'CANCELED'];
const ORDER_DIRECTIONS = ['DESC', 'ASC'];
const CORRECT_CANCELED_STATUS = 'CANCELED';
const INCORRECT_CANCELED_STATUS = 'CANCELLED';
const PRIORITIES = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
const PRIORITIES = [0 => 'ALL', 1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
const TASK_COLORS = [1 => 'green', 2 => 'red', 3 => 'orange', 4 => 'blue', 5 => 'gray'];
const COLOR_OVERDUE = 1;
const COLOR_ON_TIME = 2;
@@ -58,33 +60,62 @@ class AbstractCases implements CasesInterface
// Filter by specific priority
private $priority = 0;
// Filter by specific priorities
private $priorities = [];
// Filter by case status, know as "$filterStatus" in the old "participated last" class
private $caseStatus = '';
// 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;
// Filter by a specific range of case number
private $fromCaseNumber = 0;
private $toCaseNumber = 0;
// 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 = '';
// Filter by specific cases, know as "$appUidCheck" in the old lists classes
private $casesUids = [];
// Filter by specific cases using the case numbers
private $casesNumbers = [];
// Filter range related to the start case date
private $startCaseFrom = '';
private $startCaseTo = '';
// Filter recent cases starting by a specific date, know as "newestthan" in the old lists classes
private $newestThan = '';
// Filter range related to the finish case date
private $finishCaseFrom = '';
private $finishCaseTo = '';
// Filter old cases ending by a specific date, know as "oldestthan" in the old lists classes
private $oldestThan = '';
// Filter range related to the delegate date
private $delegateFrom = '';
private $delegateTo = '';
// 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
private $orderByColumn = 'APP_DELEGATION.APP_NUMBER';
private $orderByColumn = 'APP_NUMBER';
// Sorts the data in descending or ascending order, know as "$dir" in the old lists classes
private $orderDirection = 'DESC';
@@ -96,7 +127,7 @@ class AbstractCases implements CasesInterface
private $offset = 0;
// Number of rows to return
private $limit = 25;
private $limit = 15;
/**
* Set Category Uid value
@@ -290,9 +321,9 @@ class AbstractCases implements CasesInterface
throw new Exception("Participated status '{$participatedStatus}' is not valid.");
}
// If empty string is sent, use value 'ALL'
if ($participatedStatus === '') {
$participatedStatus = 'ALL';
// If empty string will not apply the filter
if ($participatedStatus === 'ALL') {
$participatedStatus = '';
}
$this->participatedStatus = $participatedStatus;
@@ -325,9 +356,9 @@ class AbstractCases implements CasesInterface
throw new Exception("Risk status '{$riskStatus}' is not valid.");
}
// If empty string is sent, use value 'ALL'
if ($riskStatus === '') {
$riskStatus = 'ALL';
// If empty string will not apply the filter
if ($riskStatus === 'ALL') {
$riskStatus = '';
}
$this->riskStatus = $riskStatus;
@@ -346,17 +377,16 @@ class AbstractCases implements CasesInterface
/**
* Set priority value
*
* @param int $priority
* @param string $priority
*
* @throws Exception
*/
public function setPriority(int $priority)
public function setPriority(string $priority)
{
// Validate the priority value
if (!empty($priority)) {
if (!empty(self::PRIORITIES[$priority])) {
$priorityCode = $priority;
} else {
$priorityCode = array_search($priority, self::PRIORITIES);
if (empty($priorityCode) && $priorityCode !== 0) {
throw new Exception("Priority value {$priority} is not valid.");
}
} else {
@@ -378,45 +408,109 @@ class AbstractCases implements CasesInterface
}
/**
* Set Case status
* Set priorities
*
* @param string $caseStatus
* @param array $priorities
*
* @throws Exception
*/
public function setCaseStatus(string $caseStatus)
public function setPriorities(array $priorities)
{
// Convert the value to upper case
$caseStatus = strtoupper($caseStatus);
// Validate the case status
if (!in_array($caseStatus, self::CASE_STATUSES)) {
throw new Exception("Case status '{$caseStatus}' is not valid.");
$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);
}
}
$this->priorities = $prioritiesCode;
}
// If empty string is sent, use value 'ALL'
if ($caseStatus === '') {
$caseStatus = 'ALL';
}
/**
* Get priorities
*
* @return array
*/
public function getPriorities()
{
return $this->priorities;
}
/**
* Set Case status
*
* @param string $status
*
* @throws Exception
*/
public function setCaseStatus(string $status)
{
// Fix the canceled status, this is a legacy code error
if ($caseStatus === self::INCORRECT_CANCELED_STATUS) {
$caseStatus = self::CORRECT_CANCELED_STATUS;
if ($status === self::INCORRECT_CANCELED_STATUS) {
$status = self::CORRECT_CANCELED_STATUS;
}
$this->caseStatus = $caseStatus;
$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
*
* @return string
* @return int
*/
public function getCaseStatus()
{
return $this->caseStatus;
}
/**
* 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
*
@@ -458,15 +552,13 @@ class AbstractCases implements CasesInterface
}
/**
* Set range of Case Number
* Set range of case number from
*
* @param int $from
* @param int $to
*/
public function setRangeCaseNumber(int $from, int $to)
public function setCaseNumberFrom(int $from)
{
$this->fromCaseNumber = $from;
$this->toCaseNumber = $to;
$this->caseNumberFrom = $from;
}
/**
@@ -474,9 +566,19 @@ class AbstractCases implements CasesInterface
*
* @return int
*/
public function getFromCaseNumber()
public function getCaseNumberFrom()
{
return $this->fromCaseNumber;
return $this->caseNumberFrom;
}
/**
* Set range of case number to
*
* @param int $to
*/
public function setCaseNumberTo(int $to)
{
$this->caseNumberTo = $to;
}
/**
@@ -484,9 +586,82 @@ class AbstractCases implements CasesInterface
*
* @return int
*/
public function getToCaseNumber()
public function getCaseNumberTo()
{
return $this->toCaseNumber;
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) {
if(is_numeric($cases)) {
array_push($specificCases,$cases);
} else {
array_push($rangeCases,$cases);
}
}
$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;
}
/**
@@ -530,18 +705,118 @@ class AbstractCases implements CasesInterface
}
/**
* Set Newest Than value
* Set start case from
*
* @param string $newestThan
* @param string $from
*
* @throws Exception
*/
public function setNewestThan(string $newestThan)
public function setStartCaseFrom(string $from)
{
if (!Validator::isDate($newestThan, 'Y-m-d')) {
throw new Exception("Value '{$newestThan}' is not a valid date.");
if (!Validator::isDate($from, 'Y-m-d')) {
throw new Exception("Value '{$from}' is not a valid date.");
}
$this->newestThan = $newestThan;
$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
*
* @param string $delegateFrom
*
* @throws Exception
*/
public function setDelegateFrom(string $delegateFrom)
{
if (!Validator::isDate($delegateFrom, 'Y-m-d')) {
throw new Exception("Value '{$delegateFrom}' is not a valid date.");
}
$this->delegateFrom = $delegateFrom;
}
/**
@@ -549,24 +824,24 @@ class AbstractCases implements CasesInterface
*
* @return string
*/
public function getNewestThan()
public function getDelegateFrom()
{
return $this->newestThan;
return $this->delegateFrom;
}
/**
* Set Oldest Than value
*
* @param string $oldestThan
* @param string $delegateTo
*
* @throws Exception
*/
public function setOldestThan(string $oldestThan)
public function setDelegateTo(string $delegateTo)
{
if (!Validator::isDate($oldestThan, 'Y-m-d')) {
throw new Exception("Value '{$oldestThan}' is not a valid date.");
if (!Validator::isDate($delegateTo, 'Y-m-d')) {
throw new Exception("Value '{$delegateTo}' is not a valid date.");
}
$this->oldestThan = $oldestThan;
$this->delegateTo = $delegateTo;
}
/**
@@ -574,11 +849,112 @@ class AbstractCases implements CasesInterface
*
* @return string
*/
public function getOldestThan()
public function getDelegateTo()
{
return $this->oldestThan;
return $this->delegateTo;
}
/**
* 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
*
@@ -721,6 +1097,40 @@ class AbstractCases implements CasesInterface
return $taskColor;
}
/**
* Get task color according the due date
*
* @param string $pending
*
* @return int
*/
public function prepareTaskPending($pending)
{
$taskPending = json_decode($pending, true);
$result = [];
$i = 0;
foreach ($taskPending as $thread) {
foreach ($thread as $key => $row) {
if($key === 'tas_id') {
$result[$i][$key] = $row;
$result[$i]['tas_title'] = (!empty($row)) ? Task::where('TAS_ID', $row)->first()->TAS_TITLE : '';
}
if($key === 'user_id') {
$result[$i][$key] = $row;
}
if($key === 'due_date') {
$result[$i][$key] = $row;
// Get task color label
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($row) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
}
}
$i ++;
}
return $result;
}
/**
* Set all properties
*
@@ -744,33 +1154,67 @@ class AbstractCases implements CasesInterface
if (!empty($properties['user'])) {
$this->setUserId($properties['user']);
}
// Filter by priority
if (!empty($properties['priority'])) {
$this->setPriority($properties['priority']);
}
// Filter by case number
// Filter by one case number
if (!empty($properties['caseNumber'])) {
$this->setCaseNumber($properties['caseNumber']);
}
// Filter by range of case number
if (!empty($properties['caseNumberFrom']) && !empty($properties['caseNumberTo'])) {
$this->setRangeCaseNumber($properties['caseNumberFrom'], $properties['caseNumberTo']);
}
// Filter by search
if (!empty($properties['search'])) {
$this->setValueToSearch($properties['search']);
// Filter by case title
if (!empty($properties['caseTitle'])) {
$this->setCaseTitle($properties['caseTitle']);
}
/** Apply filters related to MY CASES */
// My cases filter: started, in-progress, completed, supervising
if (!empty($properties['filter']) && get_class($this) === MyCases::class) {
if (!empty($properties['filter']) && get_class($this) === Participated::class) {
$this->setParticipatedStatus($properties['filter']);
}
// Filter by case status
if (!empty($properties['filterStatus']) && get_class($this) === MyCases::class) {
$this->setCaseStatus($properties['filterStatus']);
// Filter by one case status
if (!empty($properties['caseStatus']) && get_class($this) === Participated::class) {
$this->setCaseStatus($properties['caseStatus']);
}
// Filter by case status
if (!empty($properties['filterStatus']) && get_class($this) === Search::class) {
$this->setCaseStatus($properties['filterStatus']);
// Filter date related to started date from
if (!empty($properties['startCaseFrom'] && (get_class($this) === Participated::class || get_class($this) === Supervising::class))) {
$this->setStartCaseFrom($properties['startCaseFrom']);
}
// Filter date related to started date to
if (!empty($properties['startCaseTo']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
$this->setStartCaseTo($properties['startCaseTo']);
}
// Filter date related to finish date from
if (!empty($properties['finishCaseFrom']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
$this->setFinishCaseFrom($properties['finishCaseFrom']);
}
// Filter date related to finish date to
if (!empty($properties['finishCaseTo']) && (get_class($this) === Participated::class || get_class($this) === Supervising::class)) {
$this->setFinishCaseTo($properties['finishCaseTo']);
}
/** Apply filters related to SEARCH */
// Add a filter with specific cases or range of cases like '1, 3-5, 8, 10-15'
if (!empty($properties['filterCases']) && get_class($this) === Search::class) {
$this->setFilterCases($properties['filterCases']);
}
// Filter by more than one case statuses like ['DRAFT', 'TO_DO']
if (!empty($properties['caseStatuses']) && get_class($this) === Search::class) {
$this->setCaseStatuses($properties['caseStatuses']);
}
// Filter by more than one priorities like ['VL', 'L', 'N']
if (!empty($properties['priorities']) && get_class($this) === Search::class) {
$this->setProperties($properties['priorities']);
}
// Filter date newest related to delegation/started date
if (!empty($properties['delegationDateFrom'] && get_class($this) === Search::class)) {
$this->setDelegateFrom($properties['delegationDateFrom']);
}
// Filter date oldest related to delegation/started date
if (!empty($properties['delegationDateTo']) && get_class($this) === Search::class) {
$this->setDelegateTo($properties['delegationDateTo']);
}
// Filter date newest related to due date
if (!empty($properties['dueDateFrom']) && get_class($this) === Search::class) {
$this->setDueFrom($properties['dueDateFrom']);
}
// Filter date oldest related to due date
if (!empty($properties['dueDateTo']) && get_class($this) === Search::class) {
$this->setDueTo($properties['dueDateTo']);
}
// Filter by case uid
if (!empty($properties['caseLink'])) {
@@ -780,14 +1224,6 @@ class AbstractCases implements CasesInterface
if (!empty($properties['appUidCheck'])) {
$this->setCasesUids($properties['appUidCheck']);
}
// Filter date newest related to delegation date
if (!empty($properties['newestthan'])) {
$this->setNewestThan($properties['newestthan']);
}
// Filter date oldest related to delegation date
if (!empty($properties['oldestthan'])) {
$this->setOldestThan($properties['oldestthan']);
}
// Sort column
if (!empty($properties['sort'])) {
$this->setOrderByColumn($properties['sort']);

View File

@@ -18,7 +18,8 @@ class Draft extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -30,6 +31,39 @@ class Draft extends AbstractCases
return $this->columnsView;
}
/**
* 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());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// 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;
}
/**
* Get data self-services cases by user
*
@@ -44,18 +78,9 @@ class Draft extends AbstractCases
$query->joinTask();
// Join with application for add the initial scope for DRAFT cases
$query->draft($this->getUserId());
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
@@ -92,6 +117,7 @@ class Draft extends AbstractCases
$query = Delegation::query()->select();
// Add the initial scope for draft cases
$query->draft($this->getUserId());
$this->filters($query);
return $query->count();
}

View File

@@ -21,7 +21,8 @@ class Inbox extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -33,6 +34,39 @@ class Inbox extends AbstractCases
return $this->columnsView;
}
/**
* 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());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// 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;
}
/**
* Get the data corresponding to List Inbox
*
@@ -48,30 +82,16 @@ class Inbox extends AbstractCases
$query->joinUser();
// Join with application for add the initial scope for TO_DO cases
$query->inbox($this->getUserId());
// Define a specific risk
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;
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$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
// Execute the query
$results = $query->get();
// Prepare the result
$results->transform(function ($item, $key) {

View File

@@ -1,62 +0,0 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
class MyCases extends AbstractCases
{
/**
* Gets the data for the Cases list My Cases
*
* @return array
*/
public function getData()
{
$filter = $this->getParticipatedStatus();
$result = [];
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$result = $list->getData();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$result = $list->getData();
break;
}
}
return $result;
}
/**
* Gets the total of My Cases
*
* @return int
*/
public function getCounter()
{
$filter = $this->getParticipatedStatus();
$count = 0;
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$count = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$count = $list->getCounter();
break;
}
}
return $count;
}
}

View File

@@ -2,8 +2,8 @@
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Task;
class Participated extends AbstractCases
{
@@ -15,11 +15,13 @@ class Participated extends AbstractCases
'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Start Date
'APP_DELEGATION.DEL_FINISH_DATE', // Finish Date
'APPLICATION.APP_CREATE_DATE', // Start Date
'APPLICATION.APP_FINISH_DATE', // Finish Date
'USERS.USR_ID', // Current UserId
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -31,6 +33,59 @@ class Participated extends AbstractCases
return $this->columnsView;
}
/**
* 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());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// 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;
}
/**
* Get the data corresponding to Participated
*
@@ -39,13 +94,15 @@ class Participated extends AbstractCases
public function getData()
{
// Start the query for get the cases related to the user
$query = Delegation::query()->select();
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
// Join with application
$query->joinApplication();
// Scope to Participated
$query->participated($this->getUserId());
// Add filter
@@ -53,29 +110,42 @@ class Participated extends AbstractCases
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
// Scope that search for the STARTED
// Scope that search for the STARTED by user
$query->caseStarted();
break;
case 'IN-PROGRESS':
case 'IN_PROGRESS':
// Scope that search for the TO_DO
$query->selectRaw(
'CONCAT(
\'[\',
GROUP_CONCAT(
CONCAT(
\'{"tas_id":\',
APP_DELEGATION.TAS_ID,
\', "user_id":\',
APP_DELEGATION.USR_ID,
\', "due_date":"\',
APP_DELEGATION.DEL_TASK_DUE_DATE,
\'"}\'
)
),
\']\'
) AS PENDING'
);
$query->caseInProgress();
$query->groupBy('APP_NUMBER');
break;
case 'COMPLETED':
// Scope that search for the COMPLETED
$query->caseCompleted();
// Scope to set the last thread
$query->lastThread();
break;
}
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// Scope the specific case status
$status = $this->getCaseStatus();
if (array_key_exists($status, Application::$app_status_values)) {
$statusId = Application::$app_status_values[$status];
$query->appStatusId($statusId);
}
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause
@@ -83,17 +153,57 @@ class Participated extends AbstractCases
//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']];
$results->transform(function ($item, $key) use ($filter) {
// Apply the date format defined in environment
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
$item['DEL_FINISH_DATE_LABEL'] = !empty($item['DEL_FINISH_DATE']) ? applyMaskDateEnvironment($item['DEL_FINISH_DATE']): null;
$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 = $item['DEL_DELEGATE_DATE'];
$endDate = !empty($item['DEL_FINISH_DATE']) ? $item['DEL_FINISH_DATE'] : date("Y-m-d H:i:s");
$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);
// Get the detail related to the open thread
if (!empty($item['PENDING'])) {
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
}
switch ($filter) {
case 'STARTED':
$result = [];
$i = 0;
if ($item['APP_STATUS'] === 'TO_DO') {
$taskPending = Delegation::getPendingThreads($item['APP_NUMBER']);
foreach ($taskPending as $thread) {
// todo this need to review
$result[$i]['tas_title'] = $thread['TAS_TITLE'];
$result[$i]['user_id'] = $thread['USR_ID'];
$result[$i]['due_date'] = $thread['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($thread['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$i++;
}
$item['PENDING'] = $result;
} else {
$result[$i]['tas_title'] = $item['TAS_TITLE'];
$result[$i]['user_id'] = $item['USR_ID'];
$result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$item['PENDING'] = $result;
}
break;
case 'IN_PROGRESS':
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
break;
case 'COMPLETED':
$result = [];
$i = 0;
$result[$i]['tas_title'] = $item['TAS_TITLE'];
$result[$i]['user_id'] = $item['USR_ID'];
$result[$i]['due_date'] = $item['DEL_TASK_DUE_DATE'];
$result[$i]['tas_color'] = (!empty($row)) ? $this->getTaskColor($item['DEL_TASK_DUE_DATE']) : '';
$result[$i]['tas_color_label'] = (!empty($row)) ? self::TASK_COLORS[$result[$i]['tas_color']] : '';
$item['PENDING'] = $result;
break;
}
return $item;
});

View File

@@ -21,7 +21,8 @@ class Paused extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -33,6 +34,39 @@ class Paused extends AbstractCases
return $this->columnsView;
}
/**
* 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());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// 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;
}
/**
* Gets the data for the paused cases list
*
@@ -44,11 +78,10 @@ class Paused extends AbstractCases
// Join with process
$query->joinProcess();
// Scope that set the paused cases
$query->paused($this->getUserId(), $this->getTaskId(), $this->getCaseNumber());
// Join with delegation for get the previous index
$query->joinPreviousIndex();
// Join with delegation for get the previous user
$query->joinPreviousUser();
$query->paused($this->getUserId(), $this->getTaskId());
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// Add pagination to the query

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
class Search extends AbstractCases
@@ -14,6 +15,7 @@ class Search extends AbstractCases
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'APPLICATION.APP_STATUS', // Status
'USERS.USR_USERNAME', // Current UserName
'USERS.USR_FIRSTNAME', // Current User FirstName
'USERS.USR_LASTNAME', // Current User LastName
@@ -21,7 +23,8 @@ class Search extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -33,6 +36,101 @@ class Search extends AbstractCases
return $this->columnsView;
}
/**
* Scope filters
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function filters($query)
{
// Filter case by case number
if ($this->getCaseNumber()) {
$query->case($this->getCaseNumber());
}
// Filter cases by specific cases like [1,3,5]
if (!empty($this->getCasesNumbers())) {
$query->specificCases($this->getCasesNumbers());
}
// Filter cases by range of cases like ['1-5', '10-15']
if (!empty($this->getRangeCasesFromTo())) {
$query->rangeOfCases($this->getRangeCasesFromTo());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// Filter by process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Filter by user
if ($this->getUserId()) {
$query->userId($this->getUserId());
}
// Filter by task
if ($this->getTaskId()) {
$query->task($this->getTaskId());
}
// Filter one or more priorities like ['VL', 'L', 'N']
if (!empty($this->getPriorities())) {
$query->priorities($this->getPriorities());
}
// Filter by delegate from
if (!empty($this->getDelegateFrom())) {
$query->delegateDateFrom($this->getDelegateFrom());
}
// Filter by delegate to
if (!empty($this->getDelegateTo())) {
$query->delegateDateTo($this->getDelegateTo());
}
// Filter by due from
if (!empty($this->getDueFrom())) {
$query->dueFrom($this->getDueFrom());
}
// Filter by due to
if (!empty($this->getDueTo())) {
$query->dueTo($this->getDueTo());
}
/** This filter define the UNION */
// Filter related to the case status like ['DRAFT', 'TO_DO']
if (!empty($this->getCaseStatuses())) {
$statuses = $this->getCaseStatuses();
$casesOpen = [];
$casesClosed = [];
foreach ($statuses as $row) {
if ($row === Application::STATUS_DRAFT or $row === Application::STATUS_TODO) {
$casesOpen[] = $row;
} else {
$casesClosed[] = $row;
}
}
if (!empty($casesOpen) && !empty($casesClosed)) {
// Only in this case need to clone the same query for the union
$cloneQuery = clone $query;
// Get the open threads
$query->casesInProgress($casesOpen);
// Get the last thread
$cloneQuery->casesDone($casesClosed);
// Union
$query->union($cloneQuery);
} else {
if (!empty($casesOpen)) {
// Get the open thread
$query->casesInProgress($casesOpen);
}
if (!empty($casesClosed)) {
// Get the last thread
$query->casesDone($casesClosed);
}
}
}
return $query;
}
/**
* Get the data corresponding to advanced search
*
@@ -47,33 +145,11 @@ class Search extends AbstractCases
$query->joinTask();
// Join with users
$query->joinUser();
// Filter by case number
if ($this->getCaseNumber() > 0) {
$query->case($this->getCaseNumber());
}
// Filter by case number: from and to
if ($this->getFromCaseNumber() > 0 && $this->getToCaseNumber() > 0) {
$query->rangeOfCases($this->getFromCaseNumber(), $this->getToCaseNumber());
}
// @todo: Filter by case title, pending from other PRD
// Filter by priority
if ($this->getPriority() > 0) {
$query->priority($this->getPriority());
}
// Filter by process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
// Filter by user
if (!empty($this->getUserId())) {
$query->userId($this->getUserId());
}
// Filter by task
if (!empty($this->getTaskId())) {
$query->task($this->getTaskId());
}
// Join with application
$query->joinApplication();
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause

View File

@@ -15,11 +15,12 @@ class Supervising extends AbstractCases
'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
'APP_DELEGATION.DEL_DELEGATE_DATE', // Start Date
'APP_DELEGATION.DEL_FINISH_DATE', // Finish Date
'APPLICATION.APP_CREATE_DATE', // Start Date
'APPLICATION.APP_FINISH_DATE', // Finish Date
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date related to the colors
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -31,6 +32,59 @@ class Supervising extends AbstractCases
return $this->columnsView;
}
/**
* 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());
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
}
// 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;
}
/**
* Gets the data for the Cases list Review
*
@@ -40,51 +94,53 @@ class Supervising extends AbstractCases
{
// Get the list of processes of the supervisor
$processes = ProcessUser::getProcessesOfSupervisor($this->getUserUid());
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
$query->joinProcess();
// Join with users
$query->joinUser();
// Join with task and scope that sets the queries for List Inbox
$query->inbox($this->getUserId());
// Scope the specific array of processes supervising
$query->processInList($processes);
// Join with delegation for get the previous index
$query->joinPreviousIndex();
// Join with delegation for get the previous user
$query->joinPreviousUser();
// Scope to search for an specific case
if (!empty($this->getCaseNumber())) {
$query->case($this->getCaseNumber());
}
// Scope to search for an specific process
if (!empty($this->getProcessId())) {
$query->processId($this->getProcessId());
}
//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['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
$item['DEL_FINISH_DATE_LABEL'] = !empty($item['DEL_FINISH_DATE']) ? applyMaskDateEnvironment($item['DEL_FINISH_DATE']): null;
// Calculate duration
$startDate = $item['DEL_DELEGATE_DATE'];
$endDate = !empty($item['DEL_FINISH_DATE']) ? $item['DEL_FINISH_DATE'] : date("Y-m-d H:i:s");
$item['DURATION'] = getDiffBetweenDates($startDate, $endDate);
// 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());
// Join with process
$query->joinProcess();
// Join with task
$query->joinTask();
// Join with users
$query->joinUser();
// Join with application
$query->joinApplication();
// Only cases in progress
$query->caseInProgress();
// Scope that return the results for an specific user
$query->userId($this->getUserId());
// Scope the specific array of processes supervising
$query->processInList($processes);
/** 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);
return $item;
});
return $item;
});
return $results->values()->toArray();
return $results->values()->toArray();
} else {
return [];
}
}
/**

View File

@@ -22,7 +22,8 @@ class Unassigned extends AbstractCases
'APP_DELEGATION.DEL_DELEGATE_DATE', // Delegate Date
'APP_DELEGATION.DEL_PRIORITY', // Priority
// Additional column for other functionalities
'APP_DELEGATION.APP_UID', // Case Uid for PMFCaseLink
'APP_DELEGATION.APP_UID', // Case Uid for Open case
'APP_DELEGATION.DEL_INDEX', // Del Index for Open case
];
/**
@@ -34,6 +35,39 @@ class Unassigned extends AbstractCases
return $this->columnsView;
}
/**
* 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());
}
// Specific case title
if ($this->getCaseTitle()) {
// @todo: Filter by case title, pending from other PRD
}
// 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;
}
/**
* Get data self-services cases by user
*
@@ -47,28 +81,15 @@ class Unassigned extends AbstractCases
// Join with users
$query->joinUser();
// Join with application for add the initial scope for unassigned cases
$query->selfService($this->getUserUid());
if (!empty($this->getUserUid())) {
$query->selfService($this->getUserUid());
}
// Add join for application, for get the case title when the case status is TO_DO
$query->appStatusId(Application::STATUS_TODO);
// Specific process
if ($this->getProcessId()) {
$query->processId($this->getProcessId());
}
// Date range filter, this is used from mobile GET /light/unassigned
if ($this->getNewestThan()) {
$query->delegateDateFrom($this->getNewestThan());
}
if ($this->getOldestThan()) {
$query->delegateDateTo($this->getOldestThan());
}
// Specific case uid
if (!empty($this->getCaseUid())) {
$query->appUid($this->getCaseUid());
}
// Specific cases
if (!empty($this->getCasesUids())) {
$query->specificCasesByUid($this->getCasesUids());
}
$query->joinApplication();
$query->status(Application::STATUS_TODO);
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */
// Add any sort if needed
if ($this->getOrderByColumn()) {
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());

View File

@@ -66,6 +66,18 @@ class Delegation extends Model
return $query->where('DEL_PRIORITY', $priority);
}
/**
* Scope a query to only include specific priorities
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $priorities
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePriorities($query, array $priorities)
{
return $query->whereIn('DEL_PRIORITY', $priorities);
}
/**
* Scope a query to only include open threads
*
@@ -77,6 +89,34 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.DEL_THREAD_STATUS', '=', 'OPEN');
}
/**
* Scope to use when the case is IN_PROGRESS like DRAFT or TO_DO
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $ids
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesInProgress($query, array $ids)
{
$query->isThreadOpen()->statusIds($ids);
return $query;
}
/**
* Scope to use when the case is DONE like COMPLETED or CANCELED
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $ids
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesDone($query, array $ids)
{
$query->lastThread()->statusIds($ids);
return $query;
}
/**
* Scope a query to only include a specific index
*
@@ -111,7 +151,7 @@ class Delegation extends Model
*/
public function scopeCaseInProgress($query)
{
return $query->appStatusId(2);
return $query->where('APPLICATION.APP_STATUS_ID', 2);
}
/**
@@ -123,7 +163,85 @@ class Delegation extends Model
*/
public function scopeCaseCompleted($query)
{
return $query->appStatusId(3);
return $query->where('APPLICATION.APP_STATUS_ID', 3);
}
/**
* Scope a query to get specific status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $statusId
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStatus($query, int $statusId)
{
return $query->where('APPLICATION.APP_STATUS_ID', $statusId);
}
/**
* Scope a more status
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $statuses
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStatusIds($query, array $statuses)
{
return $query->whereIn('APPLICATION.APP_STATUS_ID', $statuses);
}
/**
* Scope a query to only include a specific start date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStartDateFrom($query, string $from)
{
return $query->where('APPLICATION.APP_CREATE_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific start date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeStartDateTo($query, string $to)
{
return $query->where('APPLICATION.APP_CREATE_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishCaseFrom($query, string $from)
{
return $query->where('APPLICATION.APP_FINISH_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishCaseTo($query, string $to)
{
return $query->where('APPLICATION.APP_FINISH_DATE', '<=', $to);
}
/**
@@ -134,7 +252,7 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDelegateDateFrom($query, $from)
public function scopeDelegateDateFrom($query, string $from)
{
return $query->where('DEL_DELEGATE_DATE', '>=', $from);
}
@@ -147,11 +265,63 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDelegateDateTo($query, $to)
public function scopeDelegateDateTo($query, string $to)
{
return $query->where('DEL_DELEGATE_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishDateFrom($query, $from)
{
return $query->where('DEL_FINISH_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific finish date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFinishDateTo($query, $to)
{
return $query->where('DEL_FINISH_DATE', '<=', $to);
}
/**
* Scope a query to only include a specific due date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDueFrom($query, $from)
{
return $query->where('DEL_TASK_DUE_DATE', '>=', $from);
}
/**
* Scope a query to only include a specific due date
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeDueTo($query, $to)
{
return $query->where('DEL_TASK_DUE_DATE', '<=', $to);
}
/**
* Scope a query to get only the date on time
*
@@ -201,21 +371,6 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.APP_NUMBER', '=', $appNumber);
}
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $from
* @param int $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRangeOfCases($query, int $from, int $to)
{
return $query->where('APP_DELEGATION.APP_NUMBER', '>=', $from)
->where('APP_DELEGATION.APP_NUMBER', '<=', $to);
}
/**
* Scope a query to only include specific cases
*
@@ -229,6 +384,57 @@ class Delegation extends Model
return $query->whereIn('APP_DELEGATION.APP_NUMBER', $cases);
}
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $from
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesFrom($query, int $from)
{
return $query->where('APP_DELEGATION.APP_NUMBER', '>=', $from);
}
/**
* Scope a query to only include cases from a range
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $to
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCasesTo($query, int $to)
{
return $query->where('APP_DELEGATION.APP_NUMBER', '<=', $to);
}
/**
* Scope more than one range of cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $rangeCases
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRangeOfCases($query, array $rangeCases)
{
foreach ($rangeCases as $fromTo) {
$fromTo = explode("-", $fromTo);
if (count($fromTo) === 2) {
$from = $fromTo[0];
$to = $fromTo[1];
if ($to > $from) {
$query->orWhere(function ($query) use ($from, $to) {
$query->casesFrom($from)->casesTo($to);
});
}
}
}
}
/**
* Scope a query to get the delegations from a case by APP_UID
*
@@ -469,7 +675,8 @@ class Delegation extends Model
public function scopeInbox($query, $userId)
{
// This scope is for the join with the APP_DELEGATION table
$query->appStatusId(2);
$query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
@@ -493,7 +700,8 @@ class Delegation extends Model
public function scopeInboxWithoutUser($query)
{
// This scope is for the join with the APP_DELEGATION table
$query->appStatusId(2);
$query->joinApplication();
$query->status(Application::STATUS_TODO);
// Scope for the restriction of the task that must not be searched for
$query->excludeTaskTypes(Task::DUMMY_TASKS);
@@ -535,7 +743,8 @@ class Delegation extends Model
public function scopeDraft($query, $user)
{
// Add join for application, for get the case title when the case status is DRAFT
$query->appStatusId(Application::STATUS_DRAFT);
$query->joinApplication();
$query->status(Application::STATUS_TODO);
// Case assigned to the user
$query->userId($user);
@@ -554,8 +763,6 @@ class Delegation extends Model
{
// Scope to set the user
$query->userId($user);
// Scope to set the last thread
$query->lastThread();
return $query;
}
@@ -720,15 +927,12 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePaused($query, int $userId, int $taskId, int $caseNumber)
public function scopePaused($query, int $userId, int $taskId)
{
$query->joinAppDelay('PAUSE');
$query->joinAppDelayUsers($userId);
$query->joinApplication();
// Specific case number
if (!empty($caseNumber)) {
$query->case($caseNumber);
}
// Exclude some specific task
$query->excludeTaskTypes(Task::DUMMY_TASKS);
// Specific task
if (!empty($taskId)) {
@@ -1401,13 +1605,13 @@ class Delegation extends Model
/**
* This function get the current user related to the specific case and index
*
* @param integer $appNumber, Case number
* @param integer $index, Index to review
* @param int $appNumber, Case number
* @param int $index, Index to review
* @param string $status, The status of the thread
*
* @return string
*/
public static function getCurrentUser($appNumber, $index, $status = 'OPEN')
public static function getCurrentUser(int $appNumber, int $index, $status = 'OPEN')
{
$query = Delegation::query()->select('USR_UID');
$query->where('APP_NUMBER', $appNumber);
@@ -1427,12 +1631,12 @@ class Delegation extends Model
/**
* Return the open thread related to the task
*
* @param integer $appNumber, Case number
* @param int $appNumber, Case number
* @param string $tasUid, The task uid
*
* @return array
*/
public static function getOpenThreads($appNumber, $tasUid)
public static function getOpenThreads(int $appNumber, string $tasUid)
{
$query = Delegation::query()->select();
$query->where('DEL_THREAD_STATUS', 'OPEN');
@@ -1457,7 +1661,7 @@ class Delegation extends Model
*
* @return boolean
*/
public static function participation($appUid, $userUid)
public static function participation(string $appUid, string $userUid)
{
$query = Delegation::query()->select();
$query->where('APP_UID', $appUid);
@@ -1515,4 +1719,31 @@ class Delegation extends Model
return $thread;
}
/**
* Return the open thread related to the task
*
* @param int $appNumber
*
* @return array
*/
public static function getPendingThreads(int $appNumber)
{
$query = Delegation::query()->select([
'TASK.TAS_TITLE',
'APP_DELEGATION.USR_ID',
'APP_DELEGATION.DEL_TASK_DUE_DATE'
]);
// Join with task
$query->joinTask();
// Get the open threads
$query->threadOpen();
// Related to the specific case number
$query->case($appNumber);
// Get the results
$results = $query->get()->values()->toArray();
return $results;
}
}

View File

@@ -64,41 +64,29 @@ class ProcessUser extends Model
return $query;
}
/**
* It returns a list of processes ids as an array
*
* @param array $processes
* @return array
*/
public static function getListOfProcessUid($processes)
{
$res = (array_map(function ($x) {
if (array_key_exists('PRO_ID', $x)) {
return $x['PRO_ID'];
}
}, $processes));
return array_filter($res);
}
/**
* It returns a list of processes of the supervisor
*
* @param string $userUid
* @return array
*/
public static function getProcessesOfSupervisor($userUid)
public static function getProcessesOfSupervisor(string $userUid)
{
$query1 = ProcessUser::query()->select(['PRO_ID']);
$query1->processSupervisor($userUid);
$processes = $query1->get()->values()->toArray();
$query2 = ProcessUser::query()->select(['PRO_ID']);
$query2->processGroupSupervisor($userUid);
array_push($processes, $query2->get()->values()->toArray());
$processes = ProcessUser::getListOfProcessUid($processes);
// Get the list of process when the user is supervisor
$query = ProcessUser::query()->select(['PRO_ID']);
$query->processSupervisor($userUid);
$results = $query->get();
$processes = [];
$results->each(function ($item, $key) use (&$processes) {
$processes[] = $item->PRO_ID;
});
// Get the list of process when the group related to the user is supervisor
$query = ProcessUser::query()->select(['PRO_ID']);
$query->processGroupSupervisor($userUid);
$results = $query->get();
$results->each(function ($item, $key) use (&$processes) {
$processes[] = $item->PRO_ID;
});
return $processes;
}

View File

@@ -0,0 +1,463 @@
<?php
namespace ProcessMaker\Services\Api;
use Exception;
use Luracast\Restler\RestException;
use ProcessMaker\BusinessModel\Cases\Draft;
use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\BusinessModel\Cases\Participated;
use ProcessMaker\BusinessModel\Cases\Paused;
use ProcessMaker\BusinessModel\Cases\Search;
use ProcessMaker\BusinessModel\Cases\Supervising;
use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\Model\User;
use ProcessMaker\Services\Api;
use RBAC;
class Home extends Api
{
/**
* Constructor of the class
* We will to define the $RBAC definition
*/
public function __construct()
{
global $RBAC;
if (!isset($RBAC)) {
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
$RBAC->sSystem = 'PROCESSMAKER';
$RBAC->initRBAC();
$RBAC->loadUserRolePermission($RBAC->sSystem, $this->getUserId());
}
}
/**
* Get the draft cases
*
* @url GET /draft
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetDraftCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Draft();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the inbox cases
*
* @url GET /todo
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetTodoCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Inbox();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the unassigned cases
*
* @url GET /unassigned
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetUnassignedCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Unassigned();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
// todo: some queries related to the unassigned are using the USR_UID
$list->setUserUid($usrUid);
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the paused cases
*
* @url GET /paused
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetPausedCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Paused();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the my cases
*
* @url GET /mycases
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param string $caseTitle
* @param string $startCaseFrom
* @param string $startCaseTo
* @param string $finishCaseFrom
* @param string $finishCaseTo
* @param string $filter
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetMyCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
string $caseTitle = '',
string $filter = 'IN_PROGRESS',
string $startCaseFrom = '',
string $startCaseTo = '',
string $finishCaseFrom = '',
string $finishCaseTo = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = User::find($usrUid)->first()->USR_ID;
$properties['filter'] = $filter;
$properties['startCaseFrom'] = $startCaseFrom;
$properties['startCaseTo'] = $startCaseTo;
$properties['finishCaseFrom'] = $finishCaseFrom;
$properties['finishCaseTo'] = $finishCaseTo;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$result = [];
try {
if (!empty($filter)) {
switch ($filter) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$list->setParticipatedStatus($filter);
$list->setProperties($properties);
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$list->setProperties($properties);
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
break;
}
}
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get counters
*
* @url GET /counters
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetCountMyCases()
{
try {
$filters = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
$result = [];
foreach ($filters as $row) {
switch ($row) {
case 'STARTED':
case 'IN_PROGRESS':
case 'COMPLETED':
$list = new Participated();
$list->setParticipatedStatus($row);
$list->setUserId($this->getUserId());
$result[strtolower($row)] = $list->getCounter();
break;
case 'SUPERVISING':
// Scope that search for the SUPERVISING cases by specific user
$list = new Supervising();
$list->setUserId($this->getUserId());
$result[strtolower($row)] = $list->getCounter();
break;
default:
$result[strtolower($row)] = 0;
}
}
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the search cases
*
* @url GET /search
*
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $user
* @param string $caseTitle
* @param string $priorities
* @param string $caseStatuses
* @param string $filterCases
* @param string $dueDateFrom
* @param string $dueDateTo
* @param string $delegationDateFrom
* @param string $delegationDateTo
* @param string $paged
* @param string $sort
*
* @return array
*
* @throws Exception
*
* @access protected
* @class AccessControl {@permission PM_ALLCASES}
*/
public function doGetSearchCases(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $user = 0,
string $caseTitle = '',
string $priorities = '',
string $caseStatuses = '',
string $filterCases = '',
string $dueDateFrom = '',
string $dueDateTo = '',
string $delegationDateFrom = '',
string $delegationDateTo = '',
string $paged = '0,15',
string $sort ='APP_NUMBER,ASC'
){
try {
$list = new Search();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['process'] = $process;
$properties['task'] = $task;
$properties['user'] = $user;
$properties['priorities'] = explode(',', $priorities);
$properties['caseStatuses'] = explode(',', $caseStatuses);
$properties['filterCases'] = $filterCases;
$properties['dueDateFrom'] = $dueDateFrom;
$properties['dueDateTo'] = $dueDateTo;
$properties['delegationDateFrom'] = $delegationDateFrom;
$properties['delegationDateTo'] = $delegationDateTo;
// Set the pagination parameters
$paged = explode(',', $paged);
$sort = explode(',', $sort);
$properties['start'] = $paged[0];
$properties['limit'] = $paged[1];
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = $list->getData();
$result['total'] = $list->getCounter();
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}