2020-11-05 17:50:41 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace ProcessMaker\BusinessModel\Cases;
|
|
|
|
|
|
2020-11-11 10:38:08 -04:00
|
|
|
use G;
|
2020-11-05 17:50:41 -04:00
|
|
|
use ProcessMaker\Model\Delegation;
|
|
|
|
|
|
|
|
|
|
class Search extends AbstractCases
|
|
|
|
|
{
|
2020-11-11 10:38:08 -04:00
|
|
|
// Columns to see in the cases list
|
|
|
|
|
public $columnsView = [
|
|
|
|
|
// Columns view in the cases list
|
|
|
|
|
'APP_DELEGATION.APP_NUMBER', // Case #
|
|
|
|
|
'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
|
|
|
|
|
'USERS.USR_USERNAME', // Current UserName
|
|
|
|
|
'USERS.USR_FIRSTNAME', // Current User FirstName
|
|
|
|
|
'USERS.USR_LASTNAME', // Current User LastName
|
|
|
|
|
'APP_DELEGATION.DEL_TASK_DUE_DATE', // Due Date
|
|
|
|
|
'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
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the columns related to the cases list
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getColumnsView()
|
|
|
|
|
{
|
|
|
|
|
return $this->columnsView;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 17:50:41 -04:00
|
|
|
/**
|
|
|
|
|
* Get the data corresponding to advanced search
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getData()
|
|
|
|
|
{
|
2020-11-11 10:38:08 -04:00
|
|
|
$query = Delegation::query()->select($this->getColumnsView());
|
|
|
|
|
// Join with process
|
|
|
|
|
$query->joinProcess();
|
|
|
|
|
// Join with task
|
|
|
|
|
$query->joinTask();
|
|
|
|
|
// Join with users
|
|
|
|
|
$query->joinUser();
|
2020-11-05 17:50:41 -04:00
|
|
|
// Filter by case number
|
2020-11-11 10:38:08 -04:00
|
|
|
if ($this->getCaseNumber() > 0) {
|
|
|
|
|
$query->case($this->getCaseNumber());
|
|
|
|
|
}
|
2020-11-05 17:50:41 -04:00
|
|
|
// 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());
|
|
|
|
|
}
|
|
|
|
|
// 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();
|
2020-11-11 10:38:08 -04:00
|
|
|
// Prepare the result
|
|
|
|
|
$results->transform(function ($item, $key) {
|
|
|
|
|
// Get priority label
|
|
|
|
|
$priorityLabel = self::PRIORITIES[$item['DEL_PRIORITY']];
|
|
|
|
|
$item['DEL_PRIORITY_LABEL'] = G::LoadTranslation("ID_PRIORITY_{$priorityLabel}");
|
|
|
|
|
// Get task color label
|
|
|
|
|
$item['TAS_COLOR'] = $this->getTaskColor($item['DEL_TASK_DUE_DATE']);
|
|
|
|
|
$item['TAS_COLOR_LABEL'] = self::TASK_COLORS[$item['TAS_COLOR']];
|
|
|
|
|
// Apply the date format defined in environment
|
|
|
|
|
$item['DEL_TASK_DUE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_TASK_DUE_DATE']);
|
|
|
|
|
$item['DEL_DELEGATE_DATE_LABEL'] = applyMaskDateEnvironment($item['DEL_DELEGATE_DATE']);
|
|
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
|
});
|
2020-11-05 17:50:41 -04:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|