Merge branch 'feature/PMCORE-3049' of https://bitbucket.org/colosa/processmaker into taskmetrics

This commit is contained in:
Henry Jordan
2021-08-26 20:34:26 +00:00
16 changed files with 1354 additions and 183 deletions

View File

@@ -4178,12 +4178,13 @@ class Cases
}
/**
* unpause a case
* Unpause a case
*
* @name unpauseCase
* @param string $appUid
* @param int $index
* @param string $usrUid
*
* @return object
*/
public function unpauseCase($appUid, $index, $usrUid)

View File

@@ -83,8 +83,10 @@ class DbConnections
$result->next();
}
if (! in_array($row[2], $types)) {
$types[] = $row[2];
if (isset($row[2])) {
if (!in_array($row[2], $types)) {
$types[] = $row[2];
}
}
$this->connections = $connections;
return $connections;

View File

@@ -30,8 +30,8 @@ class PmLicenseManager
$licenseFile = $activeLicenseSetting[config("system.workspace")];
} else {
$activeLicense = $this->getActiveLicense();
$oServerConf->setProperty('ACTIVE_LICENSE', [config("system.workspace") => $activeLicense['LICENSE_PATH']]);
$licenseFile = $activeLicense['LICENSE_PATH'];
$oServerConf->setProperty('ACTIVE_LICENSE', [config("system.workspace") => isset($activeLicense['LICENSE_PATH']) ? $activeLicense['LICENSE_PATH'] : null]);
$licenseFile = isset($activeLicense['LICENSE_PATH']) ? $activeLicense['LICENSE_PATH'] : null;
}
$application = new license_application($licenseFile, false, true, false, true);

View File

@@ -5056,11 +5056,10 @@ class WorkspaceTools
$processUid = '',
$gridKey = '',
$addTabUid = '',
$className = '',
$pathWorkspace,
int $start = 0,
int $limit = 10
) {
// Initialize DB connections
$this->initPropel();
$dbHost = explode(':', $this->dbHost);
config(['database.connections.workflow.host' => $dbHost[0]]);
@@ -5071,19 +5070,15 @@ class WorkspaceTools
config(['database.connections.workflow.port' => $dbHost[1]]);
}
//require file
set_include_path(get_include_path() . PATH_SEPARATOR . $pathWorkspace);
if (!file_exists($pathWorkspace . 'classes/' . $className . '.php')) {
throw new Exception("ERROR: " . $pathWorkspace . 'classes/' . $className . '.php' . " class file doesn't exit!");
}
require_once 'classes/model/AdditionalTables.php';
require_once $pathWorkspace . 'classes/' . $className . '.php';
//get fields
// Get fields and some specific field types
$fields = [];
$fieldsWithTypes = [];
$fieldTypes = [];
if ($addTabUid != '') {
$fields = Fields::where('ADD_TAB_UID', '=', $addTabUid)->get();
foreach ($fields as $field) {
$fieldsAux = Fields::where('ADD_TAB_UID', '=', $addTabUid)->get();
foreach ($fieldsAux as $field) {
$fields[] = $field->FLD_NAME;
$fieldsWithTypes[$field->FLD_NAME] = strtoupper($field->FLD_TYPE);
switch ($field->FLD_TYPE) {
case 'FLOAT':
case 'DOUBLE':
@@ -5096,10 +5091,11 @@ class WorkspaceTools
}
}
// Initialize variables
$context = Bootstrap::context();
$case = new Cases();
//select cases for this Process, ordered by APP_NUMBER
// Select cases of the related process, ordered by APP_NUMBER
$applications = Application::query()
->where('PRO_UID', '=', $processUid)
->where('APP_NUMBER', '>', 0)
@@ -5107,11 +5103,13 @@ class WorkspaceTools
->offset($start)
->limit($limit)
->get();
// Process applications selected
foreach ($applications as $application) {
//getting the case data
// Get case data
$appData = $case->unserializeData($application->APP_DATA);
//quick fix, map all empty values as NULL for Database
// Quick fix, map all empty values as NULL for Database
foreach ($appData as $appDataKey => $appDataValue) {
if (is_array($appDataValue) && count($appDataValue)) {
$j = key($appDataValue);
@@ -5126,10 +5124,10 @@ class WorkspaceTools
}
}
}
// normal fields
// Normal fields
$appData[$appDataKey] = $appDataValue === '' ? null : $appDataValue;
} else {
// grids
// Grids
if (is_array($appData[$appDataKey])) {
foreach ($appData[$appDataKey] as $dIndex => $dRow) {
if (is_array($dRow)) {
@@ -5144,22 +5142,30 @@ class WorkspaceTools
}
}
//populate data
// Populate data
if ($type === 'GRID') {
list($gridName, $gridUid) = explode('-', $gridKey);
$gridData = isset($appData[$gridName]) ? $appData[$gridName] : [];
foreach ($gridData as $i => $gridRow) {
try {
$obj = new $className();
$obj->fromArray($appData, BasePeer::TYPE_FIELDNAME);
$obj->setAppUid($application->APP_UID);
$obj->setAppNumber($application->APP_NUMBER);
if (method_exists($obj, 'setAppStatus')) {
$obj->setAppStatus($application->APP_STATUS);
}
$obj->fromArray(array_change_key_case($gridRow, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
$obj->setRow($i);
$obj->save();
// Change keys to uppercase
$gridRow = array_change_key_case($gridRow, CASE_UPPER);
// Completing some required values in row data
$gridRow['APP_UID'] = $application->APP_UID;
$gridRow['APP_NUMBER'] = $application->APP_NUMBER;
$gridRow['APP_STATUS'] = $application->APP_STATUS;
$gridRow['ROW'] = $i;
// Build sections of the query
$fieldsSection = $this->buildFieldsSection($fields);
$valuesSection = $this->buildValuesSection($fieldsWithTypes, $gridRow);
// Build insert query
$query = "INSERT INTO `$tableName` ($fieldsSection) VALUES ($valuesSection);";
// Execute the query
DB::connection()->statement(DB::raw($query));
} catch (Exception $e) {
$context["message"] = $e->getMessage();
$context["tableName"] = $tableName;
@@ -5171,14 +5177,23 @@ class WorkspaceTools
}
} else {
try {
$obj = new $className();
$obj->fromArray(array_change_key_case($appData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
$obj->setAppUid($application->APP_UID);
$obj->setAppNumber($application->APP_NUMBER);
if (method_exists($obj, 'setAppStatus')) {
$obj->setAppStatus($application->APP_STATUS);
}
$obj->save();
// Change keys to uppercase
$appData = array_change_key_case($appData, CASE_UPPER);
// Completing some required values in case data
$appData['APP_UID'] = $application->APP_UID;
$appData['APP_NUMBER'] = $application->APP_NUMBER;
$appData['APP_STATUS'] = $application->APP_STATUS;
// Build sections of the query
$fieldsSection = $this->buildFieldsSection($fields);
$valuesSection = $this->buildValuesSection($fieldsWithTypes, $appData);
// Build insert query
$query = "INSERT INTO `$tableName` ($fieldsSection) VALUES ($valuesSection);";
// Execute the query
DB::connection()->statement(DB::raw($query));
} catch (Exception $e) {
$context["message"] = $e->getMessage();
$context["tableName"] = $tableName;
@@ -5186,7 +5201,6 @@ class WorkspaceTools
$message = 'Sql Execution';
Log::channel(':sqlExecution')->critical($message, Bootstrap::context($context));
}
unset($obj);
}
}
}
@@ -5280,4 +5294,72 @@ class WorkspaceTools
CLI::logging($e->getMessage() . PHP_EOL . PHP_EOL);
}
}
/**
* Build the fields section for the insert query
*
* @param array $fields
* @return string
*/
private function buildFieldsSection($fields)
{
// Transform records to single array
$fields = array_map(function($field) {
return "`{$field}`";
}, $fields);
return implode(', ', $fields);
}
/**
* Build values section for the insert query
*
* @param array $fieldsWithTypes
* @param array $caseData
* @return string
*/
private function buildValuesSection($fieldsWithTypes, $caseData)
{
// Initialize variables
$values = [];
// Sanitize each value in case data according to the field type
foreach ($fieldsWithTypes as $fieldName => $fieldType) {
// Get the value
$fieldName = strtoupper($fieldName);
$value = isset($caseData[$fieldName]) ? $caseData[$fieldName] : null;
// Sanitize data
switch ($fieldType) {
case 'BIGINT':
case 'INTEGER':
case 'SMALLINT':
case 'TINYINT':
case 'BOOLEAN':
$values[] = (int)$value;
break;
case 'DECIMAL':
case 'DOUBLE':
case 'FLOAT':
case 'REAL':
$values[] = (float)$value;
break;
case 'DATE':
case 'DATETIME':
case 'TIME':
if (strtotime($value) === false) {
$value = '0000-00-00 00:00:00';
}
$values[] = "'{$value}'";
break;
default: // char, mediumtext, varchar or another type
// Escape the strings
$values[] = DB::connection()->getPdo()->quote($value);
break;
}
}
// Convert to string separated by commas
return implode(', ', $values);
}
}

View File

@@ -3372,7 +3372,6 @@ class WsBase
if (empty($caseUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " caseUid");
$g->sessionVarRestore();
return $result;
@@ -3380,7 +3379,6 @@ class WsBase
if (empty($delIndex)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " delIndex");
$g->sessionVarRestore();
return $result;
@@ -3388,7 +3386,6 @@ class WsBase
if (empty($userUid)) {
$result = new WsResponse(100, G::LoadTranslation("ID_REQUIRED_FIELD") . " userUid");
$g->sessionVarRestore();
return $result;

View File

@@ -758,32 +758,39 @@ class AdditionalTables extends BaseAdditionalTables
/**
* Populate the report table with all case data
* @param string $sType
* @param string $sProcessUid
* @param string $sGrid
* @return number
*
* @param string $tableName
* @param string $connection
* @param string $type
* @param string $processUid
* @param string $gridKey
* @param string $addTabUid
*/
public function populateReportTable($tableName, $sConnection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '', $addTabUid = '')
public function populateReportTable($tableName, $connection = 'rp', $type = 'NORMAL', $processUid = '', $gridKey = '', $addTabUid = '')
{
// Initializing variables
$this->className = $className = $this->getPHPName($tableName);
$this->classPeerName = $classPeerName = $className . 'Peer';
DB::statement("TRUNCATE " . $tableName);
$workspace = config("system.workspace");
$pathWorkspace = PATH_WORKSPACE;
$n = Application::count();
//batch process
// Truncate report table
DB::statement("TRUNCATE " . $tableName);
// Batch process
$config = System::getSystemConfiguration();
$reportTableBatchRegeneration = $config['report_table_batch_regeneration'];
// Initializing more variables
$size = $n;
$start = 0;
$limit = $reportTableBatchRegeneration;
// Creating jobs
for ($i = 1; $start < $size; $i++) {
$closure = function() use($workspace, $tableName, $type, $processUid, $gridKey, $addTabUid, $className, $pathWorkspace, $start, $limit) {
$closure = function() use($workspace, $tableName, $type, $processUid, $gridKey, $addTabUid, $start, $limit) {
$workspaceTools = new WorkspaceTools($workspace);
$workspaceTools->generateDataReport($tableName, $type, $processUid, $gridKey, $addTabUid, $className, $pathWorkspace, $start, $limit);
$workspaceTools->generateDataReport($tableName, $type, $processUid, $gridKey, $addTabUid, $start, $limit);
};
JobsManager::getSingleton()->dispatch(GenerateReportTable::class, $closure);
$start = $i * $limit;

View File

@@ -1073,19 +1073,19 @@ class Cases
* @access public
* @param string $app_uid , Uid for case
* @param string $usr_uid , Uid for user
* @param bool|string $del_index
* @param int $del_index
*
* @return void
* @throws Exception
*/
public function putUnpauseCase($appUid, $usrUid, $index = false)
public function putUnpauseCase($appUid, $usrUid, $index = 0)
{
Validator::isString($appUid, '$app_uid');
Validator::isString($usrUid, '$usr_uid');
Validator::appUid($appUid, '$app_uid');
Validator::usrUid($usrUid, '$usr_uid');
if ($index === false) {
if ($index === 0) {
$index = AppDelegation::getCurrentIndex($appUid);
}
Validator::isInteger($index, '$del_index');

View File

@@ -84,10 +84,10 @@ class Draft extends AbstractCases
/**
* Get data self-services cases by user
*
* @param callable $callback
* @return array
*/
public function getData()
public function getData(callable $callback = null)
{
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
@@ -105,6 +105,9 @@ class Draft extends AbstractCases
}
// Add pagination to the query
$query->offset($this->getOffset())->limit($this->getLimit());
if (is_callable($callback)) {
$callback($query);
}
// Get the data
$results = $query->get();
// Prepare the result

View File

@@ -0,0 +1,461 @@
<?php
namespace ProcessMaker\BusinessModel\Cases;
use ProcessMaker\BusinessModel\Cases\Draft;
use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\BusinessModel\Cases\Paused;
use ProcessMaker\BusinessModel\Cases\Unassigned;
use ProcessMaker\Model\CaseList;
use ProcessMaker\Model\User;
use ProcessMaker\Util\DateTime;
class Home
{
/**
* This is the userId field.
* @var string
*/
private $userId = '';
/**
* Constructor of the class.
* @param type $userId
*/
public function __construct($userId)
{
$this->userId = $userId;
}
/**
* Get the userId field.
* @return string
*/
public function getUserId()
{
return $this->userId;
}
/**
* Get the draft cases.
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $filterCases
* @param string $sort
* @param callable $callback
* @return array
*/
public function getDraft(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC',
callable $callback = null
)
{
$list = new Draft();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the sort parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback));
$result['total'] = $list->getPagingCounters();
return $result;
}
/**
* Get the inbox cases.
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @param callable $callback
* @return array
*/
public function getInbox(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC',
callable $callback = null
)
{
$list = new Inbox();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['delegateFrom'] = $delegateFrom;
$properties['delegateTo'] = $delegateTo;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the pagination parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback));
$result['total'] = $list->getPagingCounters();
return $result;
}
/**
* Get the unassigned cases.
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @param callable $callback
* @return array
*/
public function getUnassigned(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC',
callable $callback = null
)
{
$list = new Unassigned();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['delegateFrom'] = $delegateFrom;
$properties['delegateTo'] = $delegateTo;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the sort parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
// todo: some queries related to the unassigned are using the USR_UID
$list->setUserUid($usrUid);
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback));
$result['total'] = $list->getPagingCounters();
return $result;
}
/**
* Get the paused cases.
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @param callable $callback
* @return array
*/
public function getPaused(
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC',
callable $callback = null
)
{
$list = new Paused();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['delegateFrom'] = $delegateFrom;
$properties['delegateTo'] = $delegateTo;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the sort parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData($callback));
$result['total'] = $list->getPagingCounters();
return $result;
}
/**
* Build the columns and data from the custom list.
* @param string $type
* @param int $id
* @param array $arguments
* @param array $defaultColumns
*/
public function buildCustomCaseList(string $type, int $id, array &$arguments, array &$defaultColumns)
{
$caseList = CaseList::where('CAL_TYPE', '=', $type)
->where('CAL_ID', '=', $id)
->join('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID')
->get()
->first();
if (!empty($caseList)) {
$tableName = $caseList->ADD_TAB_NAME;
//this gets the configured columns
$columns = json_decode($caseList->CAL_COLUMNS);
$columns = CaseList::formattingColumns($type, $caseList->ADD_TAB_UID, $columns);
//this gets the visible columns from the custom List and the fields from the table
if (!empty($columns)) {
$defaultColumns = [];
}
$fields = [];
foreach ($columns as $value) {
if ($value['set'] === true) {
$defaultColumns[] = $value;
if ($value['source'] === $tableName) {
$fields[] = $value['field'];
}
}
}
//this modifies the query
if (!empty($tableName) && !empty($fields)) {
$arguments[] = function ($query) use ($tableName, $fields) {
$query->leftJoin($tableName, "{$tableName}.APP_UID", "=", "APP_DELEGATION.APP_UID");
foreach ($fields as $value) {
$query->addSelect($value);
}
};
}
}
}
/**
* Get the custom draft cases.
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $filterCases
* @param string $sort
* @return array
*/
public function getCustomDraft(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
$arguments = func_get_args();
array_shift($arguments);
$type = 'draft';
$defaultColumns = CaseList::formattingColumns($type, '', []);
$this->buildCustomCaseList($type, $id, $arguments, $defaultColumns);
$result = $this->getDraft(...$arguments);
$result['columns'] = $defaultColumns;
return $result;
}
/**
* Get the custom inbox cases.
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @return array
*/
public function getCustomInbox(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
$arguments = func_get_args();
array_shift($arguments);
$type = 'inbox';
$defaultColumns = CaseList::formattingColumns($type, '', []);
$this->buildCustomCaseList($type, $id, $arguments, $defaultColumns);
$result = $this->getInbox(...$arguments);
$result['columns'] = $defaultColumns;
return $result;
}
/**
* Get the custom unassigned cases.
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @return array
*/
public function getCustomUnassigned(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
$arguments = func_get_args();
array_shift($arguments);
$type = 'unassigned';
$defaultColumns = CaseList::formattingColumns($type, '', []);
$this->buildCustomCaseList($type, $id, $arguments, $defaultColumns);
$result = $this->getUnassigned(...$arguments);
$result['columns'] = $defaultColumns;
return $result;
}
/**
* Get the custom paused cases.
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @return array
*/
public function getCustomPaused(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
$arguments = func_get_args();
array_shift($arguments);
$type = 'paused';
$defaultColumns = CaseList::formattingColumns($type, '', []);
$this->buildCustomCaseList($type, $id, $arguments, $defaultColumns);
$result = $this->getPaused(...$arguments);
$result['columns'] = $defaultColumns;
return $result;
}
}

View File

@@ -96,10 +96,10 @@ class Inbox extends AbstractCases
/**
* Get the data corresponding to List Inbox
*
* @param callable $callback
* @return array
*/
public function getData()
public function getData(callable $callback = null)
{
// Start the query for get the cases related to the user
$query = Delegation::query()->select($this->getColumnsView());
@@ -120,6 +120,9 @@ class Inbox extends AbstractCases
}
// The limit by clause
$query->offset($this->getOffset())->limit($this->getLimit());
if (is_callable($callback)) {
$callback($query);
}
// Execute the query
$results = $query->get();
// Prepare the result

View File

@@ -95,10 +95,10 @@ class Paused extends AbstractCases
/**
* Gets the data for the paused cases list
*
* @param callable $callback
* @return array
*/
public function getData()
public function getData(callable $callback = null)
{
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
@@ -114,6 +114,9 @@ class Paused extends AbstractCases
$query->orderBy($this->getOrderByColumn(), $this->getOrderDirection());
// Add pagination to the query
$query->offset($this->getOffset())->limit($this->getLimit());
if (is_callable($callback)) {
$callback($query);
}
//Execute the query
$results = $query->get();
// Prepare the result

View File

@@ -96,10 +96,10 @@ class Unassigned extends AbstractCases
/**
* Get data self-services cases by user
*
* @param callable $callback
* @return array
*/
public function getData()
public function getData(callable $callback = null)
{
$query = Delegation::query()->select($this->getColumnsView());
// Join with process
@@ -122,6 +122,9 @@ class Unassigned extends AbstractCases
}
// Add pagination to the query
$query->offset($this->getOffset())->limit($this->getLimit());
if (is_callable($callback)) {
$callback($query);
}
// Get the data
$results = $query->get();
// Prepare the result

View File

@@ -311,14 +311,11 @@ class CaseList extends Model
//the fields have differences between the import file and the current table
$requestData['invalidFields'] = $requestData['invalidFields'] ?? '';
if ($requestData['invalidFields'] !== 'continue') {
$fields = Fields::where('ADD_TAB_UID', '=', $array['tableUid'])
->whereNotIn('FLD_NAME', self::$excludeColumns)
->select('FLD_NAME')
->get()
->transform(function ($object) {
return $object->FLD_NAME;
})
->toArray();
$fields = [];
$columns = CaseList::formattingColumns($array['type'], $array['tableUid'], []);
foreach ($columns as $column) {
$fields[] = $column['field'];
}
foreach ($array['columns'] as $value) {
if (!in_array($value['field'], $fields)) {
return [

View File

@@ -994,18 +994,19 @@ class Cases extends Api
* @url PUT /:appUid/unpause
*
* @param string $appUid {@min 1}{@max 32}
* @param int $index {@from body}
*
* @throws RestException
*
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doPutUnpauseCase($appUid)
public function doPutUnpauseCase($appUid, $index = 0)
{
try {
$userUid = $this->getUserId();
$cases = new BmCases();
$cases->putUnpauseCase($appUid, $userUid);
$cases->putUnpauseCase($appUid, $userUid, $index);
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}

View File

@@ -6,9 +6,9 @@ use Exception;
use G;
use Luracast\Restler\RestException;
use Menu;
use ProcessMaker\BusinessModel\Cases\CasesList;
use ProcessMaker\BusinessModel\Cases\Draft;
use ProcessMaker\BusinessModel\Cases\Filter;
use ProcessMaker\BusinessModel\Cases\Home as BMHome;
use ProcessMaker\BusinessModel\Cases\Inbox;
use ProcessMaker\BusinessModel\Cases\Participated;
use ProcessMaker\BusinessModel\Cases\Paused;
@@ -60,7 +60,7 @@ class Home extends Api
*
* @return array
*
* @throws Exception
* @throws RestException
*
* @access protected
* @class AccessControl {@permission PM_CASES}
@@ -74,30 +74,11 @@ class Home extends Api
string $caseTitle = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
) {
)
{
try {
$list = new Draft();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the sort parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData());
$result['total'] = $list->getPagingCounters();
return $result;
$bmHome = new BMHome($this->getUserId());
return $bmHome->getDraft(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
@@ -106,7 +87,8 @@ class Home extends Api
/**
* Get the inbox cases
*
* @url GET /todo
* @url GET /inbox
* @url GET /todo [This is kept for compatibility should not be used 'todo', the reason is to only handle the same verb (inbox) for all 'normal case list' and 'custom case list']
*
* @param int $caseNumber
* @param int $process
@@ -121,7 +103,7 @@ class Home extends Api
*
* @return array
*
* @throws Exception
* @throws RestException
*
* @access protected
* @class AccessControl {@permission PM_CASES}
@@ -137,32 +119,11 @@ class Home extends Api
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
) {
)
{
try {
$list = new Inbox();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['delegateFrom'] = $delegateFrom;
$properties['delegateTo'] = $delegateTo;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the pagination parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData());
$result['total'] = $list->getPagingCounters();
return $result;
$bmHome = new BMHome($this->getUserId());
return $bmHome->getInbox(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
@@ -186,7 +147,7 @@ class Home extends Api
*
* @return array
*
* @throws Exception
* @throws RestException
*
* @access protected
* @class AccessControl {@permission PM_CASES}
@@ -202,34 +163,11 @@ class Home extends Api
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
) {
)
{
try {
$list = new Unassigned();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['delegateFrom'] = $delegateFrom;
$properties['delegateTo'] = $delegateTo;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the sort parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
// todo: some queries related to the unassigned are using the USR_UID
$list->setUserUid($usrUid);
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData());
$result['total'] = $list->getPagingCounters();
return $result;
$bmHome = new BMHome($this->getUserId());
return $bmHome->getUnassigned(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
@@ -253,7 +191,7 @@ class Home extends Api
*
* @return array
*
* @throws Exception
* @throws RestException
*
* @access protected
* @class AccessControl {@permission PM_CASES}
@@ -269,32 +207,171 @@ class Home extends Api
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
) {
)
{
try {
$list = new Paused();
// Define the filters to apply
$properties = [];
$properties['caseNumber'] = $caseNumber;
$properties['caseTitle'] = $caseTitle;
$properties['delegateFrom'] = $delegateFrom;
$properties['delegateTo'] = $delegateTo;
$properties['filterCases'] = $filterCases;
$properties['process'] = $process;
$properties['task'] = $task;
// Get the user that access to the API
$usrUid = $this->getUserId();
$properties['user'] = !empty($usrUid) ? User::getId($usrUid) : 0;
$properties['start'] = $offset;
$properties['limit'] = $limit;
// Set the sort parameters
$sort = explode(',', $sort);
$properties['sort'] = $sort[0];
$properties['dir'] = $sort[1];
$list->setProperties($properties);
$result = [];
$result['data'] = DateTime::convertUtcToTimeZone($list->getData());
$result['total'] = $list->getPagingCounters();
return $result;
$bmHome = new BMHome($this->getUserId());
return $bmHome->getPaused(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the custom draft cases.
* @url GET /draft/:id
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $filterCases
* @param string $sort
* @return array
* @throws RestException
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetCustomDraftCases(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
try {
$bmHome = new BMHome($this->getUserId());
return $bmHome->getCustomDraft(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the custom inbox cases.
* @url GET /inbox/:id
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @return array
* @throws RestException
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetCustomTodoCases(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
try {
$bmHome = new BMHome($this->getUserId());
return $bmHome->getCustomInbox(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the custom unassigned cases.
* @url GET /unassigned/:id
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @return array
* @throws RestException
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetCustomUnassignedCases(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
try {
$bmHome = new BMHome($this->getUserId());
return $bmHome->getCustomUnassigned(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* Get the custom paused cases.
* @url GET /paused/:id
* @param int $id
* @param int $caseNumber
* @param int $process
* @param int $task
* @param int $limit
* @param int $offset
* @param string $caseTitle
* @param string $delegateFrom
* @param string $delegateTo
* @param string $filterCases
* @param string $sort
* @return array
* @throws RestException
* @access protected
* @class AccessControl {@permission PM_CASES}
*/
public function doGetCustomPausedCases(
int $id,
int $caseNumber = 0,
int $process = 0,
int $task = 0,
int $limit = 15,
int $offset = 0,
string $caseTitle = '',
string $delegateFrom = '',
string $delegateTo = '',
string $filterCases = '',
string $sort = 'APP_NUMBER,DESC'
)
{
try {
$bmHome = new BMHome($this->getUserId());
return $bmHome->getCustomPaused(...func_get_args());
} catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}