Merged in bugfix/PMCORE-3053 (pull request #8015)

PMCORE-3053 Rest Services: Improve API related to home order to get the Custom cases list

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Roly Rudy Gutierrez Pinto
2021-08-04 15:37:57 +00:00
committed by Julio Cesar Laura Avendaño
11 changed files with 468 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\CaseList;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
@@ -166,4 +167,44 @@ class Draft extends AbstractCases
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
}
/**
* Returns the total cases of the custom draft list.
* @param int $id
* @param string $type
* @return array
*/
public function getCustomListCount(int $id, string $type): array
{
$caseList = CaseList::where('CAL_ID', '=', $id)
->where('CAL_TYPE', '=', $type)
->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->select([
'CASE_LIST.*',
'ADDITIONAL_TABLES.ADD_TAB_NAME'
])
->get()
->first();
$query = Delegation::query()->select();
$query->draft($this->getUserId());
$name = '';
$description = '';
$tableName = '';
if (!is_null($caseList)) {
$name = $caseList->CAL_NAME;
$description = $caseList->CAL_DESCRIPTION;
$tableName = $caseList->ADD_TAB_NAME;
$query->leftJoin($caseList->ADD_TAB_NAME, $caseList->ADD_TAB_NAME . '.APP_UID', '=', 'APP_DELEGATION.APP_UID');
}
$count = $query->count(['APP_DELEGATION.APP_NUMBER']);
return [
'label' => G::LoadTranslation('ID_NUMBER_OF_CASES_DRAFT') . $count,
'name' => $name,
'description' => $description,
'tableName' => $tableName,
'total' => $count
];
}
}

View File

@@ -4,6 +4,7 @@ namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\CaseList;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
@@ -179,4 +180,44 @@ class Inbox extends AbstractCases
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
}
/**
* Returns the total cases of the custom inbox list.
* @param int $id
* @param string $type
* @return array
*/
public function getCustomListCount(int $id, string $type): array
{
$caseList = CaseList::where('CAL_ID', '=', $id)
->where('CAL_TYPE', '=', $type)
->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->select([
'CASE_LIST.*',
'ADDITIONAL_TABLES.ADD_TAB_NAME'
])
->get()
->first();
$query = Delegation::query()->select();
$query->inbox($this->getUserId());
$name = '';
$description = '';
$tableName = '';
if (!is_null($caseList)) {
$name = $caseList->CAL_NAME;
$description = $caseList->CAL_DESCRIPTION;
$tableName = $caseList->ADD_TAB_NAME;
$query->leftJoin($caseList->ADD_TAB_NAME, $caseList->ADD_TAB_NAME . '.APP_UID', '=', 'APP_DELEGATION.APP_UID');
}
$count = $query->count(['APP_DELEGATION.APP_NUMBER']);
return [
'label' => G::LoadTranslation('ID_NUMBER_OF_CASES_INBOX') . $count,
'name' => $name,
'description' => $description,
'tableName' => $tableName,
'total' => $count
];
}
}

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\CaseList;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
@@ -173,4 +174,44 @@ class Paused extends AbstractCases
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
}
/**
* Returns the total cases of the custom paused list.
* @param int $id
* @param string $type
* @return array
*/
public function getCustomListCount(int $id, string $type): array
{
$caseList = CaseList::where('CAL_ID', '=', $id)
->where('CAL_TYPE', '=', $type)
->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->select([
'CASE_LIST.*',
'ADDITIONAL_TABLES.ADD_TAB_NAME'
])
->get()
->first();
$query = Delegation::query()->select();
$query->paused($this->getUserId());
$name = '';
$description = '';
$tableName = '';
if (!is_null($caseList)) {
$name = $caseList->CAL_NAME;
$description = $caseList->CAL_DESCRIPTION;
$tableName = $caseList->ADD_TAB_NAME;
$query->leftJoin($caseList->ADD_TAB_NAME, $caseList->ADD_TAB_NAME . '.APP_UID', '=', 'APP_DELEGATION.APP_UID');
}
$count = $query->count(['APP_DELEGATION.APP_NUMBER']);
return [
'label' => G::LoadTranslation('ID_NUMBER_OF_CASES_PAUSED') . $count,
'name' => $name,
'description' => $description,
'tableName' => $tableName,
'total' => $count
];
}
}

View File

@@ -4,6 +4,7 @@ namespace ProcessMaker\BusinessModel\Cases;
use G;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\CaseList;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\User;
@@ -181,4 +182,44 @@ class Unassigned extends AbstractCases
// Return the number of rows
return $query->count(['APP_DELEGATION.APP_NUMBER']);
}
/**
* Returns the total cases of the custom unassigned list.
* @param int $id
* @param string $type
* @return array
*/
public function getCustomListCount(int $id, string $type): array
{
$caseList = CaseList::where('CAL_ID', '=', $id)
->where('CAL_TYPE', '=', $type)
->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->select([
'CASE_LIST.*',
'ADDITIONAL_TABLES.ADD_TAB_NAME'
])
->get()
->first();
$query = Delegation::query()->select();
$query->selfService($this->getUserId());
$name = '';
$description = '';
$tableName = '';
if (!is_null($caseList)) {
$name = $caseList->CAL_NAME;
$description = $caseList->CAL_DESCRIPTION;
$tableName = $caseList->ADD_TAB_NAME;
$query->leftJoin($caseList->ADD_TAB_NAME, $caseList->ADD_TAB_NAME . '.APP_UID', '=', 'APP_DELEGATION.APP_UID');
}
$count = $query->count(['APP_DELEGATION.APP_NUMBER']);
return [
'label' => G::LoadTranslation('ID_NUMBER_OF_CASES_UNASSIGNED') . $count,
'name' => $name,
'description' => $description,
'tableName' => $tableName,
'total' => $count
];
}
}

View File

@@ -173,9 +173,10 @@ class CaseList extends Model
* @param string $search
* @param int $offset
* @param int $limit
* @param bool $paged
* @return array
*/
public static function getSetting(string $type, string $search, int $offset, int $limit): array
public static function getSetting(string $type, string $search, int $offset, int $limit, bool $paged = true): array
{
$order = 'asc';
$model = CaseList::where('CAL_TYPE', '=', $type)
@@ -198,7 +199,11 @@ class CaseList extends Model
$count = $model->count();
$data = $model->offset($offset)->limit($limit)->get();
if ($paged === true) {
$model->offset($offset)->limit($limit);
}
$data = $model->get();
$data->transform(function ($item, $key) {
if (is_null($item->CAL_COLUMNS)) {
$item->CAL_COLUMNS = '[]';

View File

@@ -14,6 +14,7 @@ use ProcessMaker\BusinessModel\Cases\Paused;
use ProcessMaker\BusinessModel\Cases\Search;
use ProcessMaker\BusinessModel\Cases\Supervising;
use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\Model\CaseList;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\ProcessCategory;
@@ -609,6 +610,30 @@ class Home extends Api
if ($menuInstance->Id[$i] === 'ID_CASE_ARCHIVE_SEARCH') {
$option->icon = "fas fa-archive";
}
//custom cases list
if (in_array($menuInstance->Id[$i], $optionsWithCounter)) {
$mapKeys = [
'CASES_INBOX' => 'inbox',
'CASES_DRAFT' => 'draft',
'CASES_SELFSERVICE' => 'unassigned',
'CASES_PAUSED' => 'paused'
];
$option->customCasesList = [];
$result = CaseList::getSetting($mapKeys[$menuInstance->Id[$i]], '', 0, 10, false);
foreach ($result['data'] as $value) {
$option->customCasesList[] = [
"href" => "casesListExtJs?action=" . $mapKeys[$menuInstance->Id[$i]],
"id" => $value['id'],
"title" => $value['name'],
"description" => $value['description'],
"icon" => $value['iconList'],
"badge" => [
"text" => "0",
"class" => "badge-custom"
]
];
}
}
// Add option to the menu
$menuHome[] = $option;
}
@@ -727,10 +752,48 @@ class Home extends Api
$result = [];
$result['label'] = $text . $count;
$result['total'] = $count;
return $result;
}
/**
* Get task counters for inbox, draft, paused, and unassigned for custom case lists.
* @url GET /:task/counter/caseList/:id
* @param string $task
* @param int $id
* @return array
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function getCustomCaseListCounter(string $task, int $id)
{
try {
$usrUid = $this->getUserId();
$usrId = !empty($usrUid) ? User::getId($usrUid) : 0;
switch ($task) {
case 'inbox':
$taskList = new Inbox();
break;
case 'draft':
$taskList = new Draft();
break;
case 'paused':
$taskList = new Paused();
break;
case 'unassigned':
$taskList = new Unassigned();
break;
default:
return [];
}
$taskList->setUserUid($usrUid);
$taskList->setUserId($usrId);
$result = $taskList->getCustomListCount($id, $task);
return $result;
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the tasks counters for todo, draft, paused and unassigned
*