PMCORE-1214

This commit is contained in:
Paula Quispe
2020-11-05 17:50:41 -04:00
parent f54708214f
commit 939d479a06
5 changed files with 485 additions and 36 deletions

View File

@@ -16,6 +16,7 @@ class AbstractCases implements CasesInterface
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'];
// Filter by category from a process, know as "$category" in the old lists classes
private $categoryUid = '';
@@ -26,6 +27,9 @@ class AbstractCases implements CasesInterface
// Filter by process using the Id field
private $processId = 0;
// Filter by task using the Id field
private $taskId = 0;
// Filter by user, know as "$user" in the old lists classes
private $userUid = '';
@@ -44,6 +48,9 @@ class AbstractCases implements CasesInterface
// Filter by risk status, know as "$filterStatus" in the old list "inbox" class
private $riskStatus = '';
// Filter by specific priority
private $priority = 0;
// Filter by case status, know as "$filterStatus" in the old "participated last" class
private $caseStatus = '';
@@ -53,6 +60,10 @@ class AbstractCases implements CasesInterface
// 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, know as "$appUidCheck" in the old lists classes
private $casesUids = [];
@@ -140,6 +151,26 @@ class AbstractCases implements CasesInterface
return $this->processId;
}
/**
* 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
*
@@ -296,7 +327,7 @@ class AbstractCases implements CasesInterface
}
/**
* Get risk status
* Get risk value
*
* @return string
*/
@@ -305,6 +336,40 @@ class AbstractCases implements CasesInterface
return $this->riskStatus;
}
/**
* Set priority value
*
* @param int $priority
*
* @throws Exception
*/
public function setPriority(int $priority)
{
// Validate the priority value
if (!empty($priority)) {
if (!empty(self::PRIORITIES[$priority])) {
$priorityCode = $priority;
} else {
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;
}
/**
* Set Case status
*
@@ -385,6 +450,38 @@ class AbstractCases implements CasesInterface
return $this->caseNumber;
}
/**
* Set range of Case Number
*
* @param int $from
* @param int $to
*/
public function setRangeCaseNumber(int $from, int $to)
{
$this->fromCaseNumber = $from;
$this->toCaseNumber = $to;
}
/**
* Get from Case Number
*
* @return int
*/
public function getFromCaseNumber()
{
return $this->fromCaseNumber;
}
/**
* Get to Case Number
*
* @return int
*/
public function getToCaseNumber()
{
return $this->toCaseNumber;
}
/**
* Set Cases Uids
*
@@ -603,10 +700,26 @@ class AbstractCases implements CasesInterface
$this->setProcessUid($properties['process']);
}
if (!empty($properties['task'])) {
$this->setTaskId($properties['task']);
}
if (!empty($properties['user'])) {
$this->setUserUid($properties['user']);
}
if (!empty($properties['priority'])) {
$this->setPriority($properties['priority']);
}
if (!empty($properties['caseNumber'])) {
$this->setCaseNumber($properties['caseNumber']);
}
if (!empty($properties['caseNumberFrom']) && !empty($properties['caseNumberTo'])) {
$this->setRangeCaseNumber($properties['caseNumberFrom'], $properties['caseNumberTo']);
}
if (!empty($properties['search'])) {
$this->setValueToSearch($properties['search']);
}

View File

@@ -0,0 +1,76 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\Model\Delegation;
class Search extends AbstractCases
{
/**
* Get the data corresponding to advanced search
*
* @return array
*/
public function getData()
{
$query = Delegation::query()->select();
// Filter by case number
$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 category
$query->categoryProcess($this->getCategoryUid());
// 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());
}
// The order by clause
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// The limit by clause
$query->offset($this->getOffset())->limit($this->getLimit());
//Execute the query
$results = $query->get();
//Return the values as an array format
return $results->values()->toArray();
}
/**
* Get the number of rows corresponding to the advanced search
*
* @return int
*/
public function getCounter()
{
$query = Delegation::query()->select();
// Return the number of rows
return $query->count();
}
}

View File

@@ -54,6 +54,18 @@ class Delegation extends Model
return $this->belongsTo(Process::class, 'PRO_ID', 'PRO_ID');
}
/**
* Scope a query to only include specific priority
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $priority
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopePriority($query, int $priority)
{
return $query->where('DEL_PRIORITY', $priority);
}
/**
* Scope a query to only include open threads
*
@@ -73,7 +85,7 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIndex($query, $index)
public function scopeIndex($query, int $index)
{
return $query->where('DEL_INDEX', '=', $index);
}
@@ -177,6 +189,21 @@ 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
*
@@ -305,7 +332,7 @@ class Delegation extends Model
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTask($query, $task)
public function scopeTask($query, int $task)
{
return $query->where('APP_DELEGATION.TAS_ID', '=', $task);
}
@@ -1273,37 +1300,4 @@ class Delegation extends Model
return $thread;
}
/**
* Helper to get the priority code from a given value
*
* @param int $priorityValue
*
* @return string
*
* @throws Exception
*/
public static function getPriorityCode($priorityValue)
{
if (!empty(self::PRIORITIES_MAP[$priorityValue])) {
$priorityCode = self::PRIORITIES_MAP[$priorityValue];
} else {
throw new Exception("Priority value {$priorityValue} is not valid.");
}
return $priorityCode;
}
/**
* Helper to get the priority label from a given value
*
* @param int $priorityValue
*
* @return string
*/
public static function getPriorityLabel($priorityValue)
{
$priorityCode = self::getPriorityCode($priorityValue);
return G::LoadTranslation("ID_PRIORITY_{$priorityCode}");
}
}