Merged in feature/PMCORE-2397 (pull request #7601)

PMCORE-2397

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Paula Quispe
2020-12-11 22:20:35 +00:00
committed by Julio Cesar Laura Avendaño
20 changed files with 806 additions and 1431 deletions

View File

@@ -12,20 +12,26 @@ 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 INBOX_STATUSES = ['READ', 'UNREAD'];
const PARTICIPATED_STATUSES = ['STARTED', 'IN_PROGRESS', 'COMPLETED', 'SUPERVISING'];
const RISK_STATUSES = ['ON_TIME', 'AT_RISK', 'OVERDUE'];
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';
const PRIORITIES = [1 => 'VL', 2 => 'L', 3 => 'N', 4 => 'H', 5 => 'VH'];
// Task Colors
const TASK_COLORS = [1 => 'green', 2 => 'red', 3 => 'orange', 4 => 'blue', 5 => 'gray'];
const COLOR_OVERDUE = 1;
const COLOR_ON_TIME = 2;
const COLOR_DRAFT = 3;
const COLOR_PAUSED = 4;
const COLOR_UNASSIGNED = 5;
// Status values
const STATUS_DRAFT = 1;
const STATUS_TODO = 2;
const STATUS_COMPLETED = 3;
const STATUS_CANCELED = 4;
// Filter by category from a process, know as "$category" in the old lists classes
private $categoryUid = '';
@@ -286,11 +292,6 @@ class AbstractCases implements CasesInterface
throw new Exception("Inbox status '{$inboxStatus}' is not valid.");
}
// If empty string is sent, use value 'ALL'
if ($inboxStatus === '') {
$inboxStatus = 'ALL';
}
$this->inboxStatus = $inboxStatus;
}
@@ -321,11 +322,6 @@ class AbstractCases implements CasesInterface
throw new Exception("Participated status '{$participatedStatus}' is not valid.");
}
// If empty string will not apply the filter
if ($participatedStatus === 'ALL') {
$participatedStatus = '';
}
$this->participatedStatus = $participatedStatus;
}
@@ -356,11 +352,6 @@ class AbstractCases implements CasesInterface
throw new Exception("Risk status '{$riskStatus}' is not valid.");
}
// If empty string will not apply the filter
if ($riskStatus === 'ALL') {
$riskStatus = '';
}
$this->riskStatus = $riskStatus;
}

View File

@@ -11,7 +11,7 @@ class Draft extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
@@ -48,7 +48,7 @@ class Draft extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Specific process
if ($this->getProcessId()) {

View File

@@ -11,7 +11,7 @@ class Inbox extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
@@ -51,7 +51,7 @@ class Inbox extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Specific process
if ($this->getProcessId()) {

View File

@@ -12,7 +12,7 @@ class Participated extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
@@ -51,7 +51,7 @@ class Participated extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Scope to search for an specific process
if ($this->getProcessId()) {
@@ -164,10 +164,6 @@ class Participated extends AbstractCases
$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 = [];
@@ -194,7 +190,10 @@ class Participated extends AbstractCases
}
break;
case 'IN_PROGRESS':
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
// Get the detail related to the open thread
if (!empty($item['PENDING'])) {
$item['PENDING'] = $this->prepareTaskPending($item['PENDING']);
}
break;
case 'COMPLETED':
$result = [];
@@ -238,7 +237,7 @@ class Participated extends AbstractCases
// Only distinct APP_NUMBER
$query->distinct();
// Scope for in progress cases
$query->statusIds([Application::STATUS_DRAFT, Application::STATUS_TODO]);
$query->statusIds([self::STATUS_DRAFT, self::STATUS_TODO]);
break;
case 'COMPLETED':
// Scope that search for the COMPLETED

View File

@@ -11,7 +11,7 @@ class Paused extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
@@ -51,7 +51,7 @@ class Paused extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Specific process
if ($this->getProcessId()) {

View File

@@ -12,7 +12,7 @@ class Search extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'APPLICATION.APP_STATUS', // Status
@@ -61,7 +61,7 @@ class Search extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Filter by process
if ($this->getProcessId()) {
@@ -103,7 +103,7 @@ class Search extends AbstractCases
$casesOpen = [];
$casesClosed = [];
foreach ($statuses as $row) {
if ($row === Application::STATUS_DRAFT or $row === Application::STATUS_TODO) {
if ($row === self::STATUS_DRAFT or $row === self::STATUS_TODO) {
$casesOpen[] = $row;
} else {
$casesClosed[] = $row;

View File

@@ -11,7 +11,7 @@ class Supervising extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process Name
'TASK.TAS_TITLE', // Pending Task
'APPLICATION.APP_STATUS', // Status
@@ -49,7 +49,7 @@ class Supervising extends AbstractCases
}
// Specific case title
if (!empty($this->getCaseTitle())) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Scope to search for an specific process
if ($this->getProcessId()) {
@@ -125,8 +125,8 @@ class Supervising extends AbstractCases
$query->joinUser();
// Join with application
$query->joinApplication();
// Only cases in progress
$query->caseInProgress();
// Only cases in to_do
$query->caseTodo();
// Scope that return the results for an specific user
$query->userId($this->getUserId());
// Scope the specific array of processes supervising

View File

@@ -12,7 +12,7 @@ class Unassigned extends AbstractCases
public $columnsView = [
// Columns view in the cases list
'APP_DELEGATION.APP_NUMBER', // Case #
'APP_DELEGATION.APP_NUMBER AS APP_TITLE', // Case Title @todo: Filter by case title, pending from other PRD
'APP_DELEGATION.DEL_TITLE', // Case Title
'PROCESS.PRO_TITLE', // Process
'TASK.TAS_TITLE', // Task
'USERS.USR_USERNAME', // Current UserName
@@ -52,7 +52,7 @@ class Unassigned extends AbstractCases
}
// Specific case title
if ($this->getCaseTitle()) {
// @todo: Filter by case title, pending from other PRD
$query->title($this->getCaseTitle());
}
// Specific process
if ($this->getProcessId()) {
@@ -88,7 +88,7 @@ class Unassigned extends AbstractCases
}
// Add join for application, for get the case title when the case status is TO_DO
$query->joinApplication();
$query->status(Application::STATUS_TODO);
$query->status(self::STATUS_TODO);
/** Apply filters */
$this->filters($query);
/** Apply order and pagination */

View File

@@ -153,7 +153,19 @@ class Delegation extends Model
*/
public function scopeCaseInProgress($query)
{
return $query->where('APPLICATION.APP_STATUS_ID', 2);
return $query->statusIds([Application::STATUS_DRAFT, Application::STATUS_TODO]);
}
/**
* Scope a query to get the to_do cases
*
* @param \Illuminate\Database\Eloquent\Builder $query
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCaseTodo($query)
{
return $query->where('APPLICATION.APP_STATUS_ID', Application::STATUS_TODO);
}
/**
@@ -165,7 +177,7 @@ class Delegation extends Model
*/
public function scopeCaseCompleted($query)
{
return $query->where('APPLICATION.APP_STATUS_ID', 3);
return $query->where('APPLICATION.APP_STATUS_ID', Application::STATUS_COMPLETED);
}
/**
@@ -373,6 +385,37 @@ class Delegation extends Model
return $query->where('APP_DELEGATION.APP_NUMBER', '=', $appNumber);
}
/**
* Scope a query to only include a specific case title
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $search
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTitle($query, string $search)
{
$config = System::getSystemConfiguration();
if ((int)$config['disable_advanced_search_case_title_fulltext'] === 0) {
// Cleaning "fulltext" operators in order to avoid unexpected results
$search = str_replace(
['-', '+', '<', '>', '(', ')', '~', '*', '"'],
['', '', '', '', '', '', '', '', ''],
$search
);
// Build the "fulltext" expression
$search = '+"' . preg_replace('/\s+/', '" +"', addslashes($search)) . '"';
// Searching using "fulltext" index
$query->whereRaw("MATCH(APP_DELEGATION.DEL_TITLE) AGAINST('{$search}' IN BOOLEAN MODE)");
} else {
// Searching using "like" operator
$query->where('APP_DELEGATION.DEL_TITLE', 'LIKE', "%${$search}%");
}
return $query;
}
/**
* Scope a query to only include specific cases
*