Merged in bugfix/PMCORE-3177 (pull request #8033)
PMCORE-3177 Create an API for get the columns related to the custom case list Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
commit
1d740f9e9c
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace tests\unit\workflow\engine\src\ProcessMaker\Model;
|
namespace tests\unit\workflow\engine\src\ProcessMaker\Model;
|
||||||
|
|
||||||
|
use ProcessMaker\Model\AdditionalTables;
|
||||||
use ProcessMaker\Model\CaseList;
|
use ProcessMaker\Model\CaseList;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -348,4 +349,108 @@ class CaseListTest extends TestCase
|
|||||||
//assert file export
|
//assert file export
|
||||||
$this->assertFileExists($result['filename']);
|
$this->assertFileExists($result['filename']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test the formattingColumns method.
|
||||||
|
* @test
|
||||||
|
* @covers \ProcessMaker\Model\CaseList::formattingColumns()
|
||||||
|
*/
|
||||||
|
public function it_should_test_formattingColumns()
|
||||||
|
{
|
||||||
|
$additionalTables = factory(\ProcessMaker\Model\AdditionalTables::class)->create();
|
||||||
|
|
||||||
|
$fields = factory(\ProcessMaker\Model\Fields::class, 5)->create([
|
||||||
|
'ADD_TAB_UID' => $additionalTables->ADD_TAB_UID
|
||||||
|
]);
|
||||||
|
|
||||||
|
factory(CaseList::class)->create([
|
||||||
|
'CAL_TYPE' => 'inbox',
|
||||||
|
'ADD_TAB_UID' => $additionalTables->ADD_TAB_UID
|
||||||
|
]);
|
||||||
|
factory(CaseList::class)->create([
|
||||||
|
'CAL_TYPE' => 'draft',
|
||||||
|
'ADD_TAB_UID' => $additionalTables->ADD_TAB_UID
|
||||||
|
]);
|
||||||
|
factory(CaseList::class)->create([
|
||||||
|
'CAL_TYPE' => 'paused',
|
||||||
|
'ADD_TAB_UID' => $additionalTables->ADD_TAB_UID
|
||||||
|
]);
|
||||||
|
factory(CaseList::class)->create([
|
||||||
|
'CAL_TYPE' => 'unassigned',
|
||||||
|
'ADD_TAB_UID' => $additionalTables->ADD_TAB_UID
|
||||||
|
]);
|
||||||
|
|
||||||
|
$columns = [
|
||||||
|
[
|
||||||
|
"field" => "case_number",
|
||||||
|
"enableFilter" => false,
|
||||||
|
"set" => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"field" => "case_title",
|
||||||
|
"enableFilter" => false,
|
||||||
|
"set" => true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = CaseList::formattingColumns('inbox', $additionalTables->ADD_TAB_UID, $columns);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$this->assertArrayHasKey('field', $result[0]);
|
||||||
|
$this->assertArrayHasKey('name', $result[0]);
|
||||||
|
$this->assertArrayHasKey('type', $result[0]);
|
||||||
|
$this->assertArrayHasKey('source', $result[0]);
|
||||||
|
$this->assertArrayHasKey('typeSearch', $result[0]);
|
||||||
|
$this->assertArrayHasKey('enableFilter', $result[0]);
|
||||||
|
$this->assertArrayHasKey('set', $result[0]);
|
||||||
|
|
||||||
|
$result = CaseList::formattingColumns('draft', $additionalTables->ADD_TAB_UID, $columns);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$this->assertArrayHasKey('field', $result[1]);
|
||||||
|
$this->assertArrayHasKey('name', $result[1]);
|
||||||
|
$this->assertArrayHasKey('type', $result[1]);
|
||||||
|
$this->assertArrayHasKey('source', $result[1]);
|
||||||
|
$this->assertArrayHasKey('typeSearch', $result[1]);
|
||||||
|
$this->assertArrayHasKey('enableFilter', $result[1]);
|
||||||
|
$this->assertArrayHasKey('set', $result[1]);
|
||||||
|
|
||||||
|
$result = CaseList::formattingColumns('paused', $additionalTables->ADD_TAB_UID, $columns);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$this->assertArrayHasKey('field', $result[2]);
|
||||||
|
$this->assertArrayHasKey('name', $result[2]);
|
||||||
|
$this->assertArrayHasKey('type', $result[2]);
|
||||||
|
$this->assertArrayHasKey('source', $result[2]);
|
||||||
|
$this->assertArrayHasKey('typeSearch', $result[2]);
|
||||||
|
$this->assertArrayHasKey('enableFilter', $result[2]);
|
||||||
|
$this->assertArrayHasKey('set', $result[2]);
|
||||||
|
|
||||||
|
$result = CaseList::formattingColumns('unassigned', $additionalTables->ADD_TAB_UID, $columns);
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$this->assertArrayHasKey('field', $result[3]);
|
||||||
|
$this->assertArrayHasKey('name', $result[3]);
|
||||||
|
$this->assertArrayHasKey('type', $result[3]);
|
||||||
|
$this->assertArrayHasKey('source', $result[3]);
|
||||||
|
$this->assertArrayHasKey('typeSearch', $result[3]);
|
||||||
|
$this->assertArrayHasKey('enableFilter', $result[3]);
|
||||||
|
$this->assertArrayHasKey('set', $result[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test the getReportTables method.
|
||||||
|
* @test
|
||||||
|
* @covers \ProcessMaker\Model\CaseList::getReportTables()
|
||||||
|
*/
|
||||||
|
public function it_should_test_getReportTables()
|
||||||
|
{
|
||||||
|
AdditionalTables::truncate();
|
||||||
|
$additionalTables = factory(AdditionalTables::class, 10)->create();
|
||||||
|
|
||||||
|
$search = '';
|
||||||
|
$result = CaseList::getReportTables($search);
|
||||||
|
|
||||||
|
$this->assertNotEmpty($result);
|
||||||
|
$this->assertCount(10, $result);
|
||||||
|
$this->assertArrayHasKey('name', $result[0]);
|
||||||
|
$this->assertArrayHasKey('description', $result[0]);
|
||||||
|
$this->assertArrayHasKey('fields', $result[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace ProcessMaker\Model;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use G;
|
use G;
|
||||||
|
use ProcessMaker\BusinessModel\Table;
|
||||||
use ProcessMaker\Core\System;
|
use ProcessMaker\Core\System;
|
||||||
use ProcessMaker\Model\AdditionalTables;
|
use ProcessMaker\Model\AdditionalTables;
|
||||||
use ProcessMaker\Model\User;
|
use ProcessMaker\Model\User;
|
||||||
@@ -62,10 +63,17 @@ class CaseList extends Model
|
|||||||
'USR_FIRSTNAME' => 'userFirstname',
|
'USR_FIRSTNAME' => 'userFirstname',
|
||||||
'USR_LASTNAME' => 'userLastname',
|
'USR_LASTNAME' => 'userLastname',
|
||||||
'USR_EMAIL' => 'userEmail',
|
'USR_EMAIL' => 'userEmail',
|
||||||
|
'USR_POSITION' => 'userPosition',
|
||||||
'ADD_TAB_NAME' => 'tableName',
|
'ADD_TAB_NAME' => 'tableName',
|
||||||
'PRO_TITLE' => 'process'
|
'PRO_TITLE' => 'process'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the columns exclude from report table.
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $excludeColumns = ['APP_UID', 'APP_NUMBER', 'APP_STATUS'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get column name from alias.
|
* Get column name from alias.
|
||||||
* @param array $array
|
* @param array $array
|
||||||
@@ -187,7 +195,7 @@ class CaseList extends Model
|
|||||||
'CASE_LIST.*',
|
'CASE_LIST.*',
|
||||||
'PROCESS.PRO_TITLE',
|
'PROCESS.PRO_TITLE',
|
||||||
'ADDITIONAL_TABLES.ADD_TAB_NAME',
|
'ADDITIONAL_TABLES.ADD_TAB_NAME',
|
||||||
'USERS.USR_UID', 'USERS.USR_USERNAME', 'USERS.USR_FIRSTNAME', 'USERS.USR_LASTNAME', 'USERS.USR_EMAIL'
|
'USERS.USR_UID', 'USERS.USR_USERNAME', 'USERS.USR_FIRSTNAME', 'USERS.USR_LASTNAME', 'USERS.USR_EMAIL', 'USERS.USR_POSITION'
|
||||||
])
|
])
|
||||||
->where(function ($query) use ($search) {
|
->where(function ($query) use ($search) {
|
||||||
$query
|
$query
|
||||||
@@ -211,7 +219,10 @@ class CaseList extends Model
|
|||||||
|
|
||||||
$result = CaseList::getAliasFromColumnName($item->toArray());
|
$result = CaseList::getAliasFromColumnName($item->toArray());
|
||||||
|
|
||||||
$result['columns'] = json_decode($result['columns']);
|
$columns = json_decode($result['columns']);
|
||||||
|
$columns = CaseList::formattingColumns($result['type'], $result['tableUid'], $columns);
|
||||||
|
|
||||||
|
$result['columns'] = $columns;
|
||||||
$result['userAvatar'] = System::getServerMainPath() . '/users/users_ViewPhotoGrid?pUID=' . $result['USR_UID'] . '&h=' . microtime(true);
|
$result['userAvatar'] = System::getServerMainPath() . '/users/users_ViewPhotoGrid?pUID=' . $result['USR_UID'] . '&h=' . microtime(true);
|
||||||
unset($result['USR_UID']);
|
unset($result['USR_UID']);
|
||||||
|
|
||||||
@@ -285,4 +296,190 @@ class CaseList extends Model
|
|||||||
throw new Exception($e->getMessage());
|
throw new Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formatting columns from minimal stored columns configuration in custom cases list.
|
||||||
|
* @param string $type
|
||||||
|
* @param string $tableUid
|
||||||
|
* @param array $storedColumns
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function formattingColumns(string $type = 'inbox', string $tableUid = '', array $storedColumns = [])
|
||||||
|
{
|
||||||
|
$default = [
|
||||||
|
[
|
||||||
|
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
|
||||||
|
'field' => 'case_number',
|
||||||
|
'name' => G::LoadTranslation('ID_MYCASE_NUMBER'),
|
||||||
|
'type' => 'integer',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'integer range',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
|
||||||
|
'field' => 'case_title',
|
||||||
|
'name' => G::LoadTranslation('ID_CASE_TITLE'),
|
||||||
|
'type' => 'string',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'search text',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
|
||||||
|
'field' => 'process_name',
|
||||||
|
'name' => G::LoadTranslation('ID_PROCESS_NAME'),
|
||||||
|
'type' => 'string',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'search text',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
|
||||||
|
'field' => 'task',
|
||||||
|
'name' => G::LoadTranslation('ID_TASK'),
|
||||||
|
'type' => 'string',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'search text',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
|
||||||
|
'field' => 'send_by',
|
||||||
|
'name' => G::LoadTranslation('ID_SEND_BY'),
|
||||||
|
'type' => 'string',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'search text',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'paused', 'unassigned'],
|
||||||
|
'field' => 'due_date',
|
||||||
|
'name' => G::LoadTranslation('ID_DUE_DATE'),
|
||||||
|
'type' => 'date',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'date range',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'paused', 'unassigned'],
|
||||||
|
'field' => 'delegation_date',
|
||||||
|
'name' => G::LoadTranslation('ID_DELEGATION_DATE'),
|
||||||
|
'type' => 'date',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'date range',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
], [
|
||||||
|
'list' => ['inbox', 'draft', 'paused', 'unassigned'],
|
||||||
|
'field' => 'priority',
|
||||||
|
'name' => G::LoadTranslation('ID_PRIORITY'),
|
||||||
|
'type' => 'string',
|
||||||
|
'source' => 'APPLICATION',
|
||||||
|
'typeSearch' => 'option',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => true
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
//filter by type
|
||||||
|
$result = [];
|
||||||
|
foreach ($default as &$column) {
|
||||||
|
if (in_array($type, $column['list'])) {
|
||||||
|
unset($column['list']);
|
||||||
|
$result[] = $column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$default = $result;
|
||||||
|
|
||||||
|
//get additional tables
|
||||||
|
$additionalTables = AdditionalTables::where('ADD_TAB_UID', '=', $tableUid)
|
||||||
|
->where('PRO_UID', '<>', '')
|
||||||
|
->whereNotNull('PRO_UID')
|
||||||
|
->get();
|
||||||
|
$additionalTables->transform(function ($object) {
|
||||||
|
$table = new Table();
|
||||||
|
return $table->getTable($object->ADD_TAB_UID, $object->PRO_UID, true, false);
|
||||||
|
});
|
||||||
|
$result = $additionalTables->toArray();
|
||||||
|
if (!empty($result)) {
|
||||||
|
$result = $result[0];
|
||||||
|
if (isset($result['fields'])) {
|
||||||
|
foreach ($result['fields'] as $column) {
|
||||||
|
if (in_array($column['fld_name'], self::$excludeColumns)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$default[] = [
|
||||||
|
'field' => $column['fld_name'],
|
||||||
|
'name' => $column['fld_name'],
|
||||||
|
'type' => $column['fld_type'],
|
||||||
|
'source' => $result['rep_tab_name'],
|
||||||
|
'typeSearch' => 'search text',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//merge with stored information
|
||||||
|
$result = [];
|
||||||
|
foreach ($default as &$column) {
|
||||||
|
foreach ($storedColumns as $storedColumn) {
|
||||||
|
if (!is_array($storedColumn) || !isset($storedColumn['field'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($storedColumn['field'] === $column['field']) {
|
||||||
|
$column['enableFilter'] = $storedColumn['enableFilter'];
|
||||||
|
$column['set'] = $storedColumn['set'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result[] = $column;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the report tables, this can filter the results by the search parameter.
|
||||||
|
* @param string $search
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getReportTables(string $search = '')
|
||||||
|
{
|
||||||
|
$additionalTables = AdditionalTables::where('ADD_TAB_NAME', 'LIKE', "%{$search}%")
|
||||||
|
->where('PRO_UID', '<>', '')
|
||||||
|
->whereNotNull('PRO_UID')
|
||||||
|
->get();
|
||||||
|
$additionalTables->transform(function ($object) {
|
||||||
|
$table = new Table();
|
||||||
|
$result = $table->getTable($object->ADD_TAB_UID, $object->PRO_UID, true, false);
|
||||||
|
$fields = [];
|
||||||
|
if (isset($result['fields'])) {
|
||||||
|
foreach ($result['fields'] as $column) {
|
||||||
|
if (in_array($column['fld_name'], self::$excludeColumns)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$fields[] = [
|
||||||
|
'field' => $column['fld_name'],
|
||||||
|
'name' => $column['fld_name'],
|
||||||
|
'type' => $column['fld_type'],
|
||||||
|
'source' => $result['rep_tab_name'],
|
||||||
|
'typeSearch' => 'search text',
|
||||||
|
'enableFilter' => false,
|
||||||
|
'set' => false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
'name' => $result['rep_tab_name'],
|
||||||
|
'description' => $result['rep_tab_description'],
|
||||||
|
'fields' => $fields
|
||||||
|
];
|
||||||
|
});
|
||||||
|
$result = $additionalTables->toArray();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,4 +183,40 @@ class CaseList extends Api
|
|||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default columns associate to custom cases list.
|
||||||
|
* @url GET /:type/default-columns
|
||||||
|
* @param string $type
|
||||||
|
* @access protected
|
||||||
|
* @class AccessControl {@permission PM_CASES}
|
||||||
|
* @throws RestException
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function doGetDefaultColumns(string $type)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return CaseListBusinessModel::formattingColumns($type, '', []);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get report tables.
|
||||||
|
* @url GET /report-tables
|
||||||
|
* @param string $search
|
||||||
|
* @access protected
|
||||||
|
* @class AccessControl {@permission PM_CASES}
|
||||||
|
* @throws RestException
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function doGetReportTables(string $search = '')
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return CaseListBusinessModel::getReportTables($search);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user