2014-03-14 15:33:35 -04:00
|
|
|
<?php
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-04-02 16:51:28 -04:00
|
|
|
namespace ProcessMaker\BusinessModel;
|
2014-03-14 15:33:35 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
use AppCacheView;
|
|
|
|
|
use AppCacheViewPeer;
|
|
|
|
|
use AppDelay;
|
|
|
|
|
use AppDelayPeer;
|
2018-11-08 08:42:51 -04:00
|
|
|
use AppDelegation;
|
|
|
|
|
use AppDelegationPeer;
|
2017-10-05 14:54:41 -04:00
|
|
|
use AppDocument;
|
|
|
|
|
use AppDocumentPeer;
|
|
|
|
|
use AppHistoryPeer;
|
2019-09-03 12:39:37 -04:00
|
|
|
use Application;
|
2018-11-08 08:42:51 -04:00
|
|
|
use ApplicationPeer;
|
|
|
|
|
use Applications;
|
2020-06-10 12:15:01 -04:00
|
|
|
use AppNotes;
|
2017-10-05 14:54:41 -04:00
|
|
|
use AppNotesPeer;
|
2018-11-08 08:42:51 -04:00
|
|
|
use AppSolr;
|
2019-10-07 09:05:05 -04:00
|
|
|
use AppTimeoutActionExecuted;
|
2017-10-05 14:54:41 -04:00
|
|
|
use BasePeer;
|
2018-11-08 08:42:51 -04:00
|
|
|
use Bootstrap;
|
2017-10-05 14:54:41 -04:00
|
|
|
use BpmnEngineServicesSearchIndex;
|
|
|
|
|
use Cases as ClassesCases;
|
|
|
|
|
use CasesPeer;
|
|
|
|
|
use Configurations;
|
2019-04-24 09:43:53 -04:00
|
|
|
use CreoleTypes;
|
2018-11-08 08:42:51 -04:00
|
|
|
use Criteria;
|
2019-10-07 09:05:05 -04:00
|
|
|
use DateTime;
|
2017-10-05 14:54:41 -04:00
|
|
|
use DBAdapter;
|
|
|
|
|
use EntitySolrRequestData;
|
2018-11-08 08:42:51 -04:00
|
|
|
use Exception;
|
2017-10-05 14:54:41 -04:00
|
|
|
use G;
|
|
|
|
|
use Groups;
|
2017-12-12 15:11:16 -04:00
|
|
|
use GroupUserPeer;
|
2020-11-30 20:01:43 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-08-10 17:11:55 -04:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-11-08 08:42:51 -04:00
|
|
|
use InputDocument;
|
2017-10-05 14:54:41 -04:00
|
|
|
use InvalidIndexSearchTextException;
|
2022-09-29 09:51:33 -04:00
|
|
|
use Luracast\Restler\RestException;
|
2017-08-11 15:49:39 -04:00
|
|
|
use PmDynaform;
|
2019-04-24 09:43:53 -04:00
|
|
|
use PmTable;
|
2021-05-12 18:59:01 -04:00
|
|
|
use ProcessMaker\BusinessModel\Cases as BmCases;
|
2018-11-08 08:42:51 -04:00
|
|
|
use ProcessMaker\BusinessModel\ProcessSupervisor as BmProcessSupervisor;
|
2017-10-05 14:54:41 -04:00
|
|
|
use ProcessMaker\BusinessModel\Task as BmTask;
|
|
|
|
|
use ProcessMaker\BusinessModel\User as BmUser;
|
|
|
|
|
use ProcessMaker\Core\System;
|
2018-11-08 08:42:51 -04:00
|
|
|
use ProcessMaker\Exception\UploadException;
|
2020-06-12 20:59:28 -04:00
|
|
|
use ProcessMaker\Exception\CaseNoteUploadFile;
|
2021-08-02 13:06:17 -04:00
|
|
|
use ProcessMaker\Model\AppDelay as Delay;
|
2020-01-06 14:30:41 -04:00
|
|
|
use ProcessMaker\Model\Application as ModelApplication;
|
2020-06-10 12:15:01 -04:00
|
|
|
use ProcessMaker\Model\AppNotes as Notes;
|
2019-10-07 09:05:05 -04:00
|
|
|
use ProcessMaker\Model\AppTimeoutAction;
|
2019-05-20 13:23:31 -04:00
|
|
|
use ProcessMaker\Model\Delegation;
|
2020-06-04 10:38:48 -04:00
|
|
|
use ProcessMaker\Model\Documents;
|
2019-10-07 09:05:05 -04:00
|
|
|
use ProcessMaker\Model\ListUnassigned;
|
|
|
|
|
use ProcessMaker\Model\Triggers;
|
2021-07-19 13:19:55 -04:00
|
|
|
use ProcessMaker\Model\ProcessUser;
|
|
|
|
|
use ProcessMaker\Model\User;
|
2017-10-05 14:54:41 -04:00
|
|
|
use ProcessMaker\Plugins\PluginRegistry;
|
2022-09-29 09:51:33 -04:00
|
|
|
use ProcessMaker\Services\Api;
|
2017-09-19 09:56:06 -04:00
|
|
|
use ProcessMaker\Services\OAuth2\Server;
|
2019-04-24 09:43:53 -04:00
|
|
|
use ProcessMaker\Util\DateTime as UtilDateTime;
|
2018-11-08 08:42:51 -04:00
|
|
|
use ProcessMaker\Validation\ExceptionRestApi;
|
2020-06-12 20:59:28 -04:00
|
|
|
use ProcessMaker\Validation\ValidationUploadedFiles;
|
2018-11-08 08:42:51 -04:00
|
|
|
use ProcessMaker\Validation\Validator as FileValidator;
|
|
|
|
|
use ProcessPeer;
|
2017-10-05 14:54:41 -04:00
|
|
|
use ProcessUserPeer;
|
|
|
|
|
use RBAC;
|
|
|
|
|
use ResultSet;
|
|
|
|
|
use SubApplication;
|
|
|
|
|
use Task as ModelTask;
|
|
|
|
|
use TaskPeer;
|
2018-11-08 08:42:51 -04:00
|
|
|
use Tasks as ClassesTasks;
|
2017-10-05 14:54:41 -04:00
|
|
|
use TaskUserPeer;
|
|
|
|
|
use Users as ModelUsers;
|
|
|
|
|
use UsersPeer;
|
|
|
|
|
use WsBase;
|
2014-03-14 15:33:35 -04:00
|
|
|
|
|
|
|
|
class Cases
|
|
|
|
|
{
|
2014-06-06 12:04:30 -04:00
|
|
|
private $formatFieldNameInUppercase = true;
|
2017-01-05 16:13:53 -04:00
|
|
|
private $messageResponse = [];
|
2017-12-08 18:28:16 +00:00
|
|
|
private $solr = null;
|
|
|
|
|
private $solrEnv = null;
|
2018-11-08 08:42:51 -04:00
|
|
|
const MB_IN_KB = 1024;
|
|
|
|
|
const UNIT_MB = 'MB';
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the format of the fields name (uppercase, lowercase)
|
|
|
|
|
*
|
|
|
|
|
* @param bool $flag Value that set the format
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-06-06 12:04:30 -04:00
|
|
|
*/
|
|
|
|
|
public function setFormatFieldNameInUppercase($flag)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$this->formatFieldNameInUppercase = $flag;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-06-06 12:04:30 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the name of the field according to the format
|
|
|
|
|
*
|
|
|
|
|
* @param string $fieldName Field name
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return string, the field name according the format
|
|
|
|
|
* @throws Exception
|
2014-06-06 12:04:30 -04:00
|
|
|
*/
|
|
|
|
|
public function getFieldNameByFormatFieldName($fieldName)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2017-10-05 14:54:41 -04:00
|
|
|
return ($this->formatFieldNameInUppercase) ? strtoupper($fieldName) : strtolower($fieldName);
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-06-06 12:04:30 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 16:28:17 -04:00
|
|
|
/**
|
|
|
|
|
* Throw the exception "The Case doesn't exist"
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
2016-02-25 16:28:17 -04:00
|
|
|
* @param string $fieldNameForException Field name for the exception
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
2018-01-04 09:58:45 -04:00
|
|
|
* @throws Exception
|
2016-02-25 16:28:17 -04:00
|
|
|
*/
|
|
|
|
|
private function throwExceptionCaseDoesNotExist($applicationUid, $fieldNameForException)
|
|
|
|
|
{
|
2017-10-05 14:54:41 -04:00
|
|
|
throw new Exception(G::LoadTranslation(
|
2016-02-25 16:28:17 -04:00
|
|
|
'ID_CASE_DOES_NOT_EXIST2', [$fieldNameForException, $applicationUid]
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 12:04:30 -04:00
|
|
|
/**
|
|
|
|
|
* Verify if does not exist the Case in table APPLICATION
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param string $delIndex Delegation index
|
2014-06-06 12:04:30 -04:00
|
|
|
* @param string $fieldNameForException Field name for the exception
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception, Throw exception if does not exist the Case in table APPLICATION
|
2014-06-06 12:04:30 -04:00
|
|
|
*/
|
2015-09-25 19:25:47 -04:00
|
|
|
public function throwExceptionIfNotExistsCase($applicationUid, $delIndex, $fieldNameForException)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2017-10-05 14:54:41 -04:00
|
|
|
$obj = ApplicationPeer::retrieveByPK($applicationUid);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
2015-09-25 19:25:47 -04:00
|
|
|
$flag = is_null($obj);
|
|
|
|
|
|
|
|
|
|
if (!$flag && $delIndex > 0) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$obj = AppDelegationPeer::retrieveByPK($applicationUid, $delIndex);
|
2015-09-25 19:25:47 -04:00
|
|
|
|
|
|
|
|
$flag = is_null($obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($flag) {
|
2016-02-25 16:28:17 -04:00
|
|
|
$this->throwExceptionCaseDoesNotExist($applicationUid, $fieldNameForException);
|
|
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2016-02-25 16:28:17 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Application record
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param array $arrayVariableNameForException Variable name for exception
|
|
|
|
|
* @param bool $throwException Flag to throw the exception if the main parameters are invalid or do not exist
|
2016-02-25 16:28:17 -04:00
|
|
|
* (TRUE: throw the exception; FALSE: returns FALSE)
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array, an array with Application record
|
|
|
|
|
* @throws Exception, ThrowTheException/FALSE otherwise
|
2016-02-25 16:28:17 -04:00
|
|
|
*/
|
|
|
|
|
public function getApplicationRecordByPk(
|
|
|
|
|
$applicationUid,
|
|
|
|
|
array $arrayVariableNameForException,
|
|
|
|
|
$throwException = true
|
|
|
|
|
) {
|
|
|
|
|
try {
|
2017-10-05 14:54:41 -04:00
|
|
|
$obj = ApplicationPeer::retrieveByPK($applicationUid);
|
2016-02-25 16:28:17 -04:00
|
|
|
|
|
|
|
|
if (is_null($obj)) {
|
|
|
|
|
if ($throwException) {
|
|
|
|
|
$this->throwExceptionCaseDoesNotExist(
|
|
|
|
|
$applicationUid, $arrayVariableNameForException['$applicationUid']
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
2017-10-05 14:54:41 -04:00
|
|
|
return $obj->toArray(BasePeer::TYPE_FIELDNAME);
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2016-02-25 16:28:17 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get AppDelegation record
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param int $delIndex Delegation index
|
|
|
|
|
* @param array $arrayVariableNameForException Variable name for exception
|
|
|
|
|
* @param bool $throwException Flag to throw the exception if the main parameters are invalid or do not exist
|
2016-02-25 16:28:17 -04:00
|
|
|
* (TRUE: throw the exception; FALSE: returns FALSE)
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array, an array with AppDelegation record
|
|
|
|
|
* @throws Exception, ThrowTheException/FALSE otherwise
|
2016-02-25 16:28:17 -04:00
|
|
|
*/
|
|
|
|
|
public function getAppDelegationRecordByPk(
|
|
|
|
|
$applicationUid,
|
|
|
|
|
$delIndex,
|
|
|
|
|
array $arrayVariableNameForException,
|
|
|
|
|
$throwException = true
|
|
|
|
|
) {
|
|
|
|
|
try {
|
2017-10-05 14:54:41 -04:00
|
|
|
$obj = AppDelegationPeer::retrieveByPK($applicationUid, $delIndex);
|
2016-02-25 16:28:17 -04:00
|
|
|
|
|
|
|
|
if (is_null($obj)) {
|
|
|
|
|
if ($throwException) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw new Exception(G::LoadTranslation(
|
2016-02-25 16:28:17 -04:00
|
|
|
'ID_CASE_DEL_INDEX_DOES_NOT_EXIST',
|
|
|
|
|
[
|
|
|
|
|
$arrayVariableNameForException['$applicationUid'],
|
|
|
|
|
$applicationUid,
|
|
|
|
|
$arrayVariableNameForException['$delIndex'],
|
|
|
|
|
$delIndex
|
|
|
|
|
]
|
|
|
|
|
));
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-06-06 12:04:30 -04:00
|
|
|
}
|
2016-02-25 16:28:17 -04:00
|
|
|
|
|
|
|
|
//Return
|
2017-10-05 14:54:41 -04:00
|
|
|
return $obj->toArray(BasePeer::TYPE_FIELDNAME);
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-06-06 12:04:30 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-27 16:42:40 -04:00
|
|
|
/**
|
|
|
|
|
* Get list counters
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $userUid Unique id of User
|
|
|
|
|
* @param array $arrayType Type lists
|
2016-01-27 16:42:40 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array, the list counters
|
|
|
|
|
* @throws Exception
|
2016-01-27 16:42:40 -04:00
|
|
|
*/
|
|
|
|
|
public function getListCounters($userUid, array $arrayType)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2017-10-05 14:54:41 -04:00
|
|
|
$appCacheView = new AppCacheView();
|
2016-01-27 16:42:40 -04:00
|
|
|
|
2017-12-08 18:28:16 +00:00
|
|
|
if ($this->isSolrEnabled()) {
|
2016-01-27 16:42:40 -04:00
|
|
|
$arrayListCounter = array_merge(
|
2017-12-08 18:28:16 +00:00
|
|
|
$this->solr->getCasesCount($userUid),
|
2016-01-27 16:42:40 -04:00
|
|
|
$appCacheView->getAllCounters(['completed', 'cancelled'], $userUid)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$arrayListCounter = $appCacheView->getAllCounters($arrayType, $userUid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayListCounter;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2016-01-27 16:42:40 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 15:33:35 -04:00
|
|
|
/**
|
2017-07-04 10:10:09 -04:00
|
|
|
* Get list of cases from: todo, draft, unassigned
|
|
|
|
|
* Get list of cases for the following REST endpoints:
|
|
|
|
|
* /light/todo
|
|
|
|
|
* /light/draft
|
|
|
|
|
* /light/participated
|
|
|
|
|
* /light/paused
|
|
|
|
|
* /light/unassigned
|
2014-03-14 15:33:35 -04:00
|
|
|
*
|
|
|
|
|
* @access public
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param array $dataList , Data for list
|
2017-07-04 10:10:09 -04:00
|
|
|
* @return array $response
|
2014-03-14 15:33:35 -04:00
|
|
|
*/
|
|
|
|
|
public function getList($dataList = array())
|
|
|
|
|
{
|
2014-03-17 15:13:34 -04:00
|
|
|
Validator::isArray($dataList, '$dataList');
|
|
|
|
|
if (!isset($dataList["userId"])) {
|
2017-05-18 10:58:13 -04:00
|
|
|
$dataList["userId"] = null;
|
2014-03-17 15:13:34 -04:00
|
|
|
}
|
2014-03-14 15:33:35 -04:00
|
|
|
|
2017-07-04 10:10:09 -04:00
|
|
|
//We need to use the USR_UID for the cases in the list
|
|
|
|
|
$userUid = isset($dataList["userUid"]) ? $dataList["userUid"] : $dataList["userId"];
|
2017-10-05 14:54:41 -04:00
|
|
|
$callback = isset($dataList["callback"]) ? $dataList["callback"] : "stcCallback1001";
|
|
|
|
|
$dir = isset($dataList["dir"]) ? $dataList["dir"] : "DESC";
|
|
|
|
|
$sort = isset($dataList["sort"]) ? $dataList["sort"] : "APPLICATION.APP_NUMBER";
|
2017-05-05 09:44:27 -04:00
|
|
|
if ($sort === 'APP_CACHE_VIEW.APP_NUMBER') {
|
|
|
|
|
$sort = "APPLICATION.APP_NUMBER";
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
$start = isset($dataList["start"]) ? $dataList["start"] : "0";
|
|
|
|
|
$limit = isset($dataList["limit"]) ? $dataList["limit"] : "";
|
|
|
|
|
$filter = isset($dataList["filter"]) ? $dataList["filter"] : "";
|
|
|
|
|
$process = isset($dataList["process"]) ? $dataList["process"] : "";
|
|
|
|
|
$category = isset($dataList["category"]) ? $dataList["category"] : "";
|
|
|
|
|
$status = isset($dataList["status"]) ? strtoupper($dataList["status"]) : "";
|
|
|
|
|
$search = isset($dataList["search"]) ? $dataList["search"] : "";
|
|
|
|
|
$action = isset($dataList["action"]) ? $dataList["action"] : "todo";
|
|
|
|
|
$paged = isset($dataList["paged"]) ? $dataList["paged"] : true;
|
2014-03-14 15:33:35 -04:00
|
|
|
$type = "extjs";
|
2017-10-05 14:54:41 -04:00
|
|
|
$dateFrom = (!empty($dataList["dateFrom"])) ? substr($dataList["dateFrom"], 0, 10) : "";
|
|
|
|
|
$dateTo = (!empty($dataList["dateTo"])) ? substr($dataList["dateTo"], 0, 10) : "";
|
|
|
|
|
$newerThan = (!empty($dataList['newerThan'])) ? $dataList['newerThan'] : '';
|
|
|
|
|
$oldestThan = (!empty($dataList['oldestthan'])) ? $dataList['oldestthan'] : '';
|
2017-07-04 10:10:09 -04:00
|
|
|
|
2017-08-11 12:33:30 -04:00
|
|
|
$apps = new Applications();
|
2017-07-04 10:10:09 -04:00
|
|
|
$response = $apps->getAll(
|
2017-10-05 14:54:41 -04:00
|
|
|
$userUid,
|
|
|
|
|
$start,
|
|
|
|
|
$limit,
|
|
|
|
|
$action,
|
|
|
|
|
$filter,
|
|
|
|
|
$search,
|
|
|
|
|
$process,
|
|
|
|
|
$status,
|
|
|
|
|
$type,
|
|
|
|
|
$dateFrom,
|
|
|
|
|
$dateTo,
|
|
|
|
|
$callback,
|
|
|
|
|
$dir,
|
|
|
|
|
(strpos($sort, ".") !== false) ? $sort : "APP_CACHE_VIEW." . $sort,
|
|
|
|
|
$category,
|
|
|
|
|
true,
|
|
|
|
|
$paged,
|
|
|
|
|
$newerThan,
|
|
|
|
|
$oldestThan
|
2017-07-04 10:10:09 -04:00
|
|
|
);
|
|
|
|
|
if (!empty($response['data'])) {
|
|
|
|
|
foreach ($response['data'] as &$value) {
|
|
|
|
|
$value = array_change_key_case($value, CASE_LOWER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($paged) {
|
|
|
|
|
$response['total'] = $response['totalCount'];
|
2017-10-05 14:54:41 -04:00
|
|
|
$response['start'] = $start + 1;
|
2017-07-04 10:10:09 -04:00
|
|
|
$response['limit'] = $limit;
|
|
|
|
|
$response['sort'] = G::toLower($sort);
|
|
|
|
|
$response['dir'] = G::toLower($dir);
|
|
|
|
|
$response['cat_uid'] = $category;
|
|
|
|
|
$response['pro_uid'] = $process;
|
|
|
|
|
$response['search'] = $search;
|
|
|
|
|
} else {
|
|
|
|
|
$response = $response['data'];
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-07-04 10:10:09 -04:00
|
|
|
return $response;
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-07-04 10:10:09 -04:00
|
|
|
/**
|
|
|
|
|
* Search cases and get list of cases
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
|
|
|
|
* @param array $dataList, Data for list
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
2017-07-04 10:10:09 -04:00
|
|
|
*/
|
|
|
|
|
public function getCasesSearch($dataList = array())
|
|
|
|
|
{
|
|
|
|
|
Validator::isArray($dataList, '$dataList');
|
|
|
|
|
if (!isset($dataList["userId"])) {
|
|
|
|
|
$dataList["userId"] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//We need to user the USR_ID for performance
|
|
|
|
|
$userId = $dataList["userId"];
|
2017-10-05 14:54:41 -04:00
|
|
|
$dir = isset($dataList["dir"]) ? $dataList["dir"] : "DESC";
|
|
|
|
|
$sort = isset($dataList["sort"]) ? $dataList["sort"] : "APPLICATION.APP_NUMBER";
|
2017-07-04 10:10:09 -04:00
|
|
|
if ($sort === 'APP_CACHE_VIEW.APP_NUMBER') {
|
|
|
|
|
$sort = "APPLICATION.APP_NUMBER";
|
|
|
|
|
}
|
2018-07-09 14:15:42 -04:00
|
|
|
$start = !empty($dataList["start"]) ? $dataList["start"] : 0;
|
|
|
|
|
$limit = !empty($dataList["limit"]) ? $dataList["limit"] : 15;
|
2017-10-05 14:54:41 -04:00
|
|
|
$process = isset($dataList["process"]) ? $dataList["process"] : "";
|
|
|
|
|
$category = isset($dataList["category"]) ? $dataList["category"] : "";
|
|
|
|
|
$status = isset($dataList["status"]) ? strtoupper($dataList["status"]) : "";
|
|
|
|
|
$user = isset($dataList["user"]) ? $dataList["user"] : "";
|
|
|
|
|
$search = isset($dataList["search"]) ? $dataList["search"] : "";
|
|
|
|
|
$dateFrom = (!empty($dataList["dateFrom"])) ? substr($dataList["dateFrom"], 0, 10) : "";
|
|
|
|
|
$dateTo = (!empty($dataList["dateTo"])) ? substr($dataList["dateTo"], 0, 10) : "";
|
|
|
|
|
$filterStatus = isset($dataList["filterStatus"]) ? strtoupper($dataList["filterStatus"]) : "";
|
2014-03-14 15:33:35 -04:00
|
|
|
|
2017-08-11 12:33:30 -04:00
|
|
|
$apps = new Applications();
|
2017-05-05 09:44:27 -04:00
|
|
|
$response = $apps->searchAll(
|
2017-07-04 10:10:09 -04:00
|
|
|
$userId,
|
2017-04-25 16:02:18 -04:00
|
|
|
$start,
|
|
|
|
|
$limit,
|
|
|
|
|
$search,
|
|
|
|
|
$process,
|
2017-05-05 09:44:27 -04:00
|
|
|
$filterStatus,
|
2017-04-25 16:02:18 -04:00
|
|
|
$dir,
|
2017-05-05 09:44:27 -04:00
|
|
|
$sort,
|
2017-04-25 16:02:18 -04:00
|
|
|
$category,
|
2017-05-05 09:44:27 -04:00
|
|
|
$dateFrom,
|
|
|
|
|
$dateTo
|
2017-04-25 16:02:18 -04:00
|
|
|
);
|
2014-03-14 15:33:35 -04:00
|
|
|
|
2017-05-05 09:44:27 -04:00
|
|
|
$response['total'] = 0;
|
2017-10-05 14:54:41 -04:00
|
|
|
$response['start'] = $start + 1;
|
2017-05-05 09:44:27 -04:00
|
|
|
$response['limit'] = $limit;
|
|
|
|
|
$response['sort'] = G::toLower($sort);
|
|
|
|
|
$response['dir'] = G::toLower($dir);
|
|
|
|
|
$response['cat_uid'] = $category;
|
|
|
|
|
$response['pro_uid'] = $process;
|
|
|
|
|
$response['search'] = $search;
|
2017-07-04 10:10:09 -04:00
|
|
|
$response['app_status'] = G::toLower($status);
|
|
|
|
|
$response['usr_uid'] = $user;
|
|
|
|
|
$response['date_from'] = $dateFrom;
|
|
|
|
|
$response['date_to'] = $dateTo;
|
|
|
|
|
|
2014-03-27 12:17:06 -04:00
|
|
|
return $response;
|
2014-03-14 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-08 18:28:16 +00:00
|
|
|
/**
|
|
|
|
|
* Verify if Solr is Enabled
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private function isSolrEnabled()
|
|
|
|
|
{
|
|
|
|
|
$solrEnabled = false;
|
|
|
|
|
$this->solrEnv = !empty($this->solrEnv) ? $this->solrEnv : System::solrEnv();
|
|
|
|
|
if ($this->solrEnv !== false) {
|
|
|
|
|
$this->solr = !empty($this->solr) ? $this->solr : new AppSolr(
|
|
|
|
|
$this->solrEnv['solr_enabled'],
|
|
|
|
|
$this->solrEnv['solr_host'],
|
|
|
|
|
$this->solrEnv['solr_instance']
|
|
|
|
|
);
|
|
|
|
|
if ($this->solr->isSolrEnabled() && $this->solrEnv["solr_enabled"] == true) {
|
|
|
|
|
$solrEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $solrEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 15:24:14 -04:00
|
|
|
/**
|
|
|
|
|
* Get data of a Case
|
|
|
|
|
*
|
2014-03-20 17:05:04 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
2014-03-17 15:24:14 -04:00
|
|
|
* @param string $userUid Unique id of User
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return object
|
|
|
|
|
* @throws Exception
|
2014-03-17 15:24:14 -04:00
|
|
|
*/
|
2014-03-20 17:05:04 -04:00
|
|
|
public function getCaseInfo($applicationUid, $userUid)
|
2014-03-17 15:24:14 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2017-12-08 18:28:16 +00:00
|
|
|
if ($this->isSolrEnabled()) {
|
2014-03-17 15:24:14 -04:00
|
|
|
try {
|
2017-12-08 18:28:16 +00:00
|
|
|
//Check if there are missing records to reindex and reindex them
|
|
|
|
|
$this->solr->synchronizePendingApplications();
|
|
|
|
|
|
2014-03-17 15:24:14 -04:00
|
|
|
$arrayData = array();
|
|
|
|
|
$delegationIndexes = array();
|
|
|
|
|
$columsToInclude = array("APP_UID");
|
|
|
|
|
$solrSearchText = null;
|
|
|
|
|
//Todo
|
2017-10-05 14:54:41 -04:00
|
|
|
$solrSearchText = $solrSearchText . (($solrSearchText != null) ? " OR " : null) . "(APP_STATUS:TO_DO AND APP_ASSIGNED_USERS:" . $userUid . ")";
|
2014-03-17 15:24:14 -04:00
|
|
|
$delegationIndexes[] = "APP_ASSIGNED_USER_DEL_INDEX_" . $userUid . "_txt";
|
|
|
|
|
//Draft
|
2017-10-05 14:54:41 -04:00
|
|
|
$solrSearchText = $solrSearchText . (($solrSearchText != null) ? " OR " : null) . "(APP_STATUS:DRAFT AND APP_DRAFT_USER:" . $userUid . ")";
|
2014-03-17 15:24:14 -04:00
|
|
|
//Index is allways 1
|
|
|
|
|
$solrSearchText = "($solrSearchText)";
|
|
|
|
|
//Add del_index dynamic fields to list of resulting columns
|
|
|
|
|
$columsToIncludeFinal = array_merge($columsToInclude, $delegationIndexes);
|
2017-10-05 14:54:41 -04:00
|
|
|
$solrRequestData = EntitySolrRequestData::createForRequestPagination(
|
2014-03-17 15:24:14 -04:00
|
|
|
array(
|
2017-12-08 18:28:16 +00:00
|
|
|
"workspace" => $this->solrEnv["solr_instance"],
|
2014-03-17 15:24:14 -04:00
|
|
|
"startAfter" => 0,
|
2017-10-05 14:54:41 -04:00
|
|
|
"pageSize" => 1000,
|
2014-03-17 15:24:14 -04:00
|
|
|
"searchText" => $solrSearchText,
|
|
|
|
|
"numSortingCols" => 1,
|
|
|
|
|
"sortCols" => array("APP_NUMBER"),
|
2017-10-05 14:54:41 -04:00
|
|
|
"sortDir" => array(strtolower("DESC")),
|
|
|
|
|
"includeCols" => $columsToIncludeFinal,
|
2014-03-17 15:24:14 -04:00
|
|
|
"resultFormat" => "json"
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
//Use search index to return list of cases
|
2017-12-08 18:28:16 +00:00
|
|
|
$searchIndex = new BpmnEngineServicesSearchIndex($this->solr->isSolrEnabled(), $this->solrEnv["solr_host"]);
|
2014-03-17 15:24:14 -04:00
|
|
|
//Execute query
|
|
|
|
|
$solrQueryResult = $searchIndex->getDataTablePaginatedList($solrRequestData);
|
|
|
|
|
//Get the missing data from database
|
|
|
|
|
$arrayApplicationUid = array();
|
|
|
|
|
foreach ($solrQueryResult->aaData as $i => $data) {
|
|
|
|
|
$arrayApplicationUid[] = $data["APP_UID"];
|
|
|
|
|
}
|
2017-12-08 18:28:16 +00:00
|
|
|
$aaappsDBData = $this->solr->getListApplicationDelegationData($arrayApplicationUid);
|
2014-03-17 15:24:14 -04:00
|
|
|
foreach ($solrQueryResult->aaData as $i => $data) {
|
|
|
|
|
//Initialize array
|
|
|
|
|
$delIndexes = array(); //Store all the delegation indexes
|
|
|
|
|
//Complete empty values
|
|
|
|
|
$applicationUid = $data["APP_UID"]; //APP_UID
|
|
|
|
|
//Get all the indexes returned by Solr as columns
|
2014-04-22 11:11:03 -04:00
|
|
|
for ($i = count($columsToInclude); $i <= count($data) - 1; $i++) {
|
2014-03-17 15:24:14 -04:00
|
|
|
if (is_array($data[$columsToIncludeFinal[$i]])) {
|
|
|
|
|
foreach ($data[$columsToIncludeFinal[$i]] as $delIndex) {
|
|
|
|
|
$delIndexes[] = $delIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Verify if the delindex is an array
|
|
|
|
|
//if is not check different types of repositories
|
|
|
|
|
//the delegation index must always be defined.
|
|
|
|
|
if (count($delIndexes) == 0) {
|
|
|
|
|
$delIndexes[] = 1; // the first default index
|
|
|
|
|
}
|
|
|
|
|
//Remove duplicated
|
|
|
|
|
$delIndexes = array_unique($delIndexes);
|
|
|
|
|
//Get records
|
|
|
|
|
foreach ($delIndexes as $delIndex) {
|
|
|
|
|
$aRow = array();
|
|
|
|
|
//Copy result values to new row from Solr server
|
|
|
|
|
$aRow["APP_UID"] = $data["APP_UID"];
|
|
|
|
|
//Get delegation data from DB
|
|
|
|
|
//Filter data from db
|
2017-12-08 18:28:16 +00:00
|
|
|
$indexes = $this->solr->aaSearchRecords($aaappsDBData, array(
|
2014-03-17 15:24:14 -04:00
|
|
|
"APP_UID" => $applicationUid,
|
|
|
|
|
"DEL_INDEX" => $delIndex
|
|
|
|
|
));
|
|
|
|
|
foreach ($indexes as $index) {
|
|
|
|
|
$row = $aaappsDBData[$index];
|
|
|
|
|
}
|
2014-04-22 11:11:03 -04:00
|
|
|
if (!isset($row)) {
|
2014-03-17 15:24:14 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-11 14:10:44 -04:00
|
|
|
$ws = new WsBase();
|
2014-03-20 17:05:04 -04:00
|
|
|
$fields = $ws->getCaseInfo($applicationUid, $row["DEL_INDEX"]);
|
|
|
|
|
$array = json_decode(json_encode($fields), true);
|
|
|
|
|
if ($array ["status_code"] != 0) {
|
2017-08-10 10:43:44 -04:00
|
|
|
throw (new Exception($array ["message"]));
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
|
|
|
|
$array['app_uid'] = $array['caseId'];
|
|
|
|
|
$array['app_number'] = $array['caseNumber'];
|
|
|
|
|
$array['app_name'] = $array['caseName'];
|
|
|
|
|
$array['app_status'] = $array['caseStatus'];
|
|
|
|
|
$array['app_init_usr_uid'] = $array['caseCreatorUser'];
|
2014-04-08 12:50:16 -04:00
|
|
|
$array['app_init_usr_username'] = trim($array['caseCreatorUserName']);
|
2014-03-20 17:05:04 -04:00
|
|
|
$array['pro_uid'] = $array['processId'];
|
|
|
|
|
$array['pro_name'] = $array['processName'];
|
|
|
|
|
$array['app_create_date'] = $array['createDate'];
|
|
|
|
|
$array['app_update_date'] = $array['updateDate'];
|
|
|
|
|
$array['current_task'] = $array['currentUsers'];
|
2017-10-05 14:54:41 -04:00
|
|
|
for ($i = 0; $i <= count($array['current_task']) - 1; $i++) {
|
2014-03-20 17:05:04 -04:00
|
|
|
$current_task = $array['current_task'][$i];
|
|
|
|
|
$current_task['usr_uid'] = $current_task['userId'];
|
2014-03-21 16:45:35 -04:00
|
|
|
$current_task['usr_name'] = trim($current_task['userName']);
|
2014-03-20 17:05:04 -04:00
|
|
|
$current_task['tas_uid'] = $current_task['taskId'];
|
|
|
|
|
$current_task['tas_title'] = $current_task['taskName'];
|
|
|
|
|
$current_task['del_index'] = $current_task['delIndex'];
|
|
|
|
|
$current_task['del_thread'] = $current_task['delThread'];
|
|
|
|
|
$current_task['del_thread_status'] = $current_task['delThreadStatus'];
|
|
|
|
|
unset($current_task['userId']);
|
|
|
|
|
unset($current_task['userName']);
|
|
|
|
|
unset($current_task['taskId']);
|
|
|
|
|
unset($current_task['taskName']);
|
|
|
|
|
unset($current_task['delIndex']);
|
|
|
|
|
unset($current_task['delThread']);
|
|
|
|
|
unset($current_task['delThreadStatus']);
|
|
|
|
|
$aCurrent_task[] = $current_task;
|
|
|
|
|
}
|
|
|
|
|
unset($array['status_code']);
|
|
|
|
|
unset($array['message']);
|
|
|
|
|
unset($array['timestamp']);
|
|
|
|
|
unset($array['caseParalell']);
|
|
|
|
|
unset($array['caseId']);
|
|
|
|
|
unset($array['caseNumber']);
|
|
|
|
|
unset($array['caseName']);
|
|
|
|
|
unset($array['caseStatus']);
|
|
|
|
|
unset($array['caseCreatorUser']);
|
|
|
|
|
unset($array['caseCreatorUserName']);
|
|
|
|
|
unset($array['processId']);
|
|
|
|
|
unset($array['processName']);
|
|
|
|
|
unset($array['createDate']);
|
|
|
|
|
unset($array['updateDate']);
|
|
|
|
|
unset($array['currentUsers']);
|
|
|
|
|
$current_task = json_decode(json_encode($aCurrent_task), false);
|
|
|
|
|
$oResponse = json_decode(json_encode($array), false);
|
|
|
|
|
$oResponse->current_task = $current_task;
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-17 17:06:59 -04:00
|
|
|
//Return
|
2014-03-20 17:05:04 -04:00
|
|
|
return $oResponse;
|
2014-03-17 15:24:14 -04:00
|
|
|
}
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
} catch (InvalidIndexSearchTextException $e) {
|
2014-03-17 15:24:14 -04:00
|
|
|
$arrayData = array();
|
2017-10-05 14:54:41 -04:00
|
|
|
$arrayData[] = array(
|
|
|
|
|
"app_uid" => $e->getMessage(),
|
|
|
|
|
"app_name" => $e->getMessage(),
|
|
|
|
|
"del_index" => $e->getMessage(),
|
|
|
|
|
"pro_uid" => $e->getMessage()
|
|
|
|
|
);
|
2017-08-10 10:43:44 -04:00
|
|
|
throw (new Exception($arrayData));
|
2014-03-17 15:24:14 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2017-08-11 14:10:44 -04:00
|
|
|
$ws = new WsBase();
|
2015-04-15 12:49:47 -04:00
|
|
|
$fields = $ws->getCaseInfo($applicationUid, 0);
|
2014-03-20 17:05:04 -04:00
|
|
|
$array = json_decode(json_encode($fields), true);
|
2015-04-10 10:07:22 -04:00
|
|
|
|
2014-03-20 17:05:04 -04:00
|
|
|
if ($array ["status_code"] != 0) {
|
2017-08-10 10:43:44 -04:00
|
|
|
throw (new Exception($array ["message"]));
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
|
|
|
|
$array['app_uid'] = $array['caseId'];
|
|
|
|
|
$array['app_number'] = $array['caseNumber'];
|
|
|
|
|
$array['app_name'] = $array['caseName'];
|
2015-04-15 12:49:47 -04:00
|
|
|
$array["app_status"] = $array["caseStatus"];
|
2014-03-20 17:05:04 -04:00
|
|
|
$array['app_init_usr_uid'] = $array['caseCreatorUser'];
|
2014-04-08 12:50:16 -04:00
|
|
|
$array['app_init_usr_username'] = trim($array['caseCreatorUserName']);
|
2014-03-20 17:05:04 -04:00
|
|
|
$array['pro_uid'] = $array['processId'];
|
|
|
|
|
$array['pro_name'] = $array['processName'];
|
|
|
|
|
$array['app_create_date'] = $array['createDate'];
|
|
|
|
|
$array['app_update_date'] = $array['updateDate'];
|
|
|
|
|
$array['current_task'] = $array['currentUsers'];
|
2015-04-10 10:07:22 -04:00
|
|
|
|
|
|
|
|
$aCurrent_task = array();
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
for ($i = 0; $i <= count($array['current_task']) - 1; $i++) {
|
2014-03-20 17:05:04 -04:00
|
|
|
$current_task = $array['current_task'][$i];
|
|
|
|
|
$current_task['usr_uid'] = $current_task['userId'];
|
2014-03-21 16:40:02 -04:00
|
|
|
$current_task['usr_name'] = trim($current_task['userName']);
|
2014-03-20 17:05:04 -04:00
|
|
|
$current_task['tas_uid'] = $current_task['taskId'];
|
|
|
|
|
$current_task['tas_title'] = $current_task['taskName'];
|
|
|
|
|
$current_task['del_index'] = $current_task['delIndex'];
|
|
|
|
|
$current_task['del_thread'] = $current_task['delThread'];
|
|
|
|
|
$current_task['del_thread_status'] = $current_task['delThreadStatus'];
|
2015-04-09 16:10:00 -04:00
|
|
|
$current_task["del_init_date"] = $current_task["delInitDate"] . "";
|
|
|
|
|
$current_task["del_task_due_date"] = $current_task["delTaskDueDate"];
|
2014-03-20 17:05:04 -04:00
|
|
|
unset($current_task['userId']);
|
|
|
|
|
unset($current_task['userName']);
|
|
|
|
|
unset($current_task['taskId']);
|
|
|
|
|
unset($current_task['taskName']);
|
|
|
|
|
unset($current_task['delIndex']);
|
|
|
|
|
unset($current_task['delThread']);
|
|
|
|
|
unset($current_task['delThreadStatus']);
|
|
|
|
|
$aCurrent_task[] = $current_task;
|
|
|
|
|
}
|
|
|
|
|
unset($array['status_code']);
|
|
|
|
|
unset($array['message']);
|
|
|
|
|
unset($array['timestamp']);
|
|
|
|
|
unset($array['caseParalell']);
|
|
|
|
|
unset($array['caseId']);
|
|
|
|
|
unset($array['caseNumber']);
|
|
|
|
|
unset($array['caseName']);
|
|
|
|
|
unset($array['caseStatus']);
|
|
|
|
|
unset($array['caseCreatorUser']);
|
|
|
|
|
unset($array['caseCreatorUserName']);
|
|
|
|
|
unset($array['processId']);
|
|
|
|
|
unset($array['processName']);
|
|
|
|
|
unset($array['createDate']);
|
|
|
|
|
unset($array['updateDate']);
|
|
|
|
|
unset($array['currentUsers']);
|
|
|
|
|
}
|
|
|
|
|
$current_task = json_decode(json_encode($aCurrent_task), false);
|
|
|
|
|
$oResponse = json_decode(json_encode($array), false);
|
|
|
|
|
$oResponse->current_task = $current_task;
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-17 17:06:59 -04:00
|
|
|
//Return
|
2014-03-20 17:05:04 -04:00
|
|
|
return $oResponse;
|
2014-03-17 15:24:14 -04:00
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2017-12-08 18:28:16 +00:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data of a sub-process case
|
|
|
|
|
*
|
|
|
|
|
* @param string $applicationUid Unique Case Id
|
|
|
|
|
* @param string $userUid Unique User Id
|
|
|
|
|
*
|
|
|
|
|
* @return array Return an array with information of Cases
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function getCaseInfoSubProcess($applicationUid, $userUid)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$response = [];
|
|
|
|
|
$subApplication = new SubApplication();
|
|
|
|
|
$data = $subApplication->loadByAppUidParent($applicationUid);
|
2022-03-25 16:11:30 -04:00
|
|
|
if (!empty($data)) {
|
|
|
|
|
foreach ($data as $item) {
|
|
|
|
|
$response[] = $this->getCaseInfo($item['APP_UID'], $userUid);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_DOES_NOT_EXIST", [$applicationUid]));
|
2017-12-08 18:28:16 +00:00
|
|
|
}
|
2022-03-25 16:11:30 -04:00
|
|
|
|
2017-12-08 18:28:16 +00:00
|
|
|
return $response;
|
|
|
|
|
} catch (Exception $e) {
|
2014-03-17 15:24:14 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data Task Case
|
|
|
|
|
*
|
2014-03-20 17:05:04 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param string $userUid Unique id of User
|
2014-03-17 15:24:14 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array, an array with Task Case
|
|
|
|
|
* @throws Exception
|
2014-03-17 15:24:14 -04:00
|
|
|
*/
|
2014-03-20 17:05:04 -04:00
|
|
|
public function getTaskCase($applicationUid, $userUid)
|
2014-03-17 15:24:14 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2015-03-24 10:36:48 -04:00
|
|
|
//Verify data
|
2015-09-25 19:25:47 -04:00
|
|
|
$this->throwExceptionIfNotExistsCase($applicationUid, 0, $this->getFieldNameByFormatFieldName("APP_UID"));
|
2015-03-24 10:36:48 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria = new Criteria("workflow");
|
2015-03-24 10:36:48 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->addSelectColumn(ApplicationPeer::APP_UID);
|
2015-03-24 10:36:48 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->add(ApplicationPeer::APP_UID, $applicationUid, Criteria::EQUAL);
|
|
|
|
|
$criteria->add(ApplicationPeer::APP_STATUS, "COMPLETED", Criteria::EQUAL);
|
2015-03-24 10:36:48 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$rsCriteria = ApplicationPeer::doSelectRS($criteria);
|
2015-03-24 10:36:48 -04:00
|
|
|
|
|
|
|
|
if ($rsCriteria->next()) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_NO_CURRENT_TASKS_BECAUSE_CASE_ITS_COMPLETED",
|
|
|
|
|
array($this->getFieldNameByFormatFieldName("APP_UID"), $applicationUid)));
|
2015-03-24 10:36:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Get data
|
|
|
|
|
$result = array();
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$del = DBAdapter::getStringDelimiter();
|
|
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
|
|
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
|
|
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
|
|
|
|
|
$oCriteria->addSelectColumn(TaskPeer::TAS_TITLE);
|
|
|
|
|
$oCriteria->addJoin(AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::APP_UID, $applicationUid);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::USR_UID, $userUid);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN');
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
|
|
|
|
|
$oDataset = AppDelegationPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$result = array(
|
|
|
|
|
'tas_uid' => $aRow['TAS_UID'],
|
|
|
|
|
'tas_title' => $aRow['TAS_TITLE'],
|
|
|
|
|
'del_index' => $aRow['DEL_INDEX'],
|
|
|
|
|
"del_init_date" => $aRow["DEL_INIT_DATE"] . "",
|
|
|
|
|
"del_task_due_date" => $aRow["DEL_TASK_DUE_DATE"]
|
|
|
|
|
);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
2014-03-17 15:24:14 -04:00
|
|
|
//Return
|
2014-04-22 11:11:03 -04:00
|
|
|
if (empty($result)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASES_INCORRECT_INFORMATION", array($applicationUid)));
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-03-17 15:24:14 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add New Case
|
|
|
|
|
*
|
2014-03-20 17:05:04 -04:00
|
|
|
* @param string $processUid Unique id of Project
|
|
|
|
|
* @param string $taskUid Unique id of Activity (task)
|
|
|
|
|
* @param string $userUid Unique id of Case
|
2014-03-17 15:24:14 -04:00
|
|
|
* @param array $variables
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return object
|
|
|
|
|
* @throws Exception
|
2014-03-17 15:24:14 -04:00
|
|
|
*/
|
2014-03-20 17:05:04 -04:00
|
|
|
public function addCase($processUid, $taskUid, $userUid, $variables)
|
2014-03-17 15:24:14 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-08-11 14:10:44 -04:00
|
|
|
$ws = new WsBase();
|
2014-03-17 15:24:14 -04:00
|
|
|
if ($variables) {
|
|
|
|
|
$variables = array_shift($variables);
|
|
|
|
|
}
|
2014-05-22 09:12:35 -04:00
|
|
|
Validator::proUid($processUid, '$pro_uid');
|
2017-10-05 14:54:41 -04:00
|
|
|
$oTask = new ModelTask();
|
|
|
|
|
if (!$oTask->taskExists($taskUid)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_FOR", array('tas_uid')));
|
2014-04-08 12:50:16 -04:00
|
|
|
}
|
2014-03-20 17:05:04 -04:00
|
|
|
$fields = $ws->newCase($processUid, $userUid, $taskUid, $variables);
|
|
|
|
|
$array = json_decode(json_encode($fields), true);
|
|
|
|
|
if ($array ["status_code"] != 0) {
|
2017-08-10 10:43:44 -04:00
|
|
|
throw (new Exception($array ["message"]));
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
|
|
|
|
$array['app_uid'] = $array['caseId'];
|
|
|
|
|
$array['app_number'] = $array['caseNumber'];
|
|
|
|
|
unset($array['status_code']);
|
|
|
|
|
unset($array['message']);
|
|
|
|
|
unset($array['timestamp']);
|
|
|
|
|
unset($array['caseId']);
|
|
|
|
|
unset($array['caseNumber']);
|
|
|
|
|
}
|
|
|
|
|
$oResponse = json_decode(json_encode($array), false);
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-17 15:24:14 -04:00
|
|
|
//Return
|
2014-03-20 17:05:04 -04:00
|
|
|
return $oResponse;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-03-17 15:24:14 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add New Case Impersonate
|
|
|
|
|
*
|
2014-03-20 17:05:04 -04:00
|
|
|
* @param string $processUid Unique id of Project
|
|
|
|
|
* @param string $userUid Unique id of User
|
|
|
|
|
* @param string $taskUid Unique id of Case
|
2014-03-17 15:24:14 -04:00
|
|
|
* @param array $variables
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return object
|
|
|
|
|
* @throws Exception
|
2014-03-17 15:24:14 -04:00
|
|
|
*/
|
2014-03-20 17:05:04 -04:00
|
|
|
public function addCaseImpersonate($processUid, $userUid, $taskUid, $variables)
|
2014-03-17 15:24:14 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-08-11 14:10:44 -04:00
|
|
|
$ws = new WsBase();
|
2014-03-17 17:06:59 -04:00
|
|
|
if ($variables) {
|
|
|
|
|
$variables = array_shift($variables);
|
2014-03-24 11:03:23 -04:00
|
|
|
} elseif ($variables == null) {
|
|
|
|
|
$variables = array(array());
|
2014-03-17 17:06:59 -04:00
|
|
|
}
|
2014-05-22 09:12:35 -04:00
|
|
|
Validator::proUid($processUid, '$pro_uid');
|
2017-10-05 14:54:41 -04:00
|
|
|
$user = new ModelUsers();
|
|
|
|
|
if (!$user->userExists($userUid)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_FOR", array('usr_uid')));
|
2014-04-08 12:50:16 -04:00
|
|
|
}
|
2014-03-20 17:05:04 -04:00
|
|
|
$fields = $ws->newCaseImpersonate($processUid, $userUid, $variables, $taskUid);
|
|
|
|
|
$array = json_decode(json_encode($fields), true);
|
|
|
|
|
if ($array ["status_code"] != 0) {
|
2014-04-16 13:04:58 -04:00
|
|
|
if ($array ["status_code"] == 12) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw (new Exception(G::loadTranslation('ID_NO_STARTING_TASK') . '. tas_uid.'));
|
2014-04-16 13:04:58 -04:00
|
|
|
} elseif ($array ["status_code"] == 13) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw (new Exception(G::loadTranslation('ID_MULTIPLE_STARTING_TASKS') . '. tas_uid.'));
|
2014-04-16 13:04:58 -04:00
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
throw (new Exception($array ["message"]));
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
|
|
|
|
$array['app_uid'] = $array['caseId'];
|
|
|
|
|
$array['app_number'] = $array['caseNumber'];
|
|
|
|
|
unset($array['status_code']);
|
|
|
|
|
unset($array['message']);
|
|
|
|
|
unset($array['timestamp']);
|
|
|
|
|
unset($array['caseId']);
|
|
|
|
|
unset($array['caseNumber']);
|
|
|
|
|
}
|
|
|
|
|
$oResponse = json_decode(json_encode($array), false);
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-17 15:24:14 -04:00
|
|
|
//Return
|
2014-03-20 17:05:04 -04:00
|
|
|
return $oResponse;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-03-17 15:24:14 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 13:19:55 -04:00
|
|
|
/**
|
|
|
|
|
* This function check if some user has participation over the case
|
|
|
|
|
*
|
|
|
|
|
* @param string $usrUid
|
|
|
|
|
* @param int $caseNumber
|
|
|
|
|
* @param int $index
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function participation($usrUid, $caseNumber, $index)
|
|
|
|
|
{
|
|
|
|
|
$userId = User::getId($usrUid);
|
2021-08-23 15:19:23 -04:00
|
|
|
$query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->openAndPause();
|
2021-07-19 13:19:55 -04:00
|
|
|
$query1 = clone $query;
|
|
|
|
|
$result = $query->userId($userId)->limit(1)->get()->values()->toArray();
|
|
|
|
|
$permission = empty($result) ? false : true;
|
|
|
|
|
// Review if the user is supervisor
|
|
|
|
|
if (empty($result)) {
|
|
|
|
|
$processes = ProcessUser::getProcessesOfSupervisor($usrUid);
|
|
|
|
|
$query1->processInList($processes);
|
|
|
|
|
$result = $query1->get()->values()->toArray();
|
|
|
|
|
$permission = empty($result) ? false : true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $permission;
|
|
|
|
|
}
|
2014-03-17 15:24:14 -04:00
|
|
|
|
2022-11-07 09:56:49 -04:00
|
|
|
/**
|
|
|
|
|
* Review if the user is supervisor
|
|
|
|
|
*
|
|
|
|
|
* @param string $usrUid
|
|
|
|
|
* @param int $caseNumber
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isSupervisor(string $usrUid, int $caseNumber)
|
|
|
|
|
{
|
|
|
|
|
$result = [];
|
|
|
|
|
$user = new BmUser();
|
|
|
|
|
if ($user->checkPermission($usrUid, 'PM_SUPERVISOR')) {
|
|
|
|
|
$processes = ProcessUser::getProcessesOfSupervisor($usrUid);
|
|
|
|
|
$query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->processInList($processes);
|
|
|
|
|
$result = $query->get()->values()->toArray();
|
|
|
|
|
}
|
|
|
|
|
return !empty($result);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 15:24:14 -04:00
|
|
|
/**
|
|
|
|
|
* Reassign Case
|
|
|
|
|
*
|
2021-07-19 13:19:55 -04:00
|
|
|
* @param string $appUid Unique id of Case
|
|
|
|
|
* @param string $usrUid Unique id of User
|
|
|
|
|
* @param int $delIndex
|
|
|
|
|
* @param string $userSource Unique id of User Source
|
|
|
|
|
* @param string $userTarget $userUidTarget id of User Target
|
|
|
|
|
* @param string $reason
|
|
|
|
|
* @param boolean $sendMail
|
2014-03-17 15:24:14 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-17 15:24:14 -04:00
|
|
|
*/
|
2021-07-19 13:19:55 -04:00
|
|
|
public function updateReassignCase($appUid, $usrUid, $delIndex, $userSource, $userTarget, $reason = '', $sendMail = false)
|
2014-03-17 15:24:14 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-03-18 17:05:30 -04:00
|
|
|
if (!$delIndex) {
|
2021-07-19 13:19:55 -04:00
|
|
|
$delIndex = AppDelegation::getCurrentIndex($appUid);
|
2014-03-18 17:05:30 -04:00
|
|
|
}
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
/** Reassign case */
|
2017-08-11 14:10:44 -04:00
|
|
|
$ws = new WsBase();
|
2021-07-19 13:19:55 -04:00
|
|
|
$result = $ws->reassignCase($usrUid, $appUid, $delIndex, $userSource, $userTarget);
|
|
|
|
|
$result = (object)$result;
|
|
|
|
|
if (isset($result->status_code)) {
|
|
|
|
|
if ($result->status_code !== 0) {
|
|
|
|
|
throw new Exception($result->message);
|
2014-04-07 14:27:09 -04:00
|
|
|
}
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
2021-07-19 13:19:55 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASES_INCORRECT_INFORMATION", [$appUid]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Add the note */
|
|
|
|
|
if (!empty($reason)) {
|
|
|
|
|
$noteContent = $reason;
|
|
|
|
|
// Define the Case for register a case note
|
|
|
|
|
$cases = new BmCases();
|
|
|
|
|
$response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail);
|
2014-03-20 17:05:04 -04:00
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-03-17 15:24:14 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 12:31:36 -04:00
|
|
|
/**
|
|
|
|
|
* Put cancel case
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2018-05-30 09:19:46 -04:00
|
|
|
* @param string $appUid, Uid for case
|
|
|
|
|
* @param string $usrUid, Uid for user
|
2021-05-12 18:59:01 -04:00
|
|
|
* @param interger $delIndex
|
2014-03-18 12:31:36 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-18 12:31:36 -04:00
|
|
|
*/
|
2021-05-12 18:59:01 -04:00
|
|
|
public function putCancelCase($appUid, $usrUid, $delIndex = null, $reason = '', $sendMail = false)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2018-05-30 09:19:46 -04:00
|
|
|
Validator::isString($appUid, '$app_uid');
|
|
|
|
|
Validator::appUid($appUid, '$app_uid');
|
|
|
|
|
Validator::isString($usrUid, '$usr_uid');
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
2014-03-18 12:31:36 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2018-05-30 09:19:46 -04:00
|
|
|
$fields = $case->loadCase($appUid);
|
|
|
|
|
$supervisor = new BmProcessSupervisor();
|
|
|
|
|
$isSupervisor = $supervisor->isUserProcessSupervisor($fields['PRO_UID'], $usrUid);
|
2015-08-24 17:24:52 -04:00
|
|
|
|
2021-05-12 18:59:01 -04:00
|
|
|
if (is_null($delIndex)) {
|
2018-05-30 09:19:46 -04:00
|
|
|
$u = new ModelUsers();
|
|
|
|
|
$usrId = $u->load($usrUid)['USR_ID'];
|
2015-09-01 17:14:01 -04:00
|
|
|
|
2018-05-30 09:19:46 -04:00
|
|
|
if ($isSupervisor) {
|
|
|
|
|
//Get the last index open
|
|
|
|
|
$delIndex = AppDelegation::getLastIndexByStatus($fields['APP_NUMBER']);
|
|
|
|
|
} else {
|
|
|
|
|
//Get the last index open related to the user
|
|
|
|
|
$delIndex = AppDelegation::getLastIndexByUserAndStatus($fields['APP_NUMBER'], $usrId);
|
|
|
|
|
}
|
2015-08-24 17:24:52 -04:00
|
|
|
|
2018-05-30 09:19:46 -04:00
|
|
|
//We will to validate when the case is TO_DO and the user does not have a index OPEN
|
|
|
|
|
//The scenarios with COMPLETED, CANCELLED and DRAFT is considered in the WsBase::cancelCase
|
|
|
|
|
if ($fields['APP_STATUS'] === 'TO_DO' && $delIndex === 0) {
|
|
|
|
|
throw (new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_CANCEL_CASE", [$usrUid])));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Validator::isInteger($delIndex, '$del_index');
|
|
|
|
|
|
|
|
|
|
/** Cancel case */
|
|
|
|
|
$ws = new WsBase();
|
|
|
|
|
$result = $ws->cancelCase($appUid, $delIndex, $usrUid);
|
|
|
|
|
$result = (object)$result;
|
|
|
|
|
if ($result->status_code !== 0) {
|
|
|
|
|
throw new Exception($result->message);
|
2015-08-24 17:24:52 -04:00
|
|
|
}
|
2021-05-12 18:59:01 -04:00
|
|
|
/** Add the note */
|
|
|
|
|
if (!empty($reason)) {
|
|
|
|
|
$noteContent = $reason;
|
|
|
|
|
// Define the Case for register a case note
|
|
|
|
|
$cases = new BmCases();
|
|
|
|
|
$response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail);
|
|
|
|
|
}
|
2014-03-18 12:31:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Put pause case
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2021-07-19 13:19:55 -04:00
|
|
|
* @param string $appUid , Uid for case
|
|
|
|
|
* @param string $usrUid , Uid for user
|
|
|
|
|
* @param bool|string $index
|
|
|
|
|
* @param null|string $date , Date for unpaused
|
|
|
|
|
* @param string $time , Time for unpaused
|
|
|
|
|
* @param string $reason
|
|
|
|
|
* @param bool $sendMail
|
2014-03-18 12:31:36 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-18 12:31:36 -04:00
|
|
|
*/
|
2021-07-19 13:19:55 -04:00
|
|
|
public function putPauseCase($appUid, $usrUid, $index = 0, $date = null, $time = '00:00', $reason = '', $sendMail = false)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2021-07-19 13:19:55 -04:00
|
|
|
Validator::isString($appUid, '$app_uid');
|
|
|
|
|
Validator::isString($usrUid, '$usr_uid');
|
|
|
|
|
Validator::appUid($appUid, '$app_uid');
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
|
|
|
|
Validator::isInteger($index, '$del_index');
|
|
|
|
|
// Get the last index
|
|
|
|
|
if ($index === 0) {
|
|
|
|
|
$index = AppDelegation::getCurrentIndex($appUid);
|
2015-08-19 10:27:47 -04:00
|
|
|
}
|
2021-07-19 13:19:55 -04:00
|
|
|
// Get the case status
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2021-07-19 13:19:55 -04:00
|
|
|
$fields = $case->loadCase($appUid);
|
|
|
|
|
$caseNumber = $fields['APP_NUMBER'];
|
2014-05-13 16:32:10 -04:00
|
|
|
if ($fields['APP_STATUS'] == 'CANCELLED') {
|
2021-07-19 13:19:55 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_IS_CANCELED", [$appUid]));
|
2014-05-13 16:32:10 -04:00
|
|
|
}
|
2021-07-19 13:19:55 -04:00
|
|
|
// Check if the case was not paused
|
|
|
|
|
$delay = new AppDelay();
|
|
|
|
|
if ($delay->isPaused($appUid, $index)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_PAUSED", [$appUid]));
|
2014-03-18 12:31:36 -04:00
|
|
|
}
|
2021-07-19 13:19:55 -04:00
|
|
|
// Review if the user has participation or is supervisor
|
|
|
|
|
$permission = $this->participation($usrUid, $caseNumber, $index);
|
|
|
|
|
if (!$permission) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_PAUSED_CASE", [$usrUid]));
|
2015-08-19 10:27:47 -04:00
|
|
|
}
|
2014-03-25 16:22:28 -04:00
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
if ($date != null) {
|
|
|
|
|
Validator::isDate($date, 'Y-m-d', '$unpaused_date');
|
2014-03-25 16:22:28 -04:00
|
|
|
}
|
2014-03-18 12:31:36 -04:00
|
|
|
|
2021-07-26 13:13:26 -04:00
|
|
|
// Check if the case is unassigned
|
2021-08-23 10:26:42 -04:00
|
|
|
$classCases = new ClassesCases();
|
|
|
|
|
if ($classCases->isUnassignedPauseCase($appUid, $index)) {
|
2021-07-26 13:13:26 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", [G::LoadTranslation("ID_UNASSIGNED_STATUS")]));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
/** Pause case */
|
|
|
|
|
$case->pauseCase($appUid, $index, $usrUid, $date . ' ' . $time);
|
|
|
|
|
|
|
|
|
|
/** Add the note */
|
|
|
|
|
if (!empty($reason)) {
|
|
|
|
|
$noteContent = $reason;
|
|
|
|
|
// Define the Case for register a case note
|
|
|
|
|
$cases = new BmCases();
|
|
|
|
|
$response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail);
|
|
|
|
|
}
|
2014-03-18 12:31:36 -04:00
|
|
|
}
|
2014-03-18 14:37:47 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Put unpause case
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
* @param string $app_uid , Uid for case
|
|
|
|
|
* @param string $usr_uid , Uid for user
|
2021-08-26 09:42:26 -04:00
|
|
|
* @param int $del_index
|
2014-03-18 14:37:47 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-18 14:37:47 -04:00
|
|
|
*/
|
2021-08-26 09:42:26 -04:00
|
|
|
public function putUnpauseCase($appUid, $usrUid, $index = 0)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2021-07-19 13:19:55 -04:00
|
|
|
Validator::isString($appUid, '$app_uid');
|
|
|
|
|
Validator::isString($usrUid, '$usr_uid');
|
|
|
|
|
Validator::appUid($appUid, '$app_uid');
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
2014-03-18 14:37:47 -04:00
|
|
|
|
2021-08-26 09:42:26 -04:00
|
|
|
if ($index === 0) {
|
2021-07-19 13:19:55 -04:00
|
|
|
$index = AppDelegation::getCurrentIndex($appUid);
|
2014-03-18 14:37:47 -04:00
|
|
|
}
|
2021-07-19 13:19:55 -04:00
|
|
|
Validator::isInteger($index, '$del_index');
|
2015-04-08 16:13:24 -04:00
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
$delay = new AppDelay();
|
|
|
|
|
if (!$delay->isPaused($appUid, $index)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", [$appUid]));
|
2015-04-08 16:13:24 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
// Review if the user has participation or is supervisor
|
|
|
|
|
$caseNumber = ModelApplication::getCaseNumber($appUid);
|
|
|
|
|
$permission = $this->participation($usrUid, $caseNumber, $index);
|
|
|
|
|
if (!$permission) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_UNPAUSE_CASE", [$usrUid]));
|
2015-08-19 10:27:47 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
/** Unpause case */
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2021-07-19 13:19:55 -04:00
|
|
|
$case->unpauseCase($appUid, $index, $usrUid);
|
2014-03-18 14:37:47 -04:00
|
|
|
}
|
|
|
|
|
|
2021-05-12 18:59:01 -04:00
|
|
|
/**
|
|
|
|
|
* Put claim case
|
|
|
|
|
*
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param integer $index
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
|
|
|
|
public function putClaimCase($appUid, $index, $userUid)
|
|
|
|
|
{
|
|
|
|
|
// Validate the parameters
|
|
|
|
|
Validator::isString($appUid, '$appUid');
|
|
|
|
|
Validator::isString($userUid, '$userUid');
|
|
|
|
|
Validator::isInteger($index, '$index');
|
|
|
|
|
Validator::appUid($appUid, '$appUid');
|
|
|
|
|
Validator::usrUid($userUid, '$userUid');
|
|
|
|
|
|
|
|
|
|
// Review if the user can claim the case
|
|
|
|
|
$appDelegation = new AppDelegation();
|
|
|
|
|
$delegation = $appDelegation->load($appUid, $index);
|
|
|
|
|
if (empty($delegation['USR_UID'])) {
|
|
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$case->loadCase($appUid);
|
2021-11-09 11:08:01 -04:00
|
|
|
|
|
|
|
|
//Review if the user can be claim the case
|
|
|
|
|
if (!$case->isSelfService($userUid, $delegation['TAS_UID'], $appUid)) {
|
|
|
|
|
$message = preg_replace("#<br\s*/?>#i", "", G::LoadTranslation("ID_NO_PERMISSION_NO_PARTICIPATED"));
|
|
|
|
|
throw new Exception($message);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 18:59:01 -04:00
|
|
|
$case->setCatchUser($appUid, $index, $userUid);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_CLAIM_CASE", [$userUid]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 14:37:47 -04:00
|
|
|
/**
|
|
|
|
|
* Put execute trigger case
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $appUid , Uid for case
|
|
|
|
|
* @param string $triUid , Uid for trigger
|
|
|
|
|
* @param string $userUid , Uid for user
|
2018-01-04 09:58:45 -04:00
|
|
|
* @param bool|string $delIndex
|
2014-03-18 14:37:47 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
2017-08-10 10:43:44 -04:00
|
|
|
* @throws Exception
|
2014-03-18 14:37:47 -04:00
|
|
|
*/
|
2017-08-10 10:43:44 -04:00
|
|
|
public function putExecuteTriggerCase($appUid, $triUid, $userUid, $delIndex = false)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2017-08-10 10:43:44 -04:00
|
|
|
Validator::isString($appUid, '$appUid');
|
|
|
|
|
Validator::isString($triUid, '$triUid');
|
|
|
|
|
Validator::isString($userUid, '$userUid');
|
2014-03-25 16:22:28 -04:00
|
|
|
|
2017-08-10 10:43:44 -04:00
|
|
|
Validator::appUid($appUid, '$appUid');
|
|
|
|
|
Validator::triUid($triUid, '$triUid');
|
|
|
|
|
Validator::usrUid($userUid, '$userUid');
|
2014-03-18 14:37:47 -04:00
|
|
|
|
2017-08-10 10:43:44 -04:00
|
|
|
if ($delIndex === false) {
|
|
|
|
|
//We need to find the last delIndex open related to the user $usr_uid
|
|
|
|
|
$delIndex = (integer)$this->getLastParticipatedByUser($appUid, $userUid, 'OPEN');
|
|
|
|
|
//If the is assigned another user the function will be return 0
|
|
|
|
|
if ($delIndex === 0) {
|
|
|
|
|
throw new Exception(G::loadTranslation('ID_CASE_ASSIGNED_ANOTHER_USER'));
|
|
|
|
|
}
|
2014-03-18 14:37:47 -04:00
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
Validator::isInteger($delIndex, '$del_index');
|
2014-03-18 14:37:47 -04:00
|
|
|
|
2015-06-29 14:44:04 -04:00
|
|
|
global $RBAC;
|
|
|
|
|
if (!method_exists($RBAC, 'initRBAC')) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
2015-06-29 14:44:04 -04:00
|
|
|
$RBAC->sSystem = 'PROCESSMAKER';
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-11 14:10:44 -04:00
|
|
|
$case = new WsBase();
|
2017-08-10 10:43:44 -04:00
|
|
|
$result = $case->executeTrigger($userUid, $appUid, $triUid, $delIndex);
|
2015-09-15 10:40:56 -04:00
|
|
|
|
|
|
|
|
if ($result->status_code != 0) {
|
2017-08-10 10:43:44 -04:00
|
|
|
throw new Exception($result->message);
|
2015-09-15 10:40:56 -04:00
|
|
|
}
|
2014-03-18 14:37:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete case
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2020-01-06 14:30:41 -04:00
|
|
|
* @param string $appUid, Uid for case
|
|
|
|
|
* @param string $usrUid, Uid user
|
2014-03-18 14:37:47 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-18 14:37:47 -04:00
|
|
|
*/
|
2020-01-06 14:30:41 -04:00
|
|
|
public function deleteCase($appUid, $usrUid)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2020-01-06 14:30:41 -04:00
|
|
|
Validator::isString($appUid, '$app_uid');
|
|
|
|
|
Validator::appUid($appUid, '$app_uid');
|
2015-04-24 14:17:17 -04:00
|
|
|
|
2020-04-22 16:23:17 -04:00
|
|
|
// Review the status and owner
|
2020-01-06 14:30:41 -04:00
|
|
|
$caseInfo = ModelApplication::getCase($appUid);
|
2020-04-22 16:23:17 -04:00
|
|
|
if (!empty($caseInfo)) {
|
|
|
|
|
// Check if the requester is the owner
|
|
|
|
|
if ($caseInfo['APP_INIT_USER'] !== $usrUid) {
|
|
|
|
|
global $RBAC;
|
|
|
|
|
// If no we need to review if have the permission
|
|
|
|
|
if ($RBAC->userCanAccess('PM_DELETECASE') != 1) {
|
|
|
|
|
throw new Exception(G::LoadTranslation('ID_NOT_ABLE_DELETE_CASES'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 14:30:41 -04:00
|
|
|
// Review the status
|
|
|
|
|
if ($caseInfo['APP_STATUS'] != 'DRAFT') {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_DELETE_CASE_NO_STATUS"));
|
|
|
|
|
}
|
2015-04-24 14:17:17 -04:00
|
|
|
|
2020-04-22 16:23:17 -04:00
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$case->removeCase($appUid);
|
|
|
|
|
}
|
2014-03-18 14:37:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-03-18 17:05:30 -04:00
|
|
|
* Route Case
|
2014-03-17 17:06:59 -04:00
|
|
|
*
|
2014-03-20 17:05:04 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
2014-03-17 17:06:59 -04:00
|
|
|
* @param string $userUid Unique id of User
|
|
|
|
|
* @param string $delIndex
|
2017-12-21 14:23:51 -04:00
|
|
|
* @param boolean $executeTriggersBeforeAssignment
|
2014-03-17 17:06:59 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-17 17:06:59 -04:00
|
|
|
*/
|
2017-12-21 14:23:51 -04:00
|
|
|
public function updateRouteCase($applicationUid, $userUid, $delIndex, $executeTriggersBeforeAssignment)
|
2014-03-17 17:06:59 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-03-18 17:05:30 -04:00
|
|
|
if (!$delIndex) {
|
2017-08-10 10:43:44 -04:00
|
|
|
$delIndex = AppDelegation::getCurrentIndex($applicationUid);
|
2017-04-28 13:37:13 -04:00
|
|
|
//Check if the next task is a subprocess SYNCHRONOUS with a thread Open
|
2017-10-05 14:54:41 -04:00
|
|
|
$subAppData = new SubApplication();
|
2017-04-28 13:37:13 -04:00
|
|
|
$caseSubprocessPending = $subAppData->isSubProcessWithCasePending($applicationUid, $delIndex);
|
|
|
|
|
if ($caseSubprocessPending) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw (new Exception(G::LoadTranslation("ID_CASE_ALREADY_DERIVATED")));
|
2017-04-28 13:37:13 -04:00
|
|
|
}
|
2014-03-18 17:05:30 -04:00
|
|
|
}
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-08-11 14:10:44 -04:00
|
|
|
$ws = new WsBase();
|
2017-12-21 14:23:51 -04:00
|
|
|
$fields = $ws->derivateCase($userUid, $applicationUid, $delIndex, $executeTriggersBeforeAssignment);
|
2014-03-20 17:05:04 -04:00
|
|
|
$array = json_decode(json_encode($fields), true);
|
|
|
|
|
if ($array ["status_code"] != 0) {
|
2017-08-10 10:43:44 -04:00
|
|
|
throw (new Exception($array ["message"]));
|
2014-03-20 17:05:04 -04:00
|
|
|
} else {
|
|
|
|
|
unset($array['status_code']);
|
|
|
|
|
unset($array['message']);
|
|
|
|
|
unset($array['timestamp']);
|
|
|
|
|
}
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-03-17 17:06:59 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 11:59:28 -04:00
|
|
|
/**
|
|
|
|
|
* get all upload document that they have send it
|
|
|
|
|
*
|
|
|
|
|
* @param string $sProcessUID Unique id of Process
|
|
|
|
|
* @param string $sApplicationUID Unique id of Case
|
|
|
|
|
* @param string $sTasKUID Unique id of Activity
|
|
|
|
|
* @param string $sUserUID Unique id of User
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2014-03-18 11:59:28 -04:00
|
|
|
* @return object
|
2018-01-04 09:58:45 -04:00
|
|
|
* @throws Exception
|
2014-03-18 11:59:28 -04:00
|
|
|
*/
|
|
|
|
|
public function getAllUploadedDocumentsCriteria($sProcessUID, $sApplicationUID, $sTasKUID, $sUserUID)
|
|
|
|
|
{
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$conf = new Configurations();
|
2014-03-18 11:59:28 -04:00
|
|
|
$confEnvSetting = $conf->getFormats();
|
2016-11-11 12:34:54 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$cases = new ClassesCases();
|
2016-11-11 12:34:54 -04:00
|
|
|
|
2014-03-18 11:59:28 -04:00
|
|
|
$listing = false;
|
2017-08-01 12:16:06 -04:00
|
|
|
$oPluginRegistry = PluginRegistry::loadSingleton();
|
2014-03-18 11:59:28 -04:00
|
|
|
if ($oPluginRegistry->existsTrigger(PM_CASE_DOCUMENT_LIST)) {
|
|
|
|
|
$folderData = new \folderData(null, null, $sApplicationUID, null, $sUserUID);
|
|
|
|
|
$folderData->PMType = "INPUT";
|
|
|
|
|
$folderData->returnList = true;
|
|
|
|
|
$listing = $oPluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST, $folderData);
|
|
|
|
|
}
|
|
|
|
|
$aObjectPermissions = $cases->getAllObjects($sProcessUID, $sApplicationUID, $sTasKUID, $sUserUID);
|
|
|
|
|
if (!is_array($aObjectPermissions)) {
|
|
|
|
|
$aObjectPermissions = array(
|
|
|
|
|
'DYNAFORMS' => array(-1),
|
|
|
|
|
'INPUT_DOCUMENTS' => array(-1),
|
|
|
|
|
'OUTPUT_DOCUMENTS' => array(-1)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (!isset($aObjectPermissions['DYNAFORMS'])) {
|
|
|
|
|
$aObjectPermissions['DYNAFORMS'] = array(-1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_array($aObjectPermissions['DYNAFORMS'])) {
|
|
|
|
|
$aObjectPermissions['DYNAFORMS'] = array(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isset($aObjectPermissions['INPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['INPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_array($aObjectPermissions['INPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['INPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isset($aObjectPermissions['OUTPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['OUTPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_array($aObjectPermissions['OUTPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['OUTPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$aDelete = $cases->getAllObjectsFrom($sProcessUID, $sApplicationUID, $sTasKUID, $sUserUID, 'DELETE');
|
2017-10-05 14:54:41 -04:00
|
|
|
$oAppDocument = new AppDocument();
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, array('INPUT'), Criteria::IN);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_STATUS, array('ACTIVE'), Criteria::IN);
|
2014-03-18 11:59:28 -04:00
|
|
|
//$oCriteria->add(AppDocumentPeer::APP_DOC_UID, $aObjectPermissions['INPUT_DOCUMENTS'], Criteria::IN);
|
|
|
|
|
$oCriteria->add(
|
|
|
|
|
$oCriteria->getNewCriterion(
|
2017-10-05 14:54:41 -04:00
|
|
|
AppDocumentPeer::APP_DOC_UID, $aObjectPermissions['INPUT_DOCUMENTS'], Criteria::IN)->
|
|
|
|
|
addOr($oCriteria->getNewCriterion(AppDocumentPeer::USR_UID, array($sUserUID, '-1'), Criteria::IN))
|
2014-03-18 11:59:28 -04:00
|
|
|
);
|
|
|
|
|
$aConditions = array();
|
2017-10-05 14:54:41 -04:00
|
|
|
$aConditions[] = array(AppDocumentPeer::APP_UID, AppDelegationPeer::APP_UID);
|
|
|
|
|
$aConditions[] = array(AppDocumentPeer::DEL_INDEX, AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oCriteria->addJoinMC($aConditions, Criteria::LEFT_JOIN);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oCriteria->addAscendingOrderByColumn(AppDocumentPeer::APP_DOC_INDEX);
|
|
|
|
|
$oDataset = AppDocumentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
$aInputDocuments = array();
|
|
|
|
|
$aInputDocuments[] = array(
|
|
|
|
|
'APP_DOC_UID' => 'char',
|
|
|
|
|
'DOC_UID' => 'char',
|
|
|
|
|
'APP_DOC_COMMENT' => 'char',
|
2017-10-05 14:54:41 -04:00
|
|
|
'APP_DOC_FILENAME' => 'char',
|
|
|
|
|
'APP_DOC_INDEX' => 'integer'
|
2014-03-18 11:59:28 -04:00
|
|
|
);
|
2017-10-05 14:54:41 -04:00
|
|
|
$oUser = new ModelUsers();
|
2014-03-18 11:59:28 -04:00
|
|
|
while ($aRow = $oDataset->getRow()) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteria2 = new Criteria('workflow');
|
|
|
|
|
$oCriteria2->add(AppDelegationPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria2->add(AppDelegationPeer::DEL_INDEX, $aRow['DEL_INDEX']);
|
|
|
|
|
$oDataset2 = AppDelegationPeer::doSelectRS($oCriteria2);
|
|
|
|
|
$oDataset2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset2->next();
|
|
|
|
|
$aRow2 = $oDataset2->getRow();
|
2017-10-05 14:54:41 -04:00
|
|
|
$oTask = new ModelTask();
|
2014-03-18 11:59:28 -04:00
|
|
|
if ($oTask->taskExists($aRow2['TAS_UID'])) {
|
|
|
|
|
$aTask = $oTask->load($aRow2['TAS_UID']);
|
|
|
|
|
} else {
|
|
|
|
|
$aTask = array('TAS_TITLE' => '(TASK DELETED)');
|
|
|
|
|
}
|
|
|
|
|
$aAux = $oAppDocument->load($aRow['APP_DOC_UID'], $aRow['DOC_VERSION']);
|
|
|
|
|
$lastVersion = $oAppDocument->getLastAppDocVersion($aRow['APP_DOC_UID'], $sApplicationUID);
|
|
|
|
|
|
2016-02-01 11:37:35 -04:00
|
|
|
if ($aAux['USR_UID'] !== "-1") {
|
|
|
|
|
try {
|
|
|
|
|
$aAux1 = $oUser->load($aAux['USR_UID']);
|
2014-03-18 11:59:28 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$sUser = $conf->usersNameFormatBySetParameters($confEnvSetting["format"], $aAux1["USR_USERNAME"],
|
|
|
|
|
$aAux1["USR_FIRSTNAME"], $aAux1["USR_LASTNAME"]);
|
2016-02-01 11:37:35 -04:00
|
|
|
} catch (Exception $oException) {
|
|
|
|
|
$sUser = '***';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-03-18 11:59:28 -04:00
|
|
|
$sUser = '***';
|
|
|
|
|
}
|
|
|
|
|
$aFields = array(
|
|
|
|
|
'APP_DOC_UID' => $aAux['APP_DOC_UID'],
|
|
|
|
|
'DOC_UID' => $aAux['DOC_UID'],
|
|
|
|
|
'APP_DOC_COMMENT' => $aAux['APP_DOC_COMMENT'],
|
|
|
|
|
'APP_DOC_FILENAME' => $aAux['APP_DOC_FILENAME'],
|
|
|
|
|
'APP_DOC_INDEX' => $aAux['APP_DOC_INDEX'],
|
|
|
|
|
'TYPE' => $aAux['APP_DOC_TYPE'],
|
|
|
|
|
'ORIGIN' => $aTask['TAS_TITLE'],
|
|
|
|
|
'CREATE_DATE' => $aAux['APP_DOC_CREATE_DATE'],
|
|
|
|
|
'CREATED_BY' => $sUser
|
|
|
|
|
);
|
|
|
|
|
if ($aFields['APP_DOC_FILENAME'] != '') {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_FILENAME'];
|
|
|
|
|
} else {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_COMMENT'];
|
|
|
|
|
}
|
|
|
|
|
//$aFields['POSITION'] = $_SESSION['STEP_POSITION'];
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['CONFIRM'] = G::LoadTranslation('ID_CONFIRM_DELETE_ELEMENT');
|
2014-03-18 11:59:28 -04:00
|
|
|
if (in_array($aRow['APP_DOC_UID'], $aDelete['INPUT_DOCUMENTS'])) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['ID_DELETE'] = G::LoadTranslation('ID_DELETE');
|
2014-03-18 11:59:28 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_DOWNLOAD');
|
2015-11-11 08:44:19 -04:00
|
|
|
$aFields['DOWNLOAD_LINK'] = "cases/cases_ShowDocument?a=" . $aRow['APP_DOC_UID'] . "&v=" . $aRow['DOC_VERSION'];
|
2014-03-18 11:59:28 -04:00
|
|
|
$aFields['DOC_VERSION'] = $aRow['DOC_VERSION'];
|
|
|
|
|
if (is_array($listing)) {
|
|
|
|
|
foreach ($listing as $folderitem) {
|
|
|
|
|
if ($folderitem->filename == $aRow['APP_DOC_UID']) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_GET_EXTERNAL_FILE');
|
2014-03-18 11:59:28 -04:00
|
|
|
$aFields['DOWNLOAD_LINK'] = $folderitem->downloadScript;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($lastVersion == $aRow['DOC_VERSION']) {
|
|
|
|
|
//Show only last version
|
|
|
|
|
$aInputDocuments[] = $aFields;
|
|
|
|
|
}
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
$oAppDocument = new AppDocument();
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, array('ATTACHED'), Criteria::IN);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_STATUS, array('ACTIVE'), Criteria::IN);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oCriteria->add(
|
|
|
|
|
$oCriteria->getNewCriterion(
|
2017-10-05 14:54:41 -04:00
|
|
|
AppDocumentPeer::APP_DOC_UID, $aObjectPermissions['INPUT_DOCUMENTS'], Criteria::IN
|
2014-03-18 11:59:28 -04:00
|
|
|
)->
|
2017-10-05 14:54:41 -04:00
|
|
|
addOr($oCriteria->getNewCriterion(AppDocumentPeer::USR_UID, array($sUserUID, '-1'), Criteria::IN)));
|
2014-03-18 11:59:28 -04:00
|
|
|
$aConditions = array();
|
2017-10-05 14:54:41 -04:00
|
|
|
$aConditions[] = array(AppDocumentPeer::APP_UID, AppDelegationPeer::APP_UID);
|
|
|
|
|
$aConditions[] = array(AppDocumentPeer::DEL_INDEX, AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oCriteria->addJoinMC($aConditions, Criteria::LEFT_JOIN);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oCriteria->addAscendingOrderByColumn(AppDocumentPeer::APP_DOC_INDEX);
|
|
|
|
|
$oDataset = AppDocumentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
while ($aRow = $oDataset->getRow()) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteria2 = new Criteria('workflow');
|
|
|
|
|
$oCriteria2->add(AppDelegationPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria2->add(AppDelegationPeer::DEL_INDEX, $aRow['DEL_INDEX']);
|
|
|
|
|
$oDataset2 = AppDelegationPeer::doSelectRS($oCriteria2);
|
|
|
|
|
$oDataset2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset2->next();
|
|
|
|
|
$aRow2 = $oDataset2->getRow();
|
2017-10-05 14:54:41 -04:00
|
|
|
$oTask = new ModelTask();
|
2014-03-18 11:59:28 -04:00
|
|
|
if ($oTask->taskExists($aRow2['TAS_UID'])) {
|
|
|
|
|
$aTask = $oTask->load($aRow2['TAS_UID']);
|
|
|
|
|
} else {
|
|
|
|
|
$aTask = array('TAS_TITLE' => '(TASK DELETED)');
|
|
|
|
|
}
|
|
|
|
|
$aAux = $oAppDocument->load($aRow['APP_DOC_UID'], $aRow['DOC_VERSION']);
|
|
|
|
|
$lastVersion = $oAppDocument->getLastAppDocVersion($aRow['APP_DOC_UID'], $sApplicationUID);
|
|
|
|
|
try {
|
|
|
|
|
$aAux1 = $oUser->load($aAux['USR_UID']);
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$sUser = $conf->usersNameFormatBySetParameters($confEnvSetting["format"], $aAux1["USR_USERNAME"],
|
|
|
|
|
$aAux1["USR_FIRSTNAME"], $aAux1["USR_LASTNAME"]);
|
2014-03-18 11:59:28 -04:00
|
|
|
} catch (Exception $oException) {
|
|
|
|
|
$sUser = '***';
|
|
|
|
|
}
|
|
|
|
|
$aFields = array(
|
|
|
|
|
'APP_DOC_UID' => $aAux['APP_DOC_UID'],
|
|
|
|
|
'DOC_UID' => $aAux['DOC_UID'],
|
|
|
|
|
'APP_DOC_COMMENT' => $aAux['APP_DOC_COMMENT'],
|
|
|
|
|
'APP_DOC_FILENAME' => $aAux['APP_DOC_FILENAME'],
|
|
|
|
|
'APP_DOC_INDEX' => $aAux['APP_DOC_INDEX'],
|
|
|
|
|
'TYPE' => $aAux['APP_DOC_TYPE'],
|
|
|
|
|
'ORIGIN' => $aTask['TAS_TITLE'],
|
|
|
|
|
'CREATE_DATE' => $aAux['APP_DOC_CREATE_DATE'],
|
|
|
|
|
'CREATED_BY' => $sUser
|
|
|
|
|
);
|
|
|
|
|
if ($aFields['APP_DOC_FILENAME'] != '') {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_FILENAME'];
|
|
|
|
|
} else {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_COMMENT'];
|
|
|
|
|
}
|
|
|
|
|
//$aFields['POSITION'] = $_SESSION['STEP_POSITION'];
|
|
|
|
|
$aFields['CONFIRM'] = G::LoadTranslation('ID_CONFIRM_DELETE_ELEMENT');
|
|
|
|
|
if (in_array($aRow['APP_DOC_UID'], $aDelete['INPUT_DOCUMENTS'])) {
|
|
|
|
|
$aFields['ID_DELETE'] = G::LoadTranslation('ID_DELETE');
|
|
|
|
|
}
|
|
|
|
|
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_DOWNLOAD');
|
2015-11-11 08:44:19 -04:00
|
|
|
$aFields['DOWNLOAD_LINK'] = "cases/cases_ShowDocument?a=" . $aRow['APP_DOC_UID'];
|
2016-01-08 14:53:11 -04:00
|
|
|
|
2014-03-18 11:59:28 -04:00
|
|
|
if ($lastVersion == $aRow['DOC_VERSION']) {
|
|
|
|
|
//Show only last version
|
|
|
|
|
$aInputDocuments[] = $aFields;
|
|
|
|
|
}
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
// Get input documents added/modified by a supervisor - Begin
|
2017-10-05 14:54:41 -04:00
|
|
|
$oAppDocument = new AppDocument();
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, array('INPUT'), Criteria::IN);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_STATUS, array('ACTIVE'), Criteria::IN);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::DEL_INDEX, 100000);
|
|
|
|
|
$oCriteria->addJoin(AppDocumentPeer::APP_UID, ApplicationPeer::APP_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$oCriteria->add(ApplicationPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oCriteria->addAscendingOrderByColumn(AppDocumentPeer::APP_DOC_INDEX);
|
|
|
|
|
$oDataset = AppDocumentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-18 11:59:28 -04:00
|
|
|
$oDataset->next();
|
2017-10-05 14:54:41 -04:00
|
|
|
$oUser = new ModelUsers();
|
2014-03-18 11:59:28 -04:00
|
|
|
while ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$aTask = array('TAS_TITLE' => '[ ' . G::LoadTranslation('ID_SUPERVISOR') . ' ]');
|
|
|
|
|
$aAux = $oAppDocument->load($aRow['APP_DOC_UID'], $aRow['DOC_VERSION']);
|
|
|
|
|
$lastVersion = $oAppDocument->getLastAppDocVersion($aRow['APP_DOC_UID'], $sApplicationUID);
|
|
|
|
|
try {
|
|
|
|
|
$aAux1 = $oUser->load($aAux['USR_UID']);
|
2017-10-05 14:54:41 -04:00
|
|
|
$sUser = $conf->usersNameFormatBySetParameters($confEnvSetting["format"], $aAux1["USR_USERNAME"],
|
|
|
|
|
$aAux1["USR_FIRSTNAME"], $aAux1["USR_LASTNAME"]);
|
2014-03-18 11:59:28 -04:00
|
|
|
} catch (Exception $oException) {
|
|
|
|
|
$sUser = '***';
|
|
|
|
|
}
|
|
|
|
|
$aFields = array(
|
|
|
|
|
'APP_DOC_UID' => $aAux['APP_DOC_UID'],
|
|
|
|
|
'DOC_UID' => $aAux['DOC_UID'],
|
|
|
|
|
'APP_DOC_COMMENT' => $aAux['APP_DOC_COMMENT'],
|
|
|
|
|
'APP_DOC_FILENAME' => $aAux['APP_DOC_FILENAME'],
|
|
|
|
|
'APP_DOC_INDEX' => $aAux['APP_DOC_INDEX'],
|
|
|
|
|
'TYPE' => $aAux['APP_DOC_TYPE'],
|
|
|
|
|
'ORIGIN' => $aTask['TAS_TITLE'],
|
|
|
|
|
'CREATE_DATE' => $aAux['APP_DOC_CREATE_DATE'],
|
|
|
|
|
'CREATED_BY' => $sUser
|
|
|
|
|
);
|
|
|
|
|
if ($aFields['APP_DOC_FILENAME'] != '') {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_FILENAME'];
|
|
|
|
|
} else {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_COMMENT'];
|
|
|
|
|
}
|
|
|
|
|
//$aFields['POSITION'] = $_SESSION['STEP_POSITION'];
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['CONFIRM'] = G::LoadTranslation('ID_CONFIRM_DELETE_ELEMENT');
|
2014-03-18 11:59:28 -04:00
|
|
|
if (in_array($aRow['APP_DOC_UID'], $aDelete['INPUT_DOCUMENTS'])) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['ID_DELETE'] = G::LoadTranslation('ID_DELETE');
|
2014-03-18 11:59:28 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_DOWNLOAD');
|
2014-03-18 11:59:28 -04:00
|
|
|
$aFields['DOWNLOAD_LINK'] = "cases_ShowDocument?a=" . $aRow['APP_DOC_UID'] . "&v=" . $aRow['DOC_VERSION'];
|
|
|
|
|
$aFields['DOC_VERSION'] = $aRow['DOC_VERSION'];
|
|
|
|
|
if (is_array($listing)) {
|
|
|
|
|
foreach ($listing as $folderitem) {
|
|
|
|
|
if ($folderitem->filename == $aRow['APP_DOC_UID']) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_GET_EXTERNAL_FILE');
|
2014-03-18 11:59:28 -04:00
|
|
|
$aFields['DOWNLOAD_LINK'] = $folderitem->downloadScript;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-08 14:53:11 -04:00
|
|
|
|
2014-03-18 11:59:28 -04:00
|
|
|
if ($lastVersion == $aRow['DOC_VERSION']) {
|
|
|
|
|
//Show only last version
|
|
|
|
|
$aInputDocuments[] = $aFields;
|
|
|
|
|
}
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
// Get input documents added/modified by a supervisor - End
|
|
|
|
|
global $_DBArray;
|
|
|
|
|
$_DBArray['inputDocuments'] = $aInputDocuments;
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteria = new Criteria('dbarray');
|
2014-03-18 11:59:28 -04:00
|
|
|
$oCriteria->setDBArrayTable('inputDocuments');
|
|
|
|
|
$oCriteria->addDescendingOrderByColumn('CREATE_DATE');
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-18 11:59:28 -04:00
|
|
|
return $oCriteria;
|
|
|
|
|
}
|
2014-03-24 16:59:03 -04:00
|
|
|
|
2018-01-04 09:58:45 -04:00
|
|
|
/**
|
2014-03-24 16:59:03 -04:00
|
|
|
* get all generate document
|
|
|
|
|
*
|
|
|
|
|
* @name getAllGeneratedDocumentsCriteria
|
|
|
|
|
* @param string $sProcessUID
|
|
|
|
|
* @param string $sApplicationUID
|
|
|
|
|
* @param string $sTasKUID
|
|
|
|
|
* @param string $sUserUID
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2014-03-24 16:59:03 -04:00
|
|
|
* @return object
|
2018-01-04 09:58:45 -04:00
|
|
|
* @throws Exception
|
2014-03-24 16:59:03 -04:00
|
|
|
*/
|
|
|
|
|
public function getAllGeneratedDocumentsCriteria($sProcessUID, $sApplicationUID, $sTasKUID, $sUserUID)
|
|
|
|
|
{
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$conf = new Configurations();
|
2014-03-24 16:59:03 -04:00
|
|
|
$confEnvSetting = $conf->getFormats();
|
2017-08-10 10:43:44 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$cases = new ClassesCases();
|
2016-11-11 12:34:54 -04:00
|
|
|
|
2014-03-24 16:59:03 -04:00
|
|
|
$listing = false;
|
2017-08-01 12:16:06 -04:00
|
|
|
$oPluginRegistry = PluginRegistry::loadSingleton();
|
2014-03-24 16:59:03 -04:00
|
|
|
if ($oPluginRegistry->existsTrigger(PM_CASE_DOCUMENT_LIST)) {
|
|
|
|
|
$folderData = new \folderData(null, null, $sApplicationUID, null, $sUserUID);
|
|
|
|
|
$folderData->PMType = "OUTPUT";
|
|
|
|
|
$folderData->returnList = true;
|
|
|
|
|
$listing = $oPluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST, $folderData);
|
|
|
|
|
}
|
|
|
|
|
$aObjectPermissions = $cases->getAllObjects($sProcessUID, $sApplicationUID, $sTasKUID, $sUserUID);
|
|
|
|
|
if (!is_array($aObjectPermissions)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$aObjectPermissions = array(
|
|
|
|
|
'DYNAFORMS' => array(-1),
|
|
|
|
|
'INPUT_DOCUMENTS' => array(-1),
|
|
|
|
|
'OUTPUT_DOCUMENTS' => array(-1)
|
|
|
|
|
);
|
2014-03-24 16:59:03 -04:00
|
|
|
}
|
|
|
|
|
if (!isset($aObjectPermissions['DYNAFORMS'])) {
|
|
|
|
|
$aObjectPermissions['DYNAFORMS'] = array(-1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_array($aObjectPermissions['DYNAFORMS'])) {
|
|
|
|
|
$aObjectPermissions['DYNAFORMS'] = array(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isset($aObjectPermissions['INPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['INPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_array($aObjectPermissions['INPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['INPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!isset($aObjectPermissions['OUTPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['OUTPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!is_array($aObjectPermissions['OUTPUT_DOCUMENTS'])) {
|
|
|
|
|
$aObjectPermissions['OUTPUT_DOCUMENTS'] = array(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$aDelete = $cases->getAllObjectsFrom($sProcessUID, $sApplicationUID, $sTasKUID, $sUserUID, 'DELETE');
|
2017-10-05 14:54:41 -04:00
|
|
|
$oAppDocument = new AppDocument();
|
|
|
|
|
$oCriteria = new Criteria('workflow');
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_TYPE, 'OUTPUT');
|
|
|
|
|
$oCriteria->add(AppDocumentPeer::APP_DOC_STATUS, array('ACTIVE'), Criteria::IN);
|
2014-03-24 16:59:03 -04:00
|
|
|
//$oCriteria->add(AppDocumentPeer::APP_DOC_UID, $aObjectPermissions['OUTPUT_DOCUMENTS'], Criteria::IN);
|
|
|
|
|
$oCriteria->add(
|
|
|
|
|
$oCriteria->getNewCriterion(
|
2017-10-05 14:54:41 -04:00
|
|
|
AppDocumentPeer::APP_DOC_UID, $aObjectPermissions['OUTPUT_DOCUMENTS'],
|
|
|
|
|
Criteria::IN)->addOr($oCriteria->getNewCriterion(AppDocumentPeer::USR_UID, $sUserUID, Criteria::EQUAL))
|
2014-03-24 16:59:03 -04:00
|
|
|
);
|
|
|
|
|
$aConditions = array();
|
2017-10-05 14:54:41 -04:00
|
|
|
$aConditions[] = array(AppDocumentPeer::APP_UID, AppDelegationPeer::APP_UID);
|
|
|
|
|
$aConditions[] = array(AppDocumentPeer::DEL_INDEX, AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oCriteria->addJoinMC($aConditions, Criteria::LEFT_JOIN);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::PRO_UID, $sProcessUID);
|
|
|
|
|
$oCriteria->addAscendingOrderByColumn(AppDocumentPeer::APP_DOC_INDEX);
|
|
|
|
|
$oDataset = AppDocumentPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-24 16:59:03 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
$aOutputDocuments = array();
|
|
|
|
|
$aOutputDocuments[] = array(
|
|
|
|
|
'APP_DOC_UID' => 'char',
|
|
|
|
|
'DOC_UID' => 'char',
|
|
|
|
|
'APP_DOC_COMMENT' => 'char',
|
|
|
|
|
'APP_DOC_FILENAME' => 'char',
|
|
|
|
|
'APP_DOC_INDEX' => 'integer'
|
|
|
|
|
);
|
2017-10-05 14:54:41 -04:00
|
|
|
$oUser = new ModelUsers();
|
2014-03-24 16:59:03 -04:00
|
|
|
while ($aRow = $oDataset->getRow()) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteria2 = new Criteria('workflow');
|
|
|
|
|
$oCriteria2->add(AppDelegationPeer::APP_UID, $sApplicationUID);
|
|
|
|
|
$oCriteria2->add(AppDelegationPeer::DEL_INDEX, $aRow['DEL_INDEX']);
|
|
|
|
|
$oDataset2 = AppDelegationPeer::doSelectRS($oCriteria2);
|
|
|
|
|
$oDataset2->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2014-03-24 16:59:03 -04:00
|
|
|
$oDataset2->next();
|
|
|
|
|
$aRow2 = $oDataset2->getRow();
|
2017-10-05 14:54:41 -04:00
|
|
|
$oTask = new ModelTask();
|
2014-03-24 16:59:03 -04:00
|
|
|
if ($oTask->taskExists($aRow2['TAS_UID'])) {
|
|
|
|
|
$aTask = $oTask->load($aRow2['TAS_UID']);
|
|
|
|
|
} else {
|
|
|
|
|
$aTask = array('TAS_TITLE' => '(TASK DELETED)');
|
|
|
|
|
}
|
|
|
|
|
$lastVersion = $oAppDocument->getLastDocVersion($aRow['DOC_UID'], $sApplicationUID);
|
|
|
|
|
if ($lastVersion == $aRow['DOC_VERSION']) {
|
|
|
|
|
//Only show last document Version
|
|
|
|
|
$aAux = $oAppDocument->load($aRow['APP_DOC_UID'], $aRow['DOC_VERSION']);
|
|
|
|
|
//Get output Document information
|
|
|
|
|
$oOutputDocument = new \OutputDocument();
|
|
|
|
|
$aGields = $oOutputDocument->load($aRow['DOC_UID']);
|
|
|
|
|
//OUTPUTDOCUMENT
|
|
|
|
|
$outDocTitle = $aGields['OUT_DOC_TITLE'];
|
|
|
|
|
switch ($aGields['OUT_DOC_GENERATE']) {
|
|
|
|
|
//G::LoadTranslation(ID_DOWNLOAD)
|
|
|
|
|
case "PDF":
|
|
|
|
|
$fileDoc = 'javascript:alert("NO DOC")';
|
|
|
|
|
$fileDocLabel = " ";
|
2015-11-11 08:44:19 -04:00
|
|
|
$filePdf = 'cases/cases_ShowOutputDocument?a=' .
|
2014-03-24 16:59:03 -04:00
|
|
|
$aRow['APP_DOC_UID'] . '&v=' . $aRow['DOC_VERSION'] . '&ext=pdf&random=' . rand();
|
|
|
|
|
$filePdfLabel = ".pdf";
|
|
|
|
|
if (is_array($listing)) {
|
|
|
|
|
foreach ($listing as $folderitem) {
|
|
|
|
|
if (($folderitem->filename == $aRow['APP_DOC_UID']) && ($folderitem->type == "PDF")) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$filePdfLabel = G::LoadTranslation('ID_GET_EXTERNAL_FILE') . " .pdf";
|
2014-03-24 16:59:03 -04:00
|
|
|
$filePdf = $folderitem->downloadScript;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "DOC":
|
2015-11-11 08:44:19 -04:00
|
|
|
$fileDoc = 'cases/cases_ShowOutputDocument?a=' .
|
2014-03-24 16:59:03 -04:00
|
|
|
$aRow['APP_DOC_UID'] . '&v=' . $aRow['DOC_VERSION'] . '&ext=doc&random=' . rand();
|
|
|
|
|
$fileDocLabel = ".doc";
|
|
|
|
|
$filePdf = 'javascript:alert("NO PDF")';
|
|
|
|
|
$filePdfLabel = " ";
|
|
|
|
|
if (is_array($listing)) {
|
|
|
|
|
foreach ($listing as $folderitem) {
|
|
|
|
|
if (($folderitem->filename == $aRow['APP_DOC_UID']) && ($folderitem->type == "DOC")) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$fileDocLabel = G::LoadTranslation('ID_GET_EXTERNAL_FILE') . " .doc";
|
2014-03-24 16:59:03 -04:00
|
|
|
$fileDoc = $folderitem->downloadScript;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "BOTH":
|
2015-11-11 08:44:19 -04:00
|
|
|
$fileDoc = 'cases/cases_ShowOutputDocument?a=' .
|
2014-03-24 16:59:03 -04:00
|
|
|
$aRow['APP_DOC_UID'] . '&v=' . $aRow['DOC_VERSION'] . '&ext=doc&random=' . rand();
|
|
|
|
|
$fileDocLabel = ".doc";
|
|
|
|
|
if (is_array($listing)) {
|
|
|
|
|
foreach ($listing as $folderitem) {
|
|
|
|
|
if (($folderitem->filename == $aRow['APP_DOC_UID']) && ($folderitem->type == "DOC")) {
|
|
|
|
|
$fileDocLabel = G::LoadTranslation('ID_GET_EXTERNAL_FILE') . " .doc";
|
|
|
|
|
$fileDoc = $folderitem->downloadScript;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-11 08:44:19 -04:00
|
|
|
$filePdf = 'cases/cases_ShowOutputDocument?a=' .
|
2014-03-24 16:59:03 -04:00
|
|
|
$aRow['APP_DOC_UID'] . '&v=' . $aRow['DOC_VERSION'] . '&ext=pdf&random=' . rand();
|
|
|
|
|
$filePdfLabel = ".pdf";
|
|
|
|
|
|
|
|
|
|
if (is_array($listing)) {
|
|
|
|
|
foreach ($listing as $folderitem) {
|
|
|
|
|
if (($folderitem->filename == $aRow['APP_DOC_UID']) && ($folderitem->type == "PDF")) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$filePdfLabel = G::LoadTranslation('ID_GET_EXTERNAL_FILE') . " .pdf";
|
2014-03-24 16:59:03 -04:00
|
|
|
$filePdf = $folderitem->downloadScript;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
$aAux1 = $oUser->load($aAux['USR_UID']);
|
2017-10-05 14:54:41 -04:00
|
|
|
$sUser = $conf->usersNameFormatBySetParameters($confEnvSetting["format"], $aAux1["USR_USERNAME"],
|
|
|
|
|
$aAux1["USR_FIRSTNAME"], $aAux1["USR_LASTNAME"]);
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $oException) {
|
2014-03-24 16:59:03 -04:00
|
|
|
$sUser = '(USER DELETED)';
|
|
|
|
|
}
|
|
|
|
|
//if both documents were generated, we choose the pdf one, only if doc was
|
|
|
|
|
//generate then choose the doc file.
|
|
|
|
|
$firstDocLink = $filePdf;
|
|
|
|
|
$firstDocLabel = $filePdfLabel;
|
|
|
|
|
if ($aGields['OUT_DOC_GENERATE'] == 'DOC') {
|
|
|
|
|
$firstDocLink = $fileDoc;
|
|
|
|
|
$firstDocLabel = $fileDocLabel;
|
|
|
|
|
}
|
|
|
|
|
$aFields = array(
|
|
|
|
|
'APP_DOC_UID' => $aAux['APP_DOC_UID'],
|
|
|
|
|
'DOC_UID' => $aAux['DOC_UID'],
|
|
|
|
|
'APP_DOC_COMMENT' => $aAux['APP_DOC_COMMENT'],
|
|
|
|
|
'APP_DOC_FILENAME' => $aAux['APP_DOC_FILENAME'],
|
|
|
|
|
'APP_DOC_INDEX' => $aAux['APP_DOC_INDEX'],
|
|
|
|
|
'ORIGIN' => $aTask['TAS_TITLE'],
|
|
|
|
|
'CREATE_DATE' => $aAux['APP_DOC_CREATE_DATE'],
|
|
|
|
|
'CREATED_BY' => $sUser,
|
|
|
|
|
'FILEDOC' => $fileDoc,
|
|
|
|
|
'FILEPDF' => $filePdf,
|
|
|
|
|
'OUTDOCTITLE' => $outDocTitle,
|
|
|
|
|
'DOC_VERSION' => $aAux['DOC_VERSION'],
|
|
|
|
|
'TYPE' => $aAux['APP_DOC_TYPE'] . ' ' . $aGields['OUT_DOC_GENERATE'],
|
|
|
|
|
'DOWNLOAD_LINK' => $firstDocLink,
|
|
|
|
|
'DOWNLOAD_FILE' => $aAux['APP_DOC_FILENAME'] . $firstDocLabel
|
|
|
|
|
);
|
|
|
|
|
if (trim($fileDocLabel) != '') {
|
|
|
|
|
$aFields['FILEDOCLABEL'] = $fileDocLabel;
|
|
|
|
|
}
|
|
|
|
|
if (trim($filePdfLabel) != '') {
|
|
|
|
|
$aFields['FILEPDFLABEL'] = $filePdfLabel;
|
|
|
|
|
}
|
|
|
|
|
if ($aFields['APP_DOC_FILENAME'] != '') {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_FILENAME'];
|
|
|
|
|
} else {
|
|
|
|
|
$aFields['TITLE'] = $aFields['APP_DOC_COMMENT'];
|
|
|
|
|
}
|
|
|
|
|
//$aFields['POSITION'] = $_SESSION['STEP_POSITION'];
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['CONFIRM'] = G::LoadTranslation('ID_CONFIRM_DELETE_ELEMENT');
|
2014-03-24 16:59:03 -04:00
|
|
|
if (in_array($aRow['APP_DOC_UID'], $aObjectPermissions['OUTPUT_DOCUMENTS'])) {
|
|
|
|
|
if (in_array($aRow['APP_DOC_UID'], $aDelete['OUTPUT_DOCUMENTS'])) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$aFields['ID_DELETE'] = G::LoadTranslation('ID_DELETE');
|
2014-03-24 16:59:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$aOutputDocuments[] = $aFields;
|
|
|
|
|
}
|
|
|
|
|
$oDataset->next();
|
|
|
|
|
}
|
|
|
|
|
global $_DBArray;
|
|
|
|
|
$_DBArray['outputDocuments'] = $aOutputDocuments;
|
2017-02-14 21:24:08 +00:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteria = new Criteria('dbarray');
|
2014-03-24 16:59:03 -04:00
|
|
|
$oCriteria->setDBArrayTable('outputDocuments');
|
|
|
|
|
$oCriteria->addDescendingOrderByColumn('CREATE_DATE');
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-24 16:59:03 -04:00
|
|
|
return $oCriteria;
|
|
|
|
|
}
|
2014-03-26 09:50:06 -04:00
|
|
|
|
2016-05-18 15:13:56 -04:00
|
|
|
/**
|
|
|
|
|
* Get fields and values by DynaForm
|
|
|
|
|
*
|
|
|
|
|
* @param array $form
|
|
|
|
|
* @param array $appData
|
|
|
|
|
* @param array $caseVariable
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2017-08-14 16:04:57 -04:00
|
|
|
* @return array
|
2018-01-04 09:58:45 -04:00
|
|
|
* @throws Exception
|
2016-05-18 15:13:56 -04:00
|
|
|
*/
|
2019-11-27 14:36:31 -04:00
|
|
|
private function getFieldsAndValuesByDynaFormAndAppData(array $form, array $appData, array $caseVariable)
|
2016-05-18 15:13:56 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
foreach ($form['items'] as $value) {
|
2017-08-14 16:04:57 -04:00
|
|
|
foreach ($value as $field) {
|
2016-05-18 15:13:56 -04:00
|
|
|
if (isset($field['type'])) {
|
|
|
|
|
if ($field['type'] != 'form') {
|
2017-08-14 16:04:57 -04:00
|
|
|
foreach ($field as $key => $val) {
|
2017-08-17 17:03:13 -04:00
|
|
|
if (is_string($val) && in_array(substr($val, 0, 2), PmDynaform::$prefixs)) {
|
2017-08-14 16:04:57 -04:00
|
|
|
$field[$key] = substr($val, 2);
|
2017-02-20 15:44:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
2017-08-14 16:04:57 -04:00
|
|
|
foreach ($appData as $key => $val) {
|
2017-02-20 15:44:55 -04:00
|
|
|
if (in_array($key, $field, true) != false) {
|
2017-11-01 07:51:17 -04:00
|
|
|
$caseVariable[$key] = $this->getFieldValue($field, $appData[$key]);
|
2017-08-14 16:04:57 -04:00
|
|
|
if (isset($appData[$key . '_label'])) {
|
|
|
|
|
$caseVariable[$key . '_label'] = $appData[$key . '_label'];
|
2016-05-18 15:13:56 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-11-27 14:36:31 -04:00
|
|
|
$caseVariableAux = $this->getFieldsAndValuesByDynaFormAndAppData($field, $appData,
|
2017-10-05 14:54:41 -04:00
|
|
|
$caseVariable);
|
2016-05-18 15:13:56 -04:00
|
|
|
$caseVariable = array_merge($caseVariable, $caseVariableAux);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2016-05-18 15:13:56 -04:00
|
|
|
return $caseVariable;
|
2017-08-15 12:19:42 -04:00
|
|
|
} catch (Exception $e) {
|
2016-05-18 15:13:56 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 07:51:17 -04:00
|
|
|
/**
|
|
|
|
|
* Return the field value to be used in the front-end client.
|
|
|
|
|
*
|
|
|
|
|
* @param type $field
|
|
|
|
|
* @param type $value
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
|
|
|
|
* @return string
|
2017-11-01 07:51:17 -04:00
|
|
|
*/
|
|
|
|
|
private function getFieldValue($field, $value)
|
|
|
|
|
{
|
|
|
|
|
switch ($field['type']) {
|
|
|
|
|
case 'file':
|
|
|
|
|
return $field['data']['app_doc_uid'];
|
|
|
|
|
default:
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-26 09:50:06 -04:00
|
|
|
/**
|
|
|
|
|
* Get Case Variables
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $app_uid , Uid for case
|
|
|
|
|
* @param string $usr_uid , Uid for user
|
|
|
|
|
* @param string $dynaFormUid , Uid for dynaform
|
2014-03-26 09:50:06 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array
|
2014-03-26 09:50:06 -04:00
|
|
|
*/
|
2017-10-05 14:54:41 -04:00
|
|
|
public function getCaseVariables(
|
|
|
|
|
$app_uid,
|
|
|
|
|
$usr_uid,
|
|
|
|
|
$dynaFormUid = null,
|
|
|
|
|
$pro_uid = null,
|
|
|
|
|
$act_uid = null,
|
|
|
|
|
$app_index = null
|
|
|
|
|
) {
|
2014-03-26 09:50:06 -04:00
|
|
|
Validator::isString($app_uid, '$app_uid');
|
|
|
|
|
Validator::appUid($app_uid, '$app_uid');
|
2015-08-26 15:34:02 -04:00
|
|
|
Validator::isString($usr_uid, '$usr_uid');
|
|
|
|
|
Validator::usrUid($usr_uid, '$usr_uid');
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2014-03-26 09:50:06 -04:00
|
|
|
$fields = $case->loadCase($app_uid);
|
2016-05-18 15:13:56 -04:00
|
|
|
|
|
|
|
|
$arrayCaseVariable = [];
|
|
|
|
|
|
|
|
|
|
if (!is_null($dynaFormUid)) {
|
2017-09-20 10:27:38 -04:00
|
|
|
$data = [];
|
2017-09-15 17:52:26 -04:00
|
|
|
$data["APP_DATA"] = $fields['APP_DATA'];
|
2016-09-29 10:34:05 -04:00
|
|
|
$data["CURRENT_DYNAFORM"] = $dynaFormUid;
|
2017-08-11 15:49:39 -04:00
|
|
|
$pmDynaForm = new PmDynaform($data);
|
2016-12-09 15:53:29 -04:00
|
|
|
$arrayDynaFormData = $pmDynaForm->getDynaform();
|
2017-10-05 14:54:41 -04:00
|
|
|
$arrayDynContent = G::json_decode($arrayDynaFormData['DYN_CONTENT']);
|
2016-09-29 10:34:05 -04:00
|
|
|
$pmDynaForm->jsonr($arrayDynContent);
|
2016-12-09 15:53:29 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$arrayDynContent = G::json_decode(G::json_encode($arrayDynContent), true);
|
2016-05-18 15:13:56 -04:00
|
|
|
|
|
|
|
|
$arrayAppData = $fields['APP_DATA'];
|
|
|
|
|
|
2019-11-27 14:36:31 -04:00
|
|
|
$arrayCaseVariable = $this->getFieldsAndValuesByDynaFormAndAppData(
|
2017-10-05 14:54:41 -04:00
|
|
|
$arrayDynContent['items'][0], $arrayAppData, $arrayCaseVariable
|
2016-05-18 15:13:56 -04:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$arrayCaseVariable = $fields['APP_DATA'];
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 16:13:03 -04:00
|
|
|
//Get historyDate for Dynaform
|
|
|
|
|
if (!is_null($pro_uid) && !is_null($act_uid) && !is_null($app_index)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteriaAppHistory = new Criteria("workflow");
|
|
|
|
|
$oCriteriaAppHistory->addSelectColumn(AppHistoryPeer::HISTORY_DATE);
|
|
|
|
|
$oCriteriaAppHistory->add(AppHistoryPeer::APP_UID, $app_uid, Criteria::EQUAL);
|
|
|
|
|
$oCriteriaAppHistory->add(AppHistoryPeer::DEL_INDEX, $app_index, Criteria::EQUAL);
|
|
|
|
|
$oCriteriaAppHistory->add(AppHistoryPeer::PRO_UID, $pro_uid, Criteria::EQUAL);
|
|
|
|
|
$oCriteriaAppHistory->add(AppHistoryPeer::TAS_UID, $act_uid, Criteria::EQUAL);
|
|
|
|
|
$oCriteriaAppHistory->add(AppHistoryPeer::USR_UID, $usr_uid, Criteria::EQUAL);
|
2016-07-18 16:13:03 -04:00
|
|
|
if (!is_null($dynaFormUid)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCriteriaAppHistory->add(AppHistoryPeer::DYN_UID, $dynaFormUid, Criteria::EQUAL);
|
2016-07-18 16:13:03 -04:00
|
|
|
}
|
|
|
|
|
$oCriteriaAppHistory->addDescendingOrderByColumn('HISTORY_DATE');
|
|
|
|
|
$oCriteriaAppHistory->setLimit(1);
|
2017-10-05 14:54:41 -04:00
|
|
|
$oDataset = AppDocumentPeer::doSelectRS($oCriteriaAppHistory);
|
|
|
|
|
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2016-07-18 16:13:03 -04:00
|
|
|
$oDataset->next();
|
|
|
|
|
if ($aRow = $oDataset->getRow()) {
|
|
|
|
|
$dateHistory['SYS_VAR_UPDATE_DATE'] = $aRow['HISTORY_DATE'];
|
2016-09-14 11:25:24 -04:00
|
|
|
} else {
|
|
|
|
|
$dateHistory['SYS_VAR_UPDATE_DATE'] = null;
|
2016-07-18 16:13:03 -04:00
|
|
|
}
|
2016-09-14 11:53:57 -04:00
|
|
|
$arrayCaseVariable = array_merge($arrayCaseVariable, $dateHistory);
|
2016-07-18 16:13:03 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2019-10-10 14:38:22 -04:00
|
|
|
// Get the SYS_LANG defined, it can be updated
|
|
|
|
|
if (defined('SYS_LANG')) {
|
|
|
|
|
$arrayCaseVariable['SYS_LANG'] = SYS_LANG;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 15:13:56 -04:00
|
|
|
return $arrayCaseVariable;
|
2014-03-26 09:50:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Put Set Case Variables
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $app_uid , Uid for case
|
|
|
|
|
* @param array $app_data , Data for case variables
|
|
|
|
|
* @param string $dyn_uid , Uid for dynaform
|
|
|
|
|
* @param string $del_index , Index for case
|
|
|
|
|
* @param string $usr_uid , Uid for user
|
2014-03-26 09:50:06 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-26 09:50:06 -04:00
|
|
|
*/
|
2022-07-21 00:04:21 -04:00
|
|
|
public function setCaseVariables($app_uid, $app_data, $dyn_uid = null, $usr_uid = '', $del_index = 0)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2014-03-26 09:50:06 -04:00
|
|
|
Validator::isString($app_uid, '$app_uid');
|
|
|
|
|
Validator::appUid($app_uid, '$app_uid');
|
|
|
|
|
Validator::isArray($app_data, '$app_data');
|
2015-08-26 15:34:02 -04:00
|
|
|
Validator::isString($usr_uid, '$usr_uid');
|
|
|
|
|
Validator::usrUid($usr_uid, '$usr_uid');
|
2022-03-24 17:14:47 -04:00
|
|
|
// Validate the system variables
|
|
|
|
|
$systemVars = G::getSystemConstants();
|
|
|
|
|
foreach ($systemVars as $key => $var) {
|
|
|
|
|
if (array_key_exists($key, $app_data)) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_CAN_NOT_CHANGE"));
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-26 15:34:02 -04:00
|
|
|
|
2015-09-25 12:54:12 -04:00
|
|
|
$arrayResult = $this->getStatusInfo($app_uid);
|
|
|
|
|
|
|
|
|
|
if ($arrayResult["APP_STATUS"] == "CANCELLED") {
|
2021-07-19 13:19:55 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_CANCELLED", [$app_uid]));
|
2015-09-25 12:54:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($arrayResult["APP_STATUS"] == "COMPLETED") {
|
2021-07-19 13:19:55 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_CASE_IS_COMPLETED", [$app_uid]));
|
2015-09-25 12:54:12 -04:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 13:19:55 -04:00
|
|
|
// Review if the user has participation or is supervisor
|
|
|
|
|
$caseNumber = ModelApplication::getCaseNumber($app_uid);
|
|
|
|
|
$permission = $this->participation($usr_uid, $caseNumber, $del_index);
|
|
|
|
|
if (!$permission) {
|
|
|
|
|
throw new Exception(G::LoadTranslation("ID_NO_PERMISSION_NO_PARTICIPATED", [$usr_uid]));
|
2015-08-26 15:34:02 -04:00
|
|
|
}
|
2014-03-26 09:50:06 -04:00
|
|
|
|
2015-09-03 15:19:07 -04:00
|
|
|
$_SESSION['APPLICATION'] = $app_uid;
|
|
|
|
|
$_SESSION['USER_LOGGED'] = $usr_uid;
|
2015-09-15 10:40:56 -04:00
|
|
|
|
2016-08-15 09:28:25 -04:00
|
|
|
$arrayVariableDocumentToDelete = [];
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('__VARIABLE_DOCUMENT_DELETE__', $app_data)) {
|
|
|
|
|
if (is_array($app_data['__VARIABLE_DOCUMENT_DELETE__']) && !empty($app_data['__VARIABLE_DOCUMENT_DELETE__'])) {
|
|
|
|
|
$arrayVariableDocumentToDelete = $app_data['__VARIABLE_DOCUMENT_DELETE__'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($app_data['__VARIABLE_DOCUMENT_DELETE__']);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2016-04-25 12:15:39 -04:00
|
|
|
$fields = $case->loadCase($app_uid, $del_index);
|
2015-01-08 11:54:19 -04:00
|
|
|
$_POST['form'] = $app_data;
|
|
|
|
|
|
2015-01-14 10:31:38 -04:00
|
|
|
if (!is_null($dyn_uid) && $dyn_uid != '') {
|
2015-01-08 11:54:19 -04:00
|
|
|
$oDynaform = \DynaformPeer::retrieveByPK($dyn_uid);
|
|
|
|
|
|
|
|
|
|
if ($oDynaform->getDynVersion() < 2) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oForm = new \Form ($fields['PRO_UID'] . "/" . $dyn_uid, PATH_DYNAFORM);
|
2015-01-08 11:54:19 -04:00
|
|
|
$oForm->validatePost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 12:15:39 -04:00
|
|
|
if (!is_null($dyn_uid) && $del_index > 0) {
|
|
|
|
|
//save data
|
|
|
|
|
$data = array();
|
|
|
|
|
$data['APP_NUMBER'] = $fields['APP_NUMBER'];
|
|
|
|
|
$data['APP_DATA'] = $fields['APP_DATA'];
|
|
|
|
|
$data['DEL_INDEX'] = $del_index;
|
|
|
|
|
$data['TAS_UID'] = $fields['TAS_UID'];;
|
|
|
|
|
$data['CURRENT_DYNAFORM'] = $dyn_uid;
|
|
|
|
|
$data['USER_UID'] = $usr_uid;
|
|
|
|
|
$data['PRO_UID'] = $fields['PRO_UID'];
|
|
|
|
|
}
|
2015-01-08 11:54:19 -04:00
|
|
|
$data['APP_DATA'] = array_merge($fields['APP_DATA'], $_POST['form']);
|
2014-03-26 09:50:06 -04:00
|
|
|
$case->updateCase($app_uid, $data);
|
2016-08-15 09:28:25 -04:00
|
|
|
|
|
|
|
|
//Delete MultipleFile
|
|
|
|
|
if (!empty($arrayVariableDocumentToDelete)) {
|
|
|
|
|
$this->deleteMultipleFile($app_uid, $arrayVariableDocumentToDelete);
|
|
|
|
|
}
|
2014-03-26 09:50:06 -04:00
|
|
|
}
|
2014-03-26 12:20:20 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Case Notes
|
|
|
|
|
*
|
2021-05-12 18:59:01 -04:00
|
|
|
* @param string $appUid
|
|
|
|
|
* @param string $usrUid
|
|
|
|
|
* @param array $parameters
|
2014-03-26 12:20:20 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array
|
2021-05-12 18:59:01 -04:00
|
|
|
* @throws \PropelException
|
|
|
|
|
* @access public
|
2014-03-26 12:20:20 -04:00
|
|
|
*/
|
2021-05-12 18:59:01 -04:00
|
|
|
public function getCaseNotes($appUid, $usrUid, $parameters = [])
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2021-05-12 18:59:01 -04:00
|
|
|
// Validate parameters
|
|
|
|
|
Validator::isString($appUid, '$app_uid');
|
|
|
|
|
Validator::appUid($appUid, '$app_uid');
|
|
|
|
|
Validator::isString($usrUid, '$usr_uid');
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
|
|
|
|
Validator::isArray($parameters, '$parameters');
|
|
|
|
|
Validator::isArray($parameters, '$parameters');
|
|
|
|
|
$start = isset($parameters["start"]) ? $parameters["start"] : "0";
|
|
|
|
|
$limit = isset($parameters["limit"]) ? $parameters["limit"] : "";
|
|
|
|
|
$sort = isset($parameters["sort"]) ? $parameters["sort"] : "NOTE_DATE";
|
|
|
|
|
$dir = isset($parameters["dir"]) ? $parameters["dir"] : "DESC";
|
|
|
|
|
$user = isset($parameters["user"]) ? $parameters["user"] : "";
|
|
|
|
|
$dateFrom = (!empty($parameters["dateFrom"])) ? substr($parameters["dateFrom"], 0, 10) : "";
|
|
|
|
|
$dateTo = (!empty($parameters["dateTo"])) ? substr($parameters["dateTo"], 0, 10) : "";
|
|
|
|
|
$search = isset($parameters["search"]) ? $parameters["search"] : "";
|
|
|
|
|
$paged = isset($parameters["paged"]) ? $parameters["paged"] : true;
|
|
|
|
|
$files = isset($parameters["files"]) ? $parameters["files"] : false;
|
|
|
|
|
if (!empty($user)) {
|
2014-03-28 11:40:59 -04:00
|
|
|
Validator::usrUid($user, '$usr_uid');
|
|
|
|
|
}
|
2021-05-12 18:59:01 -04:00
|
|
|
if (!empty($dateFrom)) {
|
2014-03-28 11:40:59 -04:00
|
|
|
Validator::isDate($dateFrom, 'Y-m-d', '$date_from');
|
|
|
|
|
}
|
2021-05-12 18:59:01 -04:00
|
|
|
if (!empty($dateTo)) {
|
2014-03-28 11:40:59 -04:00
|
|
|
Validator::isDate($dateTo, 'Y-m-d', '$date_to');
|
|
|
|
|
}
|
2021-05-12 18:59:01 -04:00
|
|
|
// Review the process permissions
|
|
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$caseLoad = $case->loadCase($appUid);
|
|
|
|
|
$proUid = $caseLoad['PRO_UID'];
|
|
|
|
|
$tasUid = AppDelegation::getCurrentTask($appUid);
|
|
|
|
|
$respView = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, 'VIEW');
|
|
|
|
|
$respBlock = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, 'BLOCK');
|
|
|
|
|
if ($respView['CASES_NOTES'] == 0 && $respBlock['CASES_NOTES'] == 0) {
|
2021-09-16 21:48:00 -04:00
|
|
|
throw new Exception(G::LoadTranslation("ID_THIS_USER_DOESNT_HAVE_PERMISSIONS_TO_SEE_CASE_NOTES"));
|
2021-05-12 18:59:01 -04:00
|
|
|
}
|
|
|
|
|
// Get the notes
|
|
|
|
|
$appNote = new Notes();
|
|
|
|
|
$notes = $appNote->getNotes($appUid, $start, $limit, $dir);
|
|
|
|
|
$notes = AppNotes::applyHtmlentitiesInNotes($notes);
|
|
|
|
|
// Add a the notes the files related
|
|
|
|
|
$documents = new Documents();
|
|
|
|
|
$iterator = 0;
|
|
|
|
|
$data = [];
|
|
|
|
|
foreach ($notes['notes'] as $value) {
|
|
|
|
|
$data[$iterator] = array_change_key_case($value, CASE_LOWER);
|
|
|
|
|
$data[$iterator]['note_date'] = UtilDateTime::convertUtcToTimeZone($value['NOTE_DATE']);
|
|
|
|
|
if ($files) {
|
|
|
|
|
$data[$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID']);
|
|
|
|
|
}
|
|
|
|
|
$iterator++;
|
|
|
|
|
}
|
|
|
|
|
// If is paged will add the filters used
|
|
|
|
|
$filters = [];
|
|
|
|
|
if ($paged) {
|
|
|
|
|
$total = $appNote->getTotal($appUid);
|
|
|
|
|
$filters['total'] = $total;
|
|
|
|
|
$filters['start'] = $start;
|
|
|
|
|
$filters['limit'] = $limit;
|
|
|
|
|
$filters['sort'] = $sort;
|
|
|
|
|
$filters['dir'] = $dir;
|
|
|
|
|
$filters['usr_uid'] = $user;
|
|
|
|
|
$filters['date_to'] = $dateTo;
|
|
|
|
|
$filters['date_from'] = $dateFrom;
|
|
|
|
|
$filters['search'] = $search;
|
|
|
|
|
}
|
|
|
|
|
// Prepare the response
|
|
|
|
|
$response = [];
|
|
|
|
|
if ($paged) {
|
|
|
|
|
$response = $filters;
|
|
|
|
|
$response['data'] = $data;
|
2014-03-28 11:40:59 -04:00
|
|
|
} else {
|
2021-05-12 18:59:01 -04:00
|
|
|
$response = $data;
|
2014-03-26 12:20:20 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2014-03-26 12:20:20 -04:00
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save new case note
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2021-05-12 18:59:01 -04:00
|
|
|
* @param string $appUid, Uid for case
|
|
|
|
|
* @param string $usrUid, Uid for user
|
|
|
|
|
* @param string $noteContent
|
|
|
|
|
* @param boolean $sendMail
|
2014-03-26 12:20:20 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
|
|
|
|
* @throws Exception
|
2014-03-26 12:20:20 -04:00
|
|
|
*/
|
2021-05-12 18:59:01 -04:00
|
|
|
public function saveCaseNote($appUid, $usrUid, $noteContent, $sendMail = false)
|
2014-06-06 12:04:30 -04:00
|
|
|
{
|
2021-05-12 18:59:01 -04:00
|
|
|
Validator::isString($appUid, '$app_uid');
|
|
|
|
|
Validator::appUid($appUid, '$app_uid');
|
|
|
|
|
Validator::isString($usrUid, '$usr_uid');
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
|
|
|
|
Validator::isString($noteContent, '$note_content');
|
|
|
|
|
if (strlen($noteContent) > 500) {
|
|
|
|
|
throw (new Exception(G::LoadTranslation("ID_INVALID_MAX_PERMITTED", [$noteContent, '500'])));
|
2014-03-26 12:20:20 -04:00
|
|
|
}
|
2021-05-12 18:59:01 -04:00
|
|
|
Validator::isBoolean($sendMail, '$send_mail');
|
|
|
|
|
// Review the process permissions
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2021-05-12 18:59:01 -04:00
|
|
|
$caseLoad = $case->loadCase($appUid);
|
|
|
|
|
$proUid = $caseLoad['PRO_UID'];
|
|
|
|
|
$tasUid = AppDelegation::getCurrentTask($appUid);
|
|
|
|
|
$respView = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, 'VIEW');
|
|
|
|
|
$respBlock = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, 'BLOCK');
|
2014-03-26 12:20:20 -04:00
|
|
|
if ($respView['CASES_NOTES'] == 0 && $respBlock['CASES_NOTES'] == 0) {
|
2017-10-05 14:54:41 -04:00
|
|
|
throw (new Exception(G::LoadTranslation("ID_CASES_NOTES_NO_PERMISSIONS")));
|
2014-03-26 12:20:20 -04:00
|
|
|
}
|
2021-05-12 18:59:01 -04:00
|
|
|
// Save the notes
|
|
|
|
|
$response = $this->addNote($appUid, $usrUid, $noteContent, intval($sendMail));
|
2014-03-26 12:20:20 -04:00
|
|
|
}
|
2014-05-13 16:13:18 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-06-06 12:04:30 -04:00
|
|
|
* Get data of a Task from a record
|
2014-05-13 16:13:18 -04:00
|
|
|
*
|
2014-06-06 12:04:30 -04:00
|
|
|
* @param array $record Record
|
2014-05-13 16:13:18 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array Return an array with data Task
|
|
|
|
|
* @throws Exception
|
2014-05-13 16:13:18 -04:00
|
|
|
*/
|
2014-06-06 12:04:30 -04:00
|
|
|
public function getTaskDataFromRecord(array $record)
|
2014-05-13 16:13:18 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-06-06 12:04:30 -04:00
|
|
|
return array(
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("TAS_UID") => $record["TAS_UID"],
|
|
|
|
|
$this->getFieldNameByFormatFieldName("TAS_TITLE") => $record["TAS_TITLE"] . "",
|
2014-06-06 12:04:30 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("TAS_DESCRIPTION") => $record["TAS_DESCRIPTION"] . "",
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("TAS_START") => ($record["TAS_START"] == "TRUE") ? 1 : 0,
|
|
|
|
|
$this->getFieldNameByFormatFieldName("TAS_TYPE") => $record["TAS_TYPE"],
|
|
|
|
|
$this->getFieldNameByFormatFieldName("TAS_DERIVATION") => $record["TAS_DERIVATION"],
|
2014-06-06 12:04:30 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("TAS_ASSIGN_TYPE") => $record["TAS_ASSIGN_TYPE"],
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("USR_UID") => $record["USR_UID"] . "",
|
|
|
|
|
$this->getFieldNameByFormatFieldName("USR_USERNAME") => $record["USR_USERNAME"] . "",
|
|
|
|
|
$this->getFieldNameByFormatFieldName("USR_FIRSTNAME") => $record["USR_FIRSTNAME"] . "",
|
|
|
|
|
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $record["USR_LASTNAME"] . ""
|
2014-06-06 12:04:30 -04:00
|
|
|
);
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-06-06 12:04:30 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all Tasks of Case
|
|
|
|
|
* Based in: processmaker/workflow/engine/classes/class.processMap.php
|
2022-06-30 18:01:35 -04:00
|
|
|
* Method: processMap::load()
|
2014-06-06 12:04:30 -04:00
|
|
|
*
|
|
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
*
|
2019-02-19 14:30:46 -04:00
|
|
|
* @see workflow/engine/src/ProcessMaker/Services/Api/Cases.php
|
|
|
|
|
* @see workflow/engine/src/ProcessMaker/Services/Api/Light.php
|
|
|
|
|
*
|
|
|
|
|
* @link https://wiki.processmaker.com/3.3/REST_API_Cases/Cases#Get_Case.27s_Tasks:_GET_.2Fcases.2F.7Bapp_uid.7D.2Ftasks
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array Return an array with all Tasks of Case
|
|
|
|
|
* @throws Exception
|
2014-06-06 12:04:30 -04:00
|
|
|
*/
|
|
|
|
|
public function getTasks($applicationUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$arrayTask = array();
|
|
|
|
|
|
|
|
|
|
//Verify data
|
2015-09-25 19:25:47 -04:00
|
|
|
$this->throwExceptionIfNotExistsCase($applicationUid, 0, $this->getFieldNameByFormatFieldName("APP_UID"));
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
//Set variables
|
|
|
|
|
$process = new \Process();
|
|
|
|
|
$application = new \Application();
|
2017-10-05 14:54:41 -04:00
|
|
|
$conf = new Configurations();
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
$arrayApplicationData = $application->Load($applicationUid);
|
|
|
|
|
$processUid = $arrayApplicationData["PRO_UID"];
|
|
|
|
|
|
|
|
|
|
$confEnvSetting = $conf->getFormats();
|
|
|
|
|
|
|
|
|
|
$taskUid = "";
|
|
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
//Obtain the list of tasks and their respectives users assigned to each one for an specific case
|
|
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$rsTasks = $case->getTasksInfoForACase($applicationUid, $processUid);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
while ($rsTasks->next()) {
|
|
|
|
|
$row = $rsTasks->getRow();
|
2014-06-06 12:04:30 -04:00
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
//If the task is a multiple task
|
|
|
|
|
if ($row["TAS_ASSIGN_TYPE"] == 'MULTIPLE_INSTANCE' || $row["TAS_ASSIGN_TYPE"] == 'MULTIPLE_INSTANCE_VALUE_BASED') {
|
|
|
|
|
$row["USR_UID"] = "";
|
|
|
|
|
$row["USR_USERNAME"] = "";
|
|
|
|
|
$row["USR_FIRSTNAME"] = "";
|
|
|
|
|
$row["USR_LASTNAME"] = "";
|
|
|
|
|
}
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
//Task
|
|
|
|
|
if ($row["TAS_TYPE"] == "NORMAL") {
|
|
|
|
|
if (($row["TAS_TITLE"] . "" == "")) {
|
2014-05-13 16:13:18 -04:00
|
|
|
//There is no Label in Current SYS_LANG language so try to find in English - by default
|
2017-10-05 14:54:41 -04:00
|
|
|
$task = new ModelTask();
|
2014-06-06 12:04:30 -04:00
|
|
|
$task->setTasUid($row["TAS_UID"]);
|
|
|
|
|
|
|
|
|
|
$row["TAS_TITLE"] = $task->getTasTitle();
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2014-06-06 12:04:30 -04:00
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
//Get the task information when the task type is different from normal
|
|
|
|
|
$rsCriteria2 = $case->getTaskInfoForSubProcess($processUid, $row["TAS_UID"]);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
$rsCriteria2->next();
|
|
|
|
|
|
|
|
|
|
$row2 = $rsCriteria2->getRow();
|
2021-10-22 20:17:50 +00:00
|
|
|
$proUid = isset($row2["PRO_UID"]) ? $row2["PRO_UID"] : '';
|
|
|
|
|
if (!empty($proUid) && $process->exists($proUid)) {
|
2014-06-06 12:04:30 -04:00
|
|
|
$row["TAS_TITLE"] = $row2["TAS_TITLE"];
|
|
|
|
|
$row["TAS_DESCRIPTION"] = $row2["TAS_DESCRIPTION"];
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-02 11:19:58 -04:00
|
|
|
|
2014-06-06 12:04:30 -04:00
|
|
|
//Routes
|
|
|
|
|
$routeType = "";
|
|
|
|
|
$arrayRoute = array();
|
|
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
//Get the routes of a task
|
|
|
|
|
$rsCriteria2 = $case->getTaskRoutes($processUid, $row["TAS_UID"]);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
while ($rsCriteria2->next()) {
|
|
|
|
|
$row2 = $rsCriteria2->getRow();
|
|
|
|
|
|
|
|
|
|
$routeType = $row2["ROU_TYPE"];
|
|
|
|
|
|
|
|
|
|
$arrayRoute[] = array(
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("ROU_NUMBER") => (int)($row2["ROU_NUMBER"]),
|
2014-06-06 12:04:30 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("ROU_CONDITION") => $row2["ROU_CONDITION"] . "",
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("TAS_UID") => $row2["TAS_UID"]
|
2014-06-06 12:04:30 -04:00
|
|
|
);
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
//Delegations
|
|
|
|
|
$arrayAppDelegation = array();
|
|
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
$rsCriteria2 = $case->getCaseDelegations($applicationUid, $row["TAS_UID"]);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
while ($rsCriteria2->next()) {
|
|
|
|
|
$row2 = $rsCriteria2->getRow();
|
|
|
|
|
|
|
|
|
|
$arrayAppDelegationDate = array(
|
2017-10-05 14:54:41 -04:00
|
|
|
"DEL_INIT_DATE" => array(
|
|
|
|
|
"date" => $row2["DEL_INIT_DATE"],
|
|
|
|
|
"dateFormated" => G::LoadTranslation("ID_CASE_NOT_YET_STARTED")
|
|
|
|
|
),
|
|
|
|
|
"DEL_TASK_DUE_DATE" => array(
|
|
|
|
|
"date" => $row2["DEL_TASK_DUE_DATE"],
|
|
|
|
|
"dateFormated" => G::LoadTranslation("ID_CASE_NOT_YET_STARTED")
|
|
|
|
|
),
|
|
|
|
|
"DEL_FINISH_DATE" => array(
|
|
|
|
|
"date" => $row2["DEL_FINISH_DATE"],
|
|
|
|
|
"dateFormated" => G::LoadTranslation("ID_NOT_FINISHED")
|
|
|
|
|
)
|
2014-06-06 12:04:30 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($arrayAppDelegationDate as $key => $value) {
|
|
|
|
|
$d = $value;
|
|
|
|
|
|
|
|
|
|
if (!empty($d["date"])) {
|
|
|
|
|
$dateTime = new \DateTime($d["date"]);
|
|
|
|
|
$arrayAppDelegationDate[$key]["dateFormated"] = $dateTime->format($confEnvSetting["dateFormat"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$appDelegationDuration = G::LoadTranslation("ID_NOT_FINISHED");
|
2014-06-06 12:04:30 -04:00
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
$date = empty($row2["DEL_INIT_DATE"]) ? $row2["DEL_DELEGATE_DATE"] : $row2["DEL_INIT_DATE"];
|
|
|
|
|
|
|
|
|
|
if (!empty($row2["DEL_FINISH_DATE"]) && !empty($date)) {
|
|
|
|
|
$t = strtotime($row2["DEL_FINISH_DATE"]) - strtotime($date);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
$h = $t * (1 / 60) * (1 / 60);
|
|
|
|
|
$m = ($h - (int)($h)) * (60 / 1);
|
|
|
|
|
$s = ($m - (int)($m)) * (60 / 1);
|
|
|
|
|
|
|
|
|
|
$h = (int)($h);
|
|
|
|
|
$m = (int)($m);
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$appDelegationDuration = $h . " " . (($h == 1) ? G::LoadTranslation("ID_HOUR") : G::LoadTranslation("ID_HOURS"));
|
|
|
|
|
$appDelegationDuration = $appDelegationDuration . " " . $m . " " . (($m == 1) ? G::LoadTranslation("ID_MINUTE") : G::LoadTranslation("ID_MINUTES"));
|
|
|
|
|
$appDelegationDuration = $appDelegationDuration . " " . $s . " " . (($s == 1) ? G::LoadTranslation("ID_SECOND") : G::LoadTranslation("ID_SECONDS"));
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
$arrayAppDelegation[] = array(
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("DEL_INDEX") => (int)($row2["DEL_INDEX"]),
|
|
|
|
|
$this->getFieldNameByFormatFieldName("DEL_INIT_DATE") => $arrayAppDelegationDate["DEL_INIT_DATE"]["dateFormated"],
|
2014-06-06 12:04:30 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("DEL_TASK_DUE_DATE") => $arrayAppDelegationDate["DEL_TASK_DUE_DATE"]["dateFormated"],
|
2017-10-05 14:54:41 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("DEL_FINISH_DATE") => $arrayAppDelegationDate["DEL_FINISH_DATE"]["dateFormated"],
|
|
|
|
|
$this->getFieldNameByFormatFieldName("DEL_DURATION") => $appDelegationDuration,
|
|
|
|
|
$this->getFieldNameByFormatFieldName("USR_UID") => $row2["USR_UID"],
|
2019-02-19 14:30:46 -04:00
|
|
|
$this->getFieldNameByFormatFieldName("USR_USERNAME") => $row2["USR_USERNAME"],
|
|
|
|
|
$this->getFieldNameByFormatFieldName("USR_FIRSTNAME") => $row2["USR_FIRSTNAME"],
|
|
|
|
|
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $row2["USR_LASTNAME"]
|
2014-06-06 12:04:30 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Status
|
|
|
|
|
$status = "";
|
|
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
$rsCriteria2 = $case->getTotalAndMinDateForACase($applicationUid, $row["TAS_UID"]);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
$rsCriteria2->next();
|
|
|
|
|
|
|
|
|
|
$row2 = $rsCriteria2->getRow();
|
|
|
|
|
|
2019-02-19 14:30:46 -04:00
|
|
|
$rsCriteria3 = $case->getDelegationFinishDate($applicationUid, $row["TAS_UID"]);
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
$rsCriteria3->next();
|
|
|
|
|
|
|
|
|
|
$row3 = $rsCriteria3->getRow();
|
|
|
|
|
|
|
|
|
|
if ($row3) {
|
|
|
|
|
$row2["FINISH"] = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Status
|
|
|
|
|
if (empty($row2["FINISH"]) && !is_null($taskUid) && $row["TAS_UID"] == $taskUid) {
|
|
|
|
|
$status = "TASK_IN_PROGRESS"; //Red
|
|
|
|
|
} else {
|
|
|
|
|
if (!empty($row2["FINISH"])) {
|
|
|
|
|
$status = "TASK_COMPLETED"; //Green
|
2014-05-13 16:13:18 -04:00
|
|
|
} else {
|
2014-06-06 12:04:30 -04:00
|
|
|
if ($routeType != "SEC-JOIN") {
|
|
|
|
|
if ($row2["CANT"] != 0) {
|
|
|
|
|
$status = "TASK_IN_PROGRESS"; //Red
|
2014-05-13 16:13:18 -04:00
|
|
|
} else {
|
2014-06-06 12:04:30 -04:00
|
|
|
$status = "TASK_PENDING_NOT_EXECUTED"; //Gray
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2014-06-06 12:04:30 -04:00
|
|
|
//$status = "TASK_PARALLEL"; //Yellow
|
|
|
|
|
|
|
|
|
|
if ($row3) {
|
|
|
|
|
$status = "TASK_IN_PROGRESS"; //Red
|
2014-05-13 16:13:18 -04:00
|
|
|
} else {
|
2014-06-06 12:04:30 -04:00
|
|
|
$status = "TASK_PENDING_NOT_EXECUTED"; //Gray
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
//Set data
|
|
|
|
|
$arrayAux = $this->getTaskDataFromRecord($row);
|
|
|
|
|
$arrayAux[$this->getFieldNameByFormatFieldName("ROUTE")][$this->getFieldNameByFormatFieldName("TYPE")] = $routeType;
|
|
|
|
|
$arrayAux[$this->getFieldNameByFormatFieldName("ROUTE")][$this->getFieldNameByFormatFieldName("TO")] = $arrayRoute;
|
|
|
|
|
$arrayAux[$this->getFieldNameByFormatFieldName("DELEGATIONS")] = $arrayAppDelegation;
|
|
|
|
|
$arrayAux[$this->getFieldNameByFormatFieldName("STATUS")] = $status;
|
|
|
|
|
|
|
|
|
|
$arrayTask[] = $arrayAux;
|
2014-05-13 16:13:18 -04:00
|
|
|
}
|
2014-06-06 12:04:30 -04:00
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayTask;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2014-05-13 16:13:18 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-08 15:46:13 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Put execute triggers
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
* @param string $app_uid , Uid for case
|
2015-01-10 11:20:08 -04:00
|
|
|
* @param int $del_index , Index for case
|
2015-01-09 11:48:36 -04:00
|
|
|
* @param string $obj_type , Index for case
|
|
|
|
|
* @param string $obj_uid , Index for case
|
2015-01-08 15:46:13 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return void
|
2015-01-08 15:46:13 -04:00
|
|
|
*/
|
2015-01-09 15:28:20 -04:00
|
|
|
public function putExecuteTriggers($app_uid, $del_index, $obj_type, $obj_uid)
|
2015-01-08 15:46:13 -04:00
|
|
|
{
|
|
|
|
|
Validator::isString($app_uid, '$app_uid');
|
|
|
|
|
Validator::appUid($app_uid, '$app_uid');
|
|
|
|
|
Validator::isInteger($del_index, '$del_index');
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCase = new ClassesCases();
|
2015-01-08 15:46:13 -04:00
|
|
|
$aField = $oCase->loadCase($app_uid, $del_index);
|
2017-10-05 14:54:41 -04:00
|
|
|
$tas_uid = $aField["TAS_UID"];
|
2015-01-08 15:46:13 -04:00
|
|
|
|
2015-01-09 11:48:36 -04:00
|
|
|
$aField["APP_DATA"] = $oCase->executeTriggers($tas_uid, $obj_type, $obj_uid, "AFTER", $aField["APP_DATA"]);
|
|
|
|
|
$aField = $oCase->updateCase($app_uid, $aField);
|
2015-01-08 15:46:13 -04:00
|
|
|
}
|
2015-01-10 10:12:08 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Steps evaluate
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $app_uid , Uid for case
|
2015-01-10 10:12:08 -04:00
|
|
|
* @param int $del_index , Index for case
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array
|
2015-01-10 10:12:08 -04:00
|
|
|
*/
|
|
|
|
|
public function getSteps($app_uid, $del_index)
|
|
|
|
|
{
|
|
|
|
|
Validator::isString($app_uid, '$app_uid');
|
|
|
|
|
Validator::appUid($app_uid, '$app_uid');
|
|
|
|
|
Validator::isInteger($del_index, '$del_index');
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCase = new ClassesCases();
|
2015-01-10 10:12:08 -04:00
|
|
|
$aCaseField = $oCase->loadCase($app_uid, $del_index);
|
2017-10-05 14:54:41 -04:00
|
|
|
$tas_uid = $aCaseField["TAS_UID"];
|
|
|
|
|
$pro_uid = $aCaseField["PRO_UID"];
|
2015-01-10 10:12:08 -04:00
|
|
|
|
2017-08-11 12:33:30 -04:00
|
|
|
$oApplication = new Applications();
|
2015-01-10 10:12:08 -04:00
|
|
|
$aField = $oApplication->getSteps($app_uid, $del_index, $tas_uid, $pro_uid);
|
|
|
|
|
|
2015-01-10 12:05:27 -04:00
|
|
|
return $aField;
|
2015-01-10 10:12:08 -04:00
|
|
|
}
|
2015-02-21 15:59:12 -04:00
|
|
|
|
2018-01-04 09:58:45 -04:00
|
|
|
/**
|
|
|
|
|
* This function get the status information
|
|
|
|
|
*
|
2021-08-02 13:06:17 -04:00
|
|
|
* @param array $result
|
|
|
|
|
* @param string $status
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-08-02 13:06:17 -04:00
|
|
|
private function getStatusInfoFormatted(array $result, string $status = '')
|
2016-06-07 16:52:49 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2021-08-02 13:06:17 -04:00
|
|
|
$record = head($result);
|
|
|
|
|
$arrayData = [
|
|
|
|
|
'APP_STATUS' => empty($status) ? $record['APP_STATUS'] : $status,
|
|
|
|
|
'DEL_INDEX' => [],
|
|
|
|
|
'PRO_UID' => $record['PRO_UID']
|
|
|
|
|
];
|
|
|
|
|
foreach ($result as $record) {
|
2016-06-07 16:52:49 -04:00
|
|
|
$arrayData['DEL_INDEX'][] = $record['DEL_INDEX'];
|
|
|
|
|
}
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayData;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2016-06-07 16:52:49 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-10 10:07:22 -04:00
|
|
|
/**
|
|
|
|
|
* Get status info Case
|
|
|
|
|
*
|
2021-08-02 13:06:17 -04:00
|
|
|
* @param string $appUid Unique id of Case
|
|
|
|
|
* @param int $index Delegation index
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $userUid Unique id of User
|
2015-04-10 10:07:22 -04:00
|
|
|
*
|
2016-06-07 16:52:49 -04:00
|
|
|
* @return array Return an array with status info Case, array empty otherwise
|
2018-01-04 09:58:45 -04:00
|
|
|
* @throws Exception
|
2019-05-20 13:23:31 -04:00
|
|
|
*
|
|
|
|
|
* @see workflow/engine/methods/cases/main_init.php
|
|
|
|
|
* @see workflow/engine/methods/cases/opencase.php
|
2021-08-02 13:06:17 -04:00
|
|
|
* @see \ProcessMaker\BusinessModel\Cases::setCaseVariables()
|
|
|
|
|
* @see \ProcessMaker\BusinessModel\Cases\InputDocument::getCasesInputDocuments()
|
|
|
|
|
* @see \ProcessMaker\BusinessModel\Cases\InputDocument::throwExceptionIfHaventPermissionToDelete()
|
|
|
|
|
* @see \ProcessMaker\BusinessModel\Cases\OutputDocument::throwExceptionIfCaseNotIsInInbox()
|
|
|
|
|
* @see \ProcessMaker\BusinessModel\Cases\OutputDocument::throwExceptionIfHaventPermissionToDelete()
|
2015-04-10 10:07:22 -04:00
|
|
|
*/
|
2021-08-02 13:06:17 -04:00
|
|
|
public function getStatusInfo(string $appUid, int $index = 0, string $userUid = "")
|
2015-04-10 10:07:22 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2021-08-02 13:06:17 -04:00
|
|
|
$arrayData = [];
|
|
|
|
|
// Verify data
|
|
|
|
|
$this->throwExceptionIfNotExistsCase($appUid, $index, $this->getFieldNameByFormatFieldName("APP_UID"));
|
|
|
|
|
// Get the case number
|
|
|
|
|
$caseNumber = ModelApplication::getCaseNumber($appUid);
|
|
|
|
|
// Status is PAUSED
|
|
|
|
|
$result = Delay::getPaused($caseNumber, $index, $userUid);
|
|
|
|
|
if (!empty($result)) {
|
|
|
|
|
$arrayData = $this->getStatusInfoFormatted($result, 'PAUSED');
|
2016-06-07 16:52:49 -04:00
|
|
|
return $arrayData;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-02 13:06:17 -04:00
|
|
|
// Status is UNASSIGNED
|
|
|
|
|
$query = Delegation::query()->select([
|
|
|
|
|
'APP_DELEGATION.APP_NUMBER',
|
|
|
|
|
'APP_DELEGATION.DEL_INDEX',
|
|
|
|
|
'APP_DELEGATION.PRO_UID'
|
|
|
|
|
]);
|
|
|
|
|
$query->taskAssignType('SELF_SERVICE');
|
|
|
|
|
$query->threadOpen()->withoutUserId();
|
|
|
|
|
// Filter specific user
|
|
|
|
|
if (!empty($userUid)) {
|
|
|
|
|
$delegation = new Delegation();
|
|
|
|
|
$delegation->casesUnassigned($query, $userUid);
|
|
|
|
|
}
|
|
|
|
|
// Filter specific case
|
|
|
|
|
$query->case($caseNumber);
|
|
|
|
|
// Filter specific index
|
2022-06-22 16:05:04 +00:00
|
|
|
if ($index > 0) {
|
2021-08-02 13:06:17 -04:00
|
|
|
$query->index($index);
|
|
|
|
|
}
|
|
|
|
|
$results = $query->get();
|
|
|
|
|
$arrayData = $results->values()->toArray();
|
2016-06-07 16:52:49 -04:00
|
|
|
if (!empty($arrayData)) {
|
2021-08-02 13:06:17 -04:00
|
|
|
$arrayData = $this->getStatusInfoFormatted($arrayData, 'UNASSIGNED');
|
2016-06-07 16:52:49 -04:00
|
|
|
return $arrayData;
|
2015-04-10 10:07:22 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-02 13:06:17 -04:00
|
|
|
// Status is TO_DO, DRAFT
|
|
|
|
|
$query = Delegation::query()->select([
|
|
|
|
|
'APPLICATION.APP_STATUS',
|
|
|
|
|
'APP_DELEGATION.APP_NUMBER',
|
|
|
|
|
'APP_DELEGATION.DEL_INDEX',
|
|
|
|
|
'APP_DELEGATION.PRO_UID'
|
|
|
|
|
]);
|
|
|
|
|
$query->joinApplication();
|
|
|
|
|
// Filter the status TO_DO and DRAFT
|
|
|
|
|
$query->casesInProgress([1, 2]);
|
|
|
|
|
// Filter the OPEN thread
|
|
|
|
|
$query->threadOpen();
|
|
|
|
|
// Filter specific case
|
|
|
|
|
$query->case($caseNumber);
|
|
|
|
|
// Filter specific index
|
|
|
|
|
if ($index > 0) {
|
|
|
|
|
$query->index($index);
|
|
|
|
|
}
|
|
|
|
|
// Filter specific user
|
|
|
|
|
if (!empty($userUid)) {
|
|
|
|
|
$userId = !empty($userUid) ? User::getId($userUid) : 0;
|
|
|
|
|
$query->userId($userId);
|
|
|
|
|
}
|
|
|
|
|
$results = $query->get();
|
|
|
|
|
$arrayData = $results->values()->toArray();
|
2015-04-10 10:07:22 -04:00
|
|
|
|
2016-06-07 16:52:49 -04:00
|
|
|
if (!empty($arrayData)) {
|
2021-08-02 13:06:17 -04:00
|
|
|
$arrayData = $this->getStatusInfoFormatted($arrayData);
|
2016-06-07 16:52:49 -04:00
|
|
|
return $arrayData;
|
2015-04-10 10:07:22 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-02 13:06:17 -04:00
|
|
|
// Status is CANCELLED, COMPLETED
|
|
|
|
|
$query = Delegation::query()->select([
|
|
|
|
|
'APPLICATION.APP_STATUS',
|
|
|
|
|
'APP_DELEGATION.APP_NUMBER',
|
|
|
|
|
'APP_DELEGATION.DEL_INDEX',
|
|
|
|
|
'APP_DELEGATION.PRO_UID'
|
|
|
|
|
]);
|
|
|
|
|
$query->joinApplication();
|
|
|
|
|
// Filter the status COMPLETED and CANCELLED
|
|
|
|
|
$query->casesDone([3, 4]);
|
|
|
|
|
// Filter specific case
|
|
|
|
|
$query->case($caseNumber);
|
|
|
|
|
// Filter specific index
|
|
|
|
|
if ($index > 0) {
|
|
|
|
|
$query->index($index);
|
|
|
|
|
}
|
|
|
|
|
// Filter specific user
|
|
|
|
|
if (!empty($userUid)) {
|
|
|
|
|
$userId = !empty($userUid) ? User::getId($userUid) : 0;
|
|
|
|
|
$query->userId($userId);
|
|
|
|
|
}
|
|
|
|
|
$query->lastThread();
|
|
|
|
|
$results = $query->get();
|
|
|
|
|
$arrayData = $results->values()->toArray();
|
2016-06-07 16:52:49 -04:00
|
|
|
if (!empty($arrayData)) {
|
2021-08-02 13:06:17 -04:00
|
|
|
$arrayData = $this->getStatusInfoFormatted($arrayData);
|
2016-06-07 16:52:49 -04:00
|
|
|
return $arrayData;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-02 13:06:17 -04:00
|
|
|
// Status is PARTICIPATED
|
|
|
|
|
$arrayData = Delegation::getParticipatedInfo($appUid);
|
2016-06-07 16:52:49 -04:00
|
|
|
if (!empty($arrayData)) {
|
|
|
|
|
return $arrayData;
|
2015-04-10 10:07:22 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-02 13:06:17 -04:00
|
|
|
return $arrayData;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2015-04-10 10:07:22 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-05 14:56:45 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get process list for start case
|
|
|
|
|
*
|
|
|
|
|
* @param string $usrUid id of user
|
|
|
|
|
* @param string $typeView type of view
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array Return an array with process list that the user can start.
|
2022-09-29 09:51:33 -04:00
|
|
|
* @throws RestException
|
2015-11-05 14:56:45 -04:00
|
|
|
*/
|
|
|
|
|
public function getCasesListStarCase($usrUid, $typeView)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
2015-11-05 14:56:45 -04:00
|
|
|
$response = $case->getProcessListStartCase($usrUid, $typeView);
|
|
|
|
|
|
|
|
|
|
return $response;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2015-11-05 14:56:45 -04:00
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get process list bookmark for start case
|
|
|
|
|
*
|
|
|
|
|
* @param string $usrUid id of user
|
|
|
|
|
* @param string $typeView type of view
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return array Return an array with process list that the user can start.
|
|
|
|
|
* @throws Exception
|
2015-11-05 14:56:45 -04:00
|
|
|
*/
|
|
|
|
|
public function getCasesListBookmarkStarCase($usrUid, $typeView)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Validator::usrUid($usrUid, '$usr_uid');
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$user = new ModelUsers();
|
2015-11-05 14:56:45 -04:00
|
|
|
$fields = $user->load($usrUid);
|
|
|
|
|
$bookmark = empty($fields['USR_BOOKMARK_START_CASES']) ? array() : unserialize($fields['USR_BOOKMARK_START_CASES']);
|
|
|
|
|
|
|
|
|
|
//Getting group id and adding the user id
|
2017-10-05 14:54:41 -04:00
|
|
|
$group = new Groups();
|
2015-11-05 14:56:45 -04:00
|
|
|
$groups = $group->getActiveGroupsForAnUser($usrUid);
|
|
|
|
|
$groups[] = $usrUid;
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$c = new Criteria();
|
2015-11-05 14:56:45 -04:00
|
|
|
$c->clearSelectColumns();
|
2017-10-05 14:54:41 -04:00
|
|
|
$c->addSelectColumn(TaskPeer::TAS_UID);
|
|
|
|
|
$c->addSelectColumn(TaskPeer::TAS_TITLE);
|
|
|
|
|
$c->addSelectColumn(TaskPeer::PRO_UID);
|
|
|
|
|
$c->addSelectColumn(ProcessPeer::PRO_TITLE);
|
|
|
|
|
$c->addJoin(TaskPeer::PRO_UID, ProcessPeer::PRO_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$c->addJoin(TaskPeer::TAS_UID, TaskUserPeer::TAS_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$c->add(ProcessPeer::PRO_STATUS, 'ACTIVE');
|
|
|
|
|
$c->add(TaskPeer::TAS_START, 'TRUE');
|
|
|
|
|
$c->add(TaskUserPeer::USR_UID, $groups, Criteria::IN);
|
|
|
|
|
$c->add(TaskPeer::TAS_UID, $bookmark, Criteria::IN);
|
2015-11-05 14:56:45 -04:00
|
|
|
|
|
|
|
|
if ($typeView == 'category') {
|
|
|
|
|
$c->addAsColumn('PRO_CATEGORY', 'PCS.PRO_CATEGORY');
|
|
|
|
|
$c->addAsColumn('CATEGORY_NAME', 'PCSCAT.CATEGORY_NAME');
|
|
|
|
|
$c->addAlias('PCS', 'PROCESS');
|
|
|
|
|
$c->addAlias('PCSCAT', 'PROCESS_CATEGORY');
|
|
|
|
|
$aConditions = array();
|
2017-10-05 14:54:41 -04:00
|
|
|
$aConditions[] = array(TaskPeer::PRO_UID, 'PCS.PRO_UID');
|
|
|
|
|
$c->addJoinMC($aConditions, Criteria::LEFT_JOIN);
|
2015-11-05 14:56:45 -04:00
|
|
|
$aConditions = array();
|
|
|
|
|
$aConditions[] = array('PCS.PRO_CATEGORY', 'PCSCAT.CATEGORY_UID');
|
2017-10-05 14:54:41 -04:00
|
|
|
$c->addJoinMC($aConditions, Criteria::LEFT_JOIN);
|
2015-11-05 14:56:45 -04:00
|
|
|
}
|
2015-11-20 11:25:34 -04:00
|
|
|
$c->setDistinct();
|
2017-10-05 14:54:41 -04:00
|
|
|
$rs = TaskPeer::doSelectRS($c);
|
2015-11-05 14:56:45 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2015-11-05 14:56:45 -04:00
|
|
|
$processList = array();
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
if ($typeView == 'category') {
|
|
|
|
|
$processList[] = array(
|
|
|
|
|
'tas_uid' => $row['TAS_UID'],
|
|
|
|
|
'pro_title' => $row['PRO_TITLE'] . '(' . $row['TAS_TITLE'] . ')',
|
|
|
|
|
'pro_uid' => $row['PRO_UID'],
|
|
|
|
|
'pro_category' => $row['PRO_CATEGORY'],
|
|
|
|
|
'category_name' => $row['CATEGORY_NAME']
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$processList[] = array(
|
|
|
|
|
'tas_uid' => $row['TAS_UID'],
|
|
|
|
|
'pro_title' => $row['PRO_TITLE'] . '(' . $row['TAS_TITLE'] . ')',
|
|
|
|
|
'pro_uid' => $row['PRO_UID']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (count($processList) == 0) {
|
|
|
|
|
$processList['success'] = 'failure';
|
2015-12-09 11:18:05 -04:00
|
|
|
$processList['message'] = G::LoadTranslation('ID_NOT_HAVE_BOOKMARKED_PROCESSES');
|
2015-11-05 14:56:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $processList;
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2015-11-05 14:56:45 -04:00
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Users to reassign
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $userUid Unique id of User (User logged)
|
|
|
|
|
* @param string $taskUid Unique id of Task
|
|
|
|
|
* @param array $arrayFilterData Data of the filters
|
|
|
|
|
* @param string $sortField Field name to sort
|
|
|
|
|
* @param string $sortDir Direction of sorting (ASC, DESC)
|
|
|
|
|
* @param int $start Start
|
|
|
|
|
* @param int $limit Limit
|
2016-01-11 17:36:00 -04:00
|
|
|
*
|
|
|
|
|
* @return array Return Users to reassign
|
2018-01-04 09:58:45 -04:00
|
|
|
* @throws Exception
|
2016-01-11 17:36:00 -04:00
|
|
|
*/
|
2017-10-05 14:54:41 -04:00
|
|
|
public function getUsersToReassign(
|
|
|
|
|
$userUid,
|
|
|
|
|
$taskUid,
|
|
|
|
|
$arrayFilterData = null,
|
|
|
|
|
$sortField = null,
|
|
|
|
|
$sortDir = null,
|
|
|
|
|
$start = null,
|
|
|
|
|
$limit = null
|
|
|
|
|
) {
|
2016-01-11 17:36:00 -04:00
|
|
|
try {
|
|
|
|
|
$arrayUser = [];
|
|
|
|
|
|
|
|
|
|
$numRecTotal = 0;
|
|
|
|
|
|
|
|
|
|
//Set variables
|
2017-10-05 14:54:41 -04:00
|
|
|
$task = TaskPeer::retrieveByPK($taskUid);
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
$processUid = $task->getProUid();
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$user = new BmUser();
|
|
|
|
|
$task = new ClassesTasks();
|
|
|
|
|
$group = new Groups();
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
//Set variables
|
|
|
|
|
$filterName = 'filter';
|
|
|
|
|
|
|
|
|
|
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter'])) {
|
|
|
|
|
$arrayAux = [
|
2017-10-05 14:54:41 -04:00
|
|
|
'' => 'filter',
|
|
|
|
|
'LEFT' => 'lfilter',
|
2016-01-11 17:36:00 -04:00
|
|
|
'RIGHT' => 'rfilter'
|
|
|
|
|
];
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$filterName = $arrayAux[(isset($arrayFilterData['filterOption'])) ? $arrayFilterData['filterOption'] : ''];
|
2016-01-11 17:36:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Get data
|
|
|
|
|
if (!is_null($limit) && $limit . '' == '0') {
|
|
|
|
|
//Return
|
|
|
|
|
return [
|
2017-10-05 14:54:41 -04:00
|
|
|
'total' => $numRecTotal,
|
|
|
|
|
'start' => (int)((!is_null($start)) ? $start : 0),
|
|
|
|
|
'limit' => (int)((!is_null($limit)) ? $limit : 0),
|
|
|
|
|
$filterName => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter'])) ? $arrayFilterData['filter'] : '',
|
|
|
|
|
'data' => $arrayUser
|
2016-01-11 17:36:00 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Set variables
|
2017-10-05 14:54:41 -04:00
|
|
|
$processSupervisor = new BmProcessSupervisor();
|
2016-01-11 17:36:00 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$arrayResult = $processSupervisor->getProcessSupervisors($processUid, 'ASSIGNED', null, null, null,
|
|
|
|
|
'group');
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
$arrayGroupUid = array_merge(
|
2017-10-05 14:54:41 -04:00
|
|
|
array_map(function ($value) {
|
|
|
|
|
return $value['GRP_UID'];
|
|
|
|
|
}, $task->getGroupsOfTask($taskUid, 1)), //Groups
|
|
|
|
|
array_map(function ($value) {
|
|
|
|
|
return $value['GRP_UID'];
|
|
|
|
|
}, $task->getGroupsOfTask($taskUid, 2)), //AdHoc Groups
|
|
|
|
|
array_map(function ($value) {
|
|
|
|
|
return $value['grp_uid'];
|
|
|
|
|
}, $arrayResult['data']) //ProcessSupervisor Groups
|
2016-01-11 17:36:00 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$sqlTaskUser = '
|
2017-10-05 14:54:41 -04:00
|
|
|
SELECT ' . TaskUserPeer::USR_UID . '
|
|
|
|
|
FROM ' . TaskUserPeer::TABLE_NAME . '
|
|
|
|
|
WHERE ' . TaskUserPeer::TAS_UID . ' = \'%s\' AND
|
|
|
|
|
' . TaskUserPeer::TU_TYPE . ' IN (1, 2) AND
|
|
|
|
|
' . TaskUserPeer::TU_RELATION . ' = 1
|
2016-01-11 17:36:00 -04:00
|
|
|
';
|
|
|
|
|
|
|
|
|
|
$sqlGroupUser = '
|
2017-10-05 14:54:41 -04:00
|
|
|
SELECT ' . GroupUserPeer::USR_UID . '
|
|
|
|
|
FROM ' . GroupUserPeer::TABLE_NAME . '
|
|
|
|
|
WHERE ' . GroupUserPeer::GRP_UID . ' IN (%s)
|
2016-01-11 17:36:00 -04:00
|
|
|
';
|
|
|
|
|
|
|
|
|
|
$sqlProcessSupervisor = '
|
2017-10-05 14:54:41 -04:00
|
|
|
SELECT ' . ProcessUserPeer::USR_UID . '
|
|
|
|
|
FROM ' . ProcessUserPeer::TABLE_NAME . '
|
|
|
|
|
WHERE ' . ProcessUserPeer::PRO_UID . ' = \'%s\' AND
|
|
|
|
|
' . ProcessUserPeer::PU_TYPE . ' = \'%s\'
|
2016-01-11 17:36:00 -04:00
|
|
|
';
|
|
|
|
|
|
|
|
|
|
$sqlUserToReassign = '(' . sprintf($sqlTaskUser, $taskUid) . ')';
|
|
|
|
|
|
|
|
|
|
if (!empty($arrayGroupUid)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$sqlUserToReassign .= ' UNION (' . sprintf($sqlGroupUser,
|
|
|
|
|
'\'' . implode('\', \'', $arrayGroupUid) . '\'') . ')';
|
2016-01-11 17:36:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sqlUserToReassign .= ' UNION (' . sprintf($sqlProcessSupervisor, $processUid, 'SUPERVISOR') . ')';
|
|
|
|
|
|
|
|
|
|
//Query
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria = new Criteria('workflow');
|
2016-01-11 17:36:00 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->addSelectColumn(UsersPeer::USR_UID);
|
|
|
|
|
$criteria->addSelectColumn(UsersPeer::USR_USERNAME);
|
|
|
|
|
$criteria->addSelectColumn(UsersPeer::USR_FIRSTNAME);
|
|
|
|
|
$criteria->addSelectColumn(UsersPeer::USR_LASTNAME);
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
$criteria->addAlias('USER_TO_REASSIGN', '(' . $sqlUserToReassign . ')');
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->addJoin(UsersPeer::USR_UID, 'USER_TO_REASSIGN.USR_UID', Criteria::INNER_JOIN);
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter']) && trim($arrayFilterData['filter']) != '') {
|
|
|
|
|
$arraySearch = [
|
2017-10-05 14:54:41 -04:00
|
|
|
'' => '%' . $arrayFilterData['filter'] . '%',
|
|
|
|
|
'LEFT' => $arrayFilterData['filter'] . '%',
|
2016-01-11 17:36:00 -04:00
|
|
|
'RIGHT' => '%' . $arrayFilterData['filter']
|
|
|
|
|
];
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$search = $arraySearch[(isset($arrayFilterData['filterOption'])) ? $arrayFilterData['filterOption'] : ''];
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
$criteria->add(
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->getNewCriterion(UsersPeer::USR_USERNAME, $search, Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion(UsersPeer::USR_FIRSTNAME, $search, Criteria::LIKE))->addOr(
|
|
|
|
|
$criteria->getNewCriterion(UsersPeer::USR_LASTNAME, $search, Criteria::LIKE))
|
2016-01-11 17:36:00 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->add(UsersPeer::USR_STATUS, 'ACTIVE', Criteria::EQUAL);
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
if (!$user->checkPermission($userUid, 'PM_SUPERVISOR')) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->add(UsersPeer::USR_UID, $userUid, Criteria::NOT_EQUAL);
|
2016-01-11 17:36:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Number records total
|
2017-10-05 14:54:41 -04:00
|
|
|
$numRecTotal = UsersPeer::doCount($criteria);
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
//Query
|
2017-10-05 14:54:41 -04:00
|
|
|
$conf = new Configurations();
|
|
|
|
|
$sortFieldDefault = UsersPeer::TABLE_NAME . '.' . $conf->userNameFormatGetFirstFieldByUsersTable();
|
2016-03-18 16:49:33 -04:00
|
|
|
|
2016-01-11 17:36:00 -04:00
|
|
|
if (!is_null($sortField) && trim($sortField) != '') {
|
|
|
|
|
$sortField = strtoupper($sortField);
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
if (in_array(UsersPeer::TABLE_NAME . '.' . $sortField, $criteria->getSelectColumns())) {
|
|
|
|
|
$sortField = UsersPeer::TABLE_NAME . '.' . $sortField;
|
2016-01-11 17:36:00 -04:00
|
|
|
} else {
|
2016-03-18 16:49:33 -04:00
|
|
|
$sortField = $sortFieldDefault;
|
2016-01-11 17:36:00 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-18 16:49:33 -04:00
|
|
|
$sortField = $sortFieldDefault;
|
2016-01-11 17:36:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_null($sortDir) && trim($sortDir) != '' && strtoupper($sortDir) == 'DESC') {
|
|
|
|
|
$criteria->addDescendingOrderByColumn($sortField);
|
|
|
|
|
} else {
|
|
|
|
|
$criteria->addAscendingOrderByColumn($sortField);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_null($start)) {
|
|
|
|
|
$criteria->setOffset((int)($start));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_null($limit)) {
|
|
|
|
|
$criteria->setLimit((int)($limit));
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
$rsCriteria = UsersPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2016-01-11 17:36:00 -04:00
|
|
|
|
|
|
|
|
while ($rsCriteria->next()) {
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$arrayUser[] = $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return [
|
2017-10-05 14:54:41 -04:00
|
|
|
'total' => $numRecTotal,
|
|
|
|
|
'start' => (int)((!is_null($start)) ? $start : 0),
|
|
|
|
|
'limit' => (int)((!is_null($limit)) ? $limit : 0),
|
|
|
|
|
$filterName => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData['filter'])) ? $arrayFilterData['filter'] : '',
|
|
|
|
|
'data' => $arrayUser
|
2016-01-11 17:36:00 -04:00
|
|
|
];
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2016-01-11 17:36:00 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-15 14:51:44 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Batch reassign
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return json Return an json with the result of the reassigned cases.
|
2016-06-15 14:51:44 -04:00
|
|
|
*/
|
2017-01-05 16:13:53 -04:00
|
|
|
|
2016-06-15 14:51:44 -04:00
|
|
|
public function doPostReassign($data)
|
|
|
|
|
{
|
2016-08-13 11:19:02 -04:00
|
|
|
if (!is_array($data)) {
|
2016-06-15 14:51:44 -04:00
|
|
|
$isJson = is_string($data) && is_array(G::json_decode($data, true)) ? true : false;
|
2016-08-13 11:19:02 -04:00
|
|
|
if ($isJson) {
|
2016-06-15 14:51:44 -04:00
|
|
|
$data = G::json_decode($data, true);
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$dataResponse = $data;
|
|
|
|
|
$casesToReassign = $data['cases'];
|
2017-10-05 14:54:41 -04:00
|
|
|
$oCases = new ClassesCases();
|
2017-01-05 16:13:53 -04:00
|
|
|
foreach ($casesToReassign as $key => $val) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$appDelegation = AppDelegationPeer::retrieveByPK($val['APP_UID'], $val['DEL_INDEX']);
|
2017-01-05 16:13:53 -04:00
|
|
|
$existDelegation = $this->validateReassignData($appDelegation, $val, $data, 'DELEGATION_NOT_EXISTS');
|
|
|
|
|
if ($existDelegation) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$existDelegation = $this->validateReassignData($appDelegation, $val, $data,
|
|
|
|
|
'USER_NOT_ASSIGNED_TO_TASK');
|
2017-01-05 16:13:53 -04:00
|
|
|
if ($existDelegation) {
|
|
|
|
|
$usrUid = '';
|
|
|
|
|
if (array_key_exists('USR_UID', $val)) {
|
|
|
|
|
if ($val['USR_UID'] != '') {
|
|
|
|
|
$usrUid = $val['USR_UID'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($usrUid == '') {
|
2017-10-05 14:54:41 -04:00
|
|
|
$fields = $appDelegation->toArray(BasePeer::TYPE_FIELDNAME);
|
2017-01-05 16:13:53 -04:00
|
|
|
$usrUid = $fields['USR_UID'];
|
|
|
|
|
}
|
|
|
|
|
//Will be not able reassign a case when is paused
|
2017-10-05 14:54:41 -04:00
|
|
|
$flagPaused = $this->validateReassignData($appDelegation, $val, $data,
|
|
|
|
|
'ID_REASSIGNMENT_PAUSED_ERROR');
|
2017-01-05 16:13:53 -04:00
|
|
|
//Current users of OPEN DEL_INDEX thread
|
2017-10-05 14:54:41 -04:00
|
|
|
$flagSameUser = $this->validateReassignData($appDelegation, $val, $data,
|
|
|
|
|
'REASSIGNMENT_TO_THE_SAME_USER');
|
2017-01-05 16:13:53 -04:00
|
|
|
//reassign case
|
|
|
|
|
if ($flagPaused && $flagSameUser) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$reassigned = $oCases->reassignCase($val['APP_UID'], $val['DEL_INDEX'], $usrUid,
|
|
|
|
|
$data['usr_uid_target']);
|
2017-01-05 16:13:53 -04:00
|
|
|
$result = $reassigned ? 1 : 0;
|
|
|
|
|
$this->messageResponse = [
|
|
|
|
|
'APP_UID' => $val['APP_UID'],
|
|
|
|
|
'DEL_INDEX' => $val['DEL_INDEX'],
|
|
|
|
|
'RESULT' => $result,
|
|
|
|
|
'STATUS' => 'SUCCESS'
|
|
|
|
|
];
|
2016-06-15 14:51:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
2017-01-05 16:13:53 -04:00
|
|
|
}
|
|
|
|
|
$dataResponse['cases'][$key] = $this->messageResponse;
|
|
|
|
|
}
|
|
|
|
|
unset($dataResponse['usr_uid_target']);
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-01-05 16:13:53 -04:00
|
|
|
return G::json_encode($dataResponse);
|
|
|
|
|
}
|
2016-06-15 14:51:44 -04:00
|
|
|
|
2017-01-05 16:13:53 -04:00
|
|
|
/**
|
|
|
|
|
* @param $appDelegation
|
|
|
|
|
* @param $value
|
|
|
|
|
* @param $data
|
|
|
|
|
* @param string $type
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2017-01-05 16:13:53 -04:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private function validateReassignData($appDelegation, $value, $data, $type = 'DELEGATION_NOT_EXISTS')
|
|
|
|
|
{
|
|
|
|
|
$return = true;
|
|
|
|
|
switch ($type) {
|
|
|
|
|
case 'DELEGATION_NOT_EXISTS':
|
|
|
|
|
if (is_null($appDelegation)) {
|
|
|
|
|
$this->messageResponse = [
|
|
|
|
|
'APP_UID' => $value['APP_UID'],
|
|
|
|
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
|
|
|
|
'RESULT' => 0,
|
|
|
|
|
'STATUS' => $type
|
|
|
|
|
];
|
|
|
|
|
$return = false;
|
2016-06-15 14:51:44 -04:00
|
|
|
}
|
2017-01-05 16:13:53 -04:00
|
|
|
break;
|
|
|
|
|
case 'USER_NOT_ASSIGNED_TO_TASK':
|
2017-10-05 14:54:41 -04:00
|
|
|
$task = new BmTask();
|
|
|
|
|
$supervisor = new BmProcessSupervisor();
|
2017-01-05 16:13:53 -04:00
|
|
|
$taskUid = $appDelegation->getTasUid();
|
|
|
|
|
$flagBoolean = $task->checkUserOrGroupAssignedTask($taskUid, $data['usr_uid_target']);
|
|
|
|
|
$flagps = $supervisor->isUserProcessSupervisor($appDelegation->getProUid(), $data['usr_uid_target']);
|
|
|
|
|
|
|
|
|
|
if (!$flagBoolean && !$flagps) {
|
|
|
|
|
$this->messageResponse = [
|
|
|
|
|
'APP_UID' => $value['APP_UID'],
|
|
|
|
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
|
|
|
|
'RESULT' => 0,
|
|
|
|
|
'STATUS' => 'USER_NOT_ASSIGNED_TO_TASK'
|
|
|
|
|
];
|
|
|
|
|
$return = false;
|
2016-08-12 18:26:57 -04:00
|
|
|
}
|
2017-01-05 16:13:53 -04:00
|
|
|
break;
|
|
|
|
|
case 'ID_REASSIGNMENT_PAUSED_ERROR':
|
2017-10-05 14:54:41 -04:00
|
|
|
if (AppDelay::isPaused($value['APP_UID'], $value['DEL_INDEX'])) {
|
2017-01-05 16:13:53 -04:00
|
|
|
$this->messageResponse = [
|
|
|
|
|
'APP_UID' => $value['APP_UID'],
|
|
|
|
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
|
|
|
|
'RESULT' => 0,
|
2017-10-05 14:54:41 -04:00
|
|
|
'STATUS' => G::LoadTranslation('ID_REASSIGNMENT_PAUSED_ERROR')
|
2017-01-05 16:13:53 -04:00
|
|
|
];
|
|
|
|
|
$return = false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'REASSIGNMENT_TO_THE_SAME_USER':
|
|
|
|
|
$aCurUser = $appDelegation->getCurrentUsers($value['APP_UID'], $value['DEL_INDEX']);
|
2016-08-13 11:19:02 -04:00
|
|
|
if (!empty($aCurUser)) {
|
2017-01-05 16:13:53 -04:00
|
|
|
foreach ($aCurUser as $keyAux => $val) {
|
|
|
|
|
if ($val === $data['usr_uid_target']) {
|
|
|
|
|
$this->messageResponse = [
|
|
|
|
|
'APP_UID' => $value['APP_UID'],
|
|
|
|
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
|
|
|
|
'RESULT' => 1,
|
|
|
|
|
'STATUS' => 'SUCCESS'
|
|
|
|
|
];
|
|
|
|
|
$return = false;
|
2016-08-12 18:26:57 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-08-13 11:19:02 -04:00
|
|
|
} else {
|
2016-08-12 18:26:57 -04:00
|
|
|
//DEL_INDEX is CLOSED
|
2017-01-05 16:13:53 -04:00
|
|
|
$this->messageResponse = [
|
|
|
|
|
'APP_UID' => $value['APP_UID'],
|
|
|
|
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
|
|
|
|
'RESULT' => 0,
|
2017-10-05 14:54:41 -04:00
|
|
|
'STATUS' => G::LoadTranslation('ID_REASSIGNMENT_ERROR')
|
2017-01-05 16:13:53 -04:00
|
|
|
];
|
|
|
|
|
$return = false;
|
2016-08-12 18:26:57 -04:00
|
|
|
}
|
2017-01-05 16:13:53 -04:00
|
|
|
break;
|
2016-06-15 14:51:44 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-01-05 16:13:53 -04:00
|
|
|
return $return;
|
2016-06-15 14:51:44 -04:00
|
|
|
}
|
2016-08-15 09:28:25 -04:00
|
|
|
|
2016-08-10 15:33:49 -04:00
|
|
|
/**
|
2018-01-04 09:58:45 -04:00
|
|
|
* If case already routed
|
|
|
|
|
*
|
|
|
|
|
* @param string $app_uid
|
|
|
|
|
* @param string $del_index
|
|
|
|
|
* @param string $usr_uid
|
2016-08-15 09:28:25 -04:00
|
|
|
*
|
2018-01-04 09:58:45 -04:00
|
|
|
* @return boolean
|
2016-08-10 15:33:49 -04:00
|
|
|
*/
|
|
|
|
|
public function caseAlreadyRouted($app_uid, $del_index, $usr_uid = '')
|
|
|
|
|
{
|
2017-10-05 14:54:41 -04:00
|
|
|
$c = new Criteria('workflow');
|
|
|
|
|
$c->add(AppDelegationPeer::APP_UID, $app_uid);
|
|
|
|
|
$c->add(AppDelegationPeer::DEL_INDEX, $del_index);
|
2016-08-10 15:33:49 -04:00
|
|
|
if (!empty($usr_uid)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$c->add(AppDelegationPeer::USR_UID, $usr_uid);
|
2016-08-10 15:33:49 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
$c->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
|
|
|
|
|
|
|
|
|
|
return !(boolean)AppDelegationPeer::doCount($c);
|
2016-08-10 15:33:49 -04:00
|
|
|
}
|
2016-08-13 13:13:59 -04:00
|
|
|
|
2017-11-07 13:59:59 -04:00
|
|
|
/**
|
|
|
|
|
* This function review if the user has processPermissions or the user is supervisor
|
|
|
|
|
*
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
* @param string $applicationUid
|
|
|
|
|
* @param string $dynaformUid
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
2016-08-13 13:13:59 -04:00
|
|
|
public function checkUserHasPermissionsOrSupervisor($userUid, $applicationUid, $dynaformUid)
|
|
|
|
|
{
|
2017-01-13 11:21:13 -04:00
|
|
|
$arrayApplicationData = $this->getApplicationRecordByPk($applicationUid, [], false);
|
2017-11-07 13:59:59 -04:00
|
|
|
//Get all access for the user, we no consider the permissions
|
|
|
|
|
$userCanAccess = $this->userAuthorization(
|
|
|
|
|
$userUid,
|
|
|
|
|
$arrayApplicationData['PRO_UID'],
|
|
|
|
|
$applicationUid,
|
|
|
|
|
[],
|
|
|
|
|
[],
|
|
|
|
|
true
|
|
|
|
|
);
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-11-07 13:59:59 -04:00
|
|
|
//We need to get all the object permission consider the BLOCK
|
|
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$allObjectPermissions = $case->getAllObjects($arrayApplicationData['PRO_UID'], $applicationUid, '', $userUid);
|
|
|
|
|
|
|
|
|
|
//Check case tracker
|
|
|
|
|
$flagCaseTracker = $case->getAllObjectsTrackerDynaform($arrayApplicationData['PRO_UID'], $dynaformUid);
|
|
|
|
|
|
|
|
|
|
//Review if the user has participated in the case
|
|
|
|
|
//Review if the user is supervisor in the case and if had assign the objectSupervisor
|
|
|
|
|
//Review if the user has process permission SUMMARY FORM
|
|
|
|
|
//Review if the user has process permission DYNAFORM for the specific form
|
|
|
|
|
//Review if the form is configured for case tracker
|
|
|
|
|
return (
|
|
|
|
|
$userCanAccess['participated']
|
|
|
|
|
|| ($userCanAccess['supervisor'] && in_array($dynaformUid, $userCanAccess['objectSupervisor']))
|
|
|
|
|
|| $allObjectPermissions['SUMMARY_FORM']
|
|
|
|
|
|| in_array($dynaformUid, $allObjectPermissions['DYNAFORMS'])
|
|
|
|
|
|| $flagCaseTracker
|
|
|
|
|
);
|
2016-08-13 13:13:59 -04:00
|
|
|
}
|
2016-01-11 17:36:00 -04:00
|
|
|
|
2016-08-15 09:28:25 -04:00
|
|
|
/**
|
|
|
|
|
* Delete MultipleFile in Case data
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param array $arrayApplicationData Case data
|
|
|
|
|
* @param string $variable1 Variable1
|
|
|
|
|
* @param string $variable2 Variable2
|
|
|
|
|
* @param string $type Type (NORMAL, GRID)
|
|
|
|
|
* @param array $arrayDocumentToDelete Document to delete
|
2016-08-15 09:28:25 -04:00
|
|
|
*
|
|
|
|
|
* @return array Returns array with Case data updated
|
|
|
|
|
*/
|
2019-11-27 14:36:31 -04:00
|
|
|
private function applicationDataDeleteMultipleFile(
|
2017-10-05 14:54:41 -04:00
|
|
|
array $arrayApplicationData,
|
|
|
|
|
$variable1,
|
|
|
|
|
$variable2,
|
|
|
|
|
$type,
|
|
|
|
|
array $arrayDocumentToDelete
|
|
|
|
|
) {
|
2016-08-15 09:28:25 -04:00
|
|
|
if (array_key_exists($variable1, $arrayApplicationData) &&
|
|
|
|
|
is_array($arrayApplicationData[$variable1]) && !empty($arrayApplicationData[$variable1])
|
|
|
|
|
) {
|
|
|
|
|
switch ($type) {
|
|
|
|
|
case 'NORMAL':
|
|
|
|
|
$arrayAux = $arrayApplicationData[$variable1];
|
|
|
|
|
$arrayApplicationData[$variable1] = [];
|
|
|
|
|
$keyd = null;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayAux as $key => $value) {
|
|
|
|
|
if ($value['appDocUid'] == $arrayDocumentToDelete['appDocUid'] &&
|
|
|
|
|
(int)($value['version']) == (int)($arrayDocumentToDelete['version'])
|
|
|
|
|
) {
|
|
|
|
|
$keyd = $key;
|
|
|
|
|
} else {
|
|
|
|
|
$arrayApplicationData[$variable1][] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_null($keyd)) {
|
|
|
|
|
$variable1 = $variable1 . '_label';
|
|
|
|
|
|
|
|
|
|
if (array_key_exists($variable1, $arrayApplicationData) &&
|
|
|
|
|
is_array($arrayApplicationData[$variable1]) && !empty($arrayApplicationData[$variable1])
|
|
|
|
|
) {
|
|
|
|
|
$arrayAux = $arrayApplicationData[$variable1];
|
|
|
|
|
$arrayApplicationData[$variable1] = [];
|
|
|
|
|
|
|
|
|
|
foreach ($arrayAux as $key => $value) {
|
|
|
|
|
if ($key != $keyd) {
|
|
|
|
|
$arrayApplicationData[$variable1][] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'GRID':
|
|
|
|
|
foreach ($arrayApplicationData[$variable1] as $key => $value) {
|
|
|
|
|
if (array_key_exists($variable2, $value)) {
|
2019-11-27 14:36:31 -04:00
|
|
|
$arrayApplicationData[$variable1][$key] = $this->applicationDataDeleteMultipleFile(
|
2016-08-15 09:28:25 -04:00
|
|
|
$value, $variable2, null, 'NORMAL', $arrayDocumentToDelete
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayApplicationData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete MultipleFile
|
|
|
|
|
*
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param array $arrayVariableDocumentToDelete Variable with Documents to delete
|
2016-08-15 09:28:25 -04:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function deleteMultipleFile($applicationUid, array $arrayVariableDocumentToDelete)
|
|
|
|
|
{
|
2017-10-05 14:54:41 -04:00
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$appDocument = new AppDocument();
|
2016-08-15 09:28:25 -04:00
|
|
|
|
|
|
|
|
$arrayApplicationData = $this->getApplicationRecordByPk($applicationUid, [], false);
|
|
|
|
|
$arrayApplicationData['APP_DATA'] = $case->unserializeData($arrayApplicationData['APP_DATA']);
|
|
|
|
|
$flagDelete = false;
|
|
|
|
|
foreach ($arrayVariableDocumentToDelete as $key => $value) {
|
|
|
|
|
if (is_array($value) && !empty($value)) {
|
|
|
|
|
$type = '';
|
|
|
|
|
|
|
|
|
|
$arrayAux = $value;
|
|
|
|
|
$arrayAux = array_shift($arrayAux);
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('appDocUid', $arrayAux)) {
|
|
|
|
|
$type = 'NORMAL';
|
|
|
|
|
} else {
|
|
|
|
|
$arrayAux = array_shift($arrayAux);
|
|
|
|
|
$arrayAux = array_shift($arrayAux);
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('appDocUid', $arrayAux)) {
|
|
|
|
|
$type = 'GRID';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
|
case 'NORMAL':
|
|
|
|
|
$variable = $key;
|
|
|
|
|
$arrayDocumentDelete = $value;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayDocumentDelete as $value2) {
|
2020-04-29 20:31:21 -04:00
|
|
|
if ($value2['appDocUid'] !== "") {
|
|
|
|
|
$appDocument->remove($value2['appDocUid'], (int)($value2['version']));
|
2016-08-15 09:28:25 -04:00
|
|
|
|
2020-04-29 20:31:21 -04:00
|
|
|
$arrayApplicationData['APP_DATA'] = $this->applicationDataDeleteMultipleFile(
|
|
|
|
|
$arrayApplicationData['APP_DATA'], $variable, null, $type, $value2
|
|
|
|
|
);
|
2016-08-15 09:28:25 -04:00
|
|
|
|
2020-04-29 20:31:21 -04:00
|
|
|
$flagDelete = true;
|
|
|
|
|
}
|
2016-08-15 09:28:25 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'GRID':
|
|
|
|
|
$grid = $key;
|
|
|
|
|
|
|
|
|
|
foreach ($value as $value2) {
|
|
|
|
|
foreach ($value2 as $key3 => $value3) {
|
|
|
|
|
$variable = $key3;
|
|
|
|
|
$arrayDocumentDelete = $value3;
|
|
|
|
|
|
|
|
|
|
foreach ($arrayDocumentDelete as $value4) {
|
2020-04-29 20:31:21 -04:00
|
|
|
if ($value4['appDocUid'] !== "") {
|
|
|
|
|
$appDocument->remove($value4['appDocUid'], (int)($value4['version']));
|
2016-08-15 09:28:25 -04:00
|
|
|
|
2020-04-29 20:31:21 -04:00
|
|
|
$arrayApplicationData['APP_DATA'] = $this->applicationDataDeleteMultipleFile(
|
|
|
|
|
$arrayApplicationData['APP_DATA'], $grid, $variable, $type, $value4
|
|
|
|
|
);
|
2016-08-15 09:28:25 -04:00
|
|
|
|
2020-04-29 20:31:21 -04:00
|
|
|
$flagDelete = true;
|
|
|
|
|
}
|
2016-08-15 09:28:25 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 10:43:44 -04:00
|
|
|
//Delete simple files.
|
2016-11-15 15:43:12 -04:00
|
|
|
//The observations suggested by 'pull request' approver are applied (please see pull request).
|
|
|
|
|
foreach ($arrayVariableDocumentToDelete as $key => $value) {
|
|
|
|
|
if (isset($value['appDocUid'])) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$appDocument->remove($value['appDocUid'], (int)(isset($value['version']) ? $value['version'] : 1));
|
2016-11-15 15:43:12 -04:00
|
|
|
if (is_string($arrayApplicationData['APP_DATA'][$key])) {
|
|
|
|
|
try {
|
|
|
|
|
$files = G::json_decode($arrayApplicationData['APP_DATA'][$key]);
|
|
|
|
|
foreach ($files as $keyFile => $valueFile) {
|
|
|
|
|
if ($valueFile === $value['appDocUid']) {
|
|
|
|
|
unset($files[$keyFile]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$arrayApplicationData['APP_DATA'][$key] = G::json_encode($files);
|
2017-08-10 10:43:44 -04:00
|
|
|
} catch (Exception $e) {
|
2020-08-10 17:11:55 -04:00
|
|
|
$message = $e->getMessage();
|
|
|
|
|
$context = $value;
|
|
|
|
|
Log::channel(':DeleteFile')->error($message, Bootstrap::context($context));
|
2016-11-15 15:43:12 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$flagDelete = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-15 09:28:25 -04:00
|
|
|
if ($flagDelete) {
|
|
|
|
|
$result = $case->updateCase($applicationUid, $arrayApplicationData);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-02 13:57:00 -04:00
|
|
|
|
|
|
|
|
/**
|
2017-11-07 13:59:59 -04:00
|
|
|
* Get Permissions, Participate, Access, Objects supervisor
|
2017-02-02 13:57:00 -04:00
|
|
|
*
|
|
|
|
|
* @param string $usrUid
|
|
|
|
|
* @param string $proUid
|
|
|
|
|
* @param string $appUid
|
2017-11-07 13:59:59 -04:00
|
|
|
* @param array $rolesPermissions, the roles that we need to review
|
|
|
|
|
* @param array $objectPermissions, the permissions that we need to review
|
|
|
|
|
* @param boolean $objectSupervisor, if we need to get all the objects supervisor
|
2018-04-27 11:14:48 -04:00
|
|
|
* @param string $tasUid
|
2019-09-03 12:39:37 -04:00
|
|
|
*
|
2017-11-07 13:59:59 -04:00
|
|
|
* @return array
|
2017-02-02 13:57:00 -04:00
|
|
|
*/
|
2017-10-05 14:54:41 -04:00
|
|
|
public function userAuthorization(
|
|
|
|
|
$usrUid,
|
|
|
|
|
$proUid,
|
|
|
|
|
$appUid,
|
2017-11-07 13:59:59 -04:00
|
|
|
$rolesPermissions = [],
|
|
|
|
|
$objectPermissions = [],
|
2018-04-27 11:14:48 -04:00
|
|
|
$objectSupervisor = false,
|
|
|
|
|
$tasUid = ''
|
2017-10-05 14:54:41 -04:00
|
|
|
) {
|
2017-11-07 13:59:59 -04:00
|
|
|
$arrayAccess = [];
|
2017-02-02 13:57:00 -04:00
|
|
|
|
2019-09-03 12:39:37 -04:00
|
|
|
// User has participated
|
|
|
|
|
$arrayAccess['participated'] = Delegation::participation($appUid, $usrUid);
|
2017-02-02 13:57:00 -04:00
|
|
|
|
2019-09-03 12:39:37 -04:00
|
|
|
// User is supervisor
|
2017-10-05 14:54:41 -04:00
|
|
|
$supervisor = new BmProcessSupervisor();
|
2017-02-09 12:29:59 -04:00
|
|
|
$isSupervisor = $supervisor->isUserProcessSupervisor($proUid, $usrUid);
|
2017-02-09 12:31:32 -04:00
|
|
|
$arrayAccess['supervisor'] = ($isSupervisor) ? true : false;
|
2017-02-02 13:57:00 -04:00
|
|
|
|
2019-09-03 12:39:37 -04:00
|
|
|
// If the user is supervisor we will to return the object assigned
|
2017-11-07 13:59:59 -04:00
|
|
|
if ($isSupervisor && $objectSupervisor) {
|
|
|
|
|
$ps = new BmProcessSupervisor();
|
|
|
|
|
$arrayAccess['objectSupervisor'] = $ps->getObjectSupervisor($proUid);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 12:39:37 -04:00
|
|
|
// Roles Permissions
|
2017-02-09 12:29:59 -04:00
|
|
|
if (count($rolesPermissions) > 0) {
|
2017-02-02 13:57:00 -04:00
|
|
|
global $RBAC;
|
|
|
|
|
foreach ($rolesPermissions as $value) {
|
|
|
|
|
$arrayAccess['rolesPermissions'][$value] = ($RBAC->userCanAccess($value) < 0) ? false : true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 12:39:37 -04:00
|
|
|
// Object Permissions
|
2017-02-07 12:25:21 -04:00
|
|
|
if (count($objectPermissions) > 0) {
|
2017-11-07 13:59:59 -04:00
|
|
|
$case = new ClassesCases();
|
2017-02-02 13:57:00 -04:00
|
|
|
foreach ($objectPermissions as $key => $value) {
|
2018-04-27 11:14:48 -04:00
|
|
|
$resPermission = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, $value);
|
2017-02-07 12:25:21 -04:00
|
|
|
if (isset($resPermission[$key])) {
|
2017-02-02 13:57:00 -04:00
|
|
|
$arrayAccess['objectPermissions'][$key] = $resPermission[$key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $arrayAccess;
|
|
|
|
|
}
|
2017-02-22 12:13:16 -04:00
|
|
|
|
2017-03-01 10:51:38 -04:00
|
|
|
|
2017-02-22 12:13:16 -04:00
|
|
|
/**
|
|
|
|
|
* Get Global System Variables
|
|
|
|
|
* @param array $appData
|
|
|
|
|
* @param array $dataVariable
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2017-02-22 12:13:16 -04:00
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getGlobalVariables($appData = array(), $dataVariable = array())
|
|
|
|
|
{
|
|
|
|
|
$appData = array_change_key_case($appData, CASE_UPPER);
|
|
|
|
|
$dataVariable = array_change_key_case($dataVariable, CASE_UPPER);
|
|
|
|
|
|
2017-09-19 09:56:06 -04:00
|
|
|
$result = [];
|
|
|
|
|
//we get the appData parameters
|
|
|
|
|
if (!empty($appData['APPLICATION'])) {
|
|
|
|
|
$result['APPLICATION'] = $appData['APPLICATION'];
|
2017-02-22 12:13:16 -04:00
|
|
|
}
|
2017-09-19 09:56:06 -04:00
|
|
|
if (!empty($appData['PROCESS'])) {
|
|
|
|
|
$result['PROCESS'] = $appData['PROCESS'];
|
2017-02-22 12:13:16 -04:00
|
|
|
}
|
2017-09-19 09:56:06 -04:00
|
|
|
if (!empty($appData['TASK'])) {
|
|
|
|
|
$result['TASK'] = $appData['TASK'];
|
2017-02-22 12:13:16 -04:00
|
|
|
}
|
2017-09-19 09:56:06 -04:00
|
|
|
if (!empty($appData['INDEX'])) {
|
|
|
|
|
$result['INDEX'] = $appData['INDEX'];
|
2017-02-22 12:13:16 -04:00
|
|
|
}
|
2017-09-19 09:56:06 -04:00
|
|
|
|
|
|
|
|
//we try to get the missing elements
|
|
|
|
|
if (!empty($dataVariable['APP_UID']) && empty($result['APPLICATION'])) {
|
|
|
|
|
$result['APPLICATION'] = $dataVariable['APP_UID'];
|
|
|
|
|
}
|
|
|
|
|
if (!empty($dataVariable['PRO_UID']) && empty($result['PROCESS'])) {
|
|
|
|
|
$result['PROCESS'] = $dataVariable['PRO_UID'];
|
|
|
|
|
}
|
2017-09-20 10:27:38 -04:00
|
|
|
|
|
|
|
|
$result['USER_LOGGED'] = '';
|
|
|
|
|
$result['USR_USERNAME'] = '';
|
|
|
|
|
global $RBAC;
|
|
|
|
|
if (isset($RBAC) && isset($RBAC->aUserInfo)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$result['USER_LOGGED'] = isset($RBAC->aUserInfo['USER_INFO']['USR_UID']) ? $RBAC->aUserInfo['USER_INFO']['USR_UID'] : '';
|
|
|
|
|
$result['USR_USERNAME'] = isset($RBAC->aUserInfo['USER_INFO']['USR_USERNAME']) ? $RBAC->aUserInfo['USER_INFO']['USR_USERNAME'] : '';
|
2017-09-20 10:27:38 -04:00
|
|
|
}
|
2017-09-19 09:56:06 -04:00
|
|
|
if (empty($result['USER_LOGGED'])) {
|
|
|
|
|
$result['USER_LOGGED'] = Server::getUserId();
|
|
|
|
|
if (!empty($result['USER_LOGGED'])) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$oUserLogged = new ModelUsers();
|
2017-09-20 10:27:38 -04:00
|
|
|
$oUserLogged->load($result['USER_LOGGED']);
|
2017-09-19 09:56:06 -04:00
|
|
|
$result['USR_USERNAME'] = $oUserLogged->getUsrUsername();
|
|
|
|
|
}
|
2017-02-22 12:13:16 -04:00
|
|
|
}
|
|
|
|
|
|
2017-09-19 09:56:06 -04:00
|
|
|
//the parameter dataVariable may contain additional elements
|
|
|
|
|
$result = array_merge($dataVariable, $result);
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-09-19 09:56:06 -04:00
|
|
|
return $result;
|
2017-02-22 12:13:16 -04:00
|
|
|
}
|
2017-03-01 10:51:38 -04:00
|
|
|
|
2017-02-23 15:02:41 -04:00
|
|
|
/**
|
|
|
|
|
* Get index last participation from a user
|
|
|
|
|
*
|
|
|
|
|
* This function return the last participation
|
|
|
|
|
* by default is not considered the status OPEN or CLOSED
|
|
|
|
|
* in parallel cases return the first to find
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
* @param string $threadStatus
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2017-02-23 15:02:41 -04:00
|
|
|
* @return integer delIndex
|
|
|
|
|
*/
|
|
|
|
|
public function getLastParticipatedByUser($appUid, $userUid, $threadStatus = '')
|
|
|
|
|
{
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
$criteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$criteria->addSelectColumn(AppDelegationPeer::DEL_THREAD_STATUS);
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_UID, $appUid, Criteria::EQUAL);
|
|
|
|
|
$criteria->add(AppDelegationPeer::USR_UID, $userUid, Criteria::EQUAL);
|
2017-02-23 15:02:41 -04:00
|
|
|
if (!empty($threadStatus)) {
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->add(AppDelegationPeer::DEL_THREAD_STATUS, $threadStatus, Criteria::EQUAL);
|
2017-02-23 15:02:41 -04:00
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
$dataSet = AppDelegationPeer::doSelectRS($criteria);
|
|
|
|
|
$dataSet->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2017-02-23 15:02:41 -04:00
|
|
|
$dataSet->next();
|
|
|
|
|
$row = $dataSet->getRow();
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-02-23 15:02:41 -04:00
|
|
|
return isset($row['DEL_INDEX']) ? $row['DEL_INDEX'] : 0;
|
|
|
|
|
}
|
2017-03-06 10:48:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get last index, we can considering the pause thread
|
|
|
|
|
*
|
|
|
|
|
* This function return the last index thread and will be considered the paused cases
|
|
|
|
|
* Is created by Jump to and redirect the correct thread
|
|
|
|
|
* by default is not considered the paused thread
|
|
|
|
|
* in parallel cases return the first thread to find
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param boolean $checkCaseIsPaused
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2017-03-06 10:48:18 -04:00
|
|
|
* @return integer delIndex
|
|
|
|
|
*/
|
|
|
|
|
public function getOneLastThread($appUid, $checkCaseIsPaused = false)
|
|
|
|
|
{
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
$criteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$criteria->addSelectColumn(AppDelegationPeer::DEL_THREAD_STATUS);
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_UID, $appUid, Criteria::EQUAL);
|
|
|
|
|
$dataSet = AppDelegationPeer::doSelectRS($criteria);
|
|
|
|
|
$dataSet->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2017-03-06 10:48:18 -04:00
|
|
|
$dataSet->next();
|
|
|
|
|
$row = $dataSet->getRow();
|
|
|
|
|
$delIndex = 0;
|
|
|
|
|
while (is_array($row)) {
|
|
|
|
|
$delIndex = $row['DEL_INDEX'];
|
2017-10-05 14:54:41 -04:00
|
|
|
if ($checkCaseIsPaused && AppDelay::isPaused($appUid, $delIndex)) {
|
2017-03-06 10:48:18 -04:00
|
|
|
return $delIndex;
|
|
|
|
|
}
|
|
|
|
|
$dataSet->next();
|
|
|
|
|
$row = $dataSet->getRow();
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-03-06 10:48:18 -04:00
|
|
|
return $delIndex;
|
|
|
|
|
}
|
2017-10-05 14:54:41 -04:00
|
|
|
|
2017-06-02 12:26:03 -04:00
|
|
|
/**
|
|
|
|
|
* This function will be return the criteria for the search filter
|
|
|
|
|
*
|
|
|
|
|
* We considered in the search criteria the custom cases list,
|
|
|
|
|
* the titles related to: caseTitle taskTitle processTitle and
|
|
|
|
|
* the case number
|
2017-10-05 14:54:41 -04:00
|
|
|
* @param Criteria $criteria , must be contain the initial criteria for search
|
|
|
|
|
* @param string $listPeer , name of the list class
|
|
|
|
|
* @param string $search , the parameter for search in the table
|
|
|
|
|
* @param string $additionalClassName , name of the className of pmtable
|
2019-04-24 09:43:53 -04:00
|
|
|
* @param array $additionalColumns , columns related to the custom cases list ex: TABLE_NAME.COLUMN_NAME
|
2018-01-04 09:58:45 -04:00
|
|
|
*
|
2017-06-02 12:26:03 -04:00
|
|
|
* @throws PropelException
|
|
|
|
|
*/
|
2017-10-05 14:54:41 -04:00
|
|
|
public function getSearchCriteriaListCases(
|
|
|
|
|
&$criteria,
|
|
|
|
|
$listPeer,
|
|
|
|
|
$search,
|
|
|
|
|
$additionalClassName = '',
|
2019-04-24 09:43:53 -04:00
|
|
|
$additionalColumns = []
|
2017-10-05 14:54:41 -04:00
|
|
|
) {
|
2019-04-24 09:43:53 -04:00
|
|
|
$tmpCriteria = '';
|
2017-06-02 12:26:03 -04:00
|
|
|
//If we have additional tables configured in the custom cases list, prepare the variables for search
|
|
|
|
|
if (count($additionalColumns) > 0) {
|
|
|
|
|
require_once(PATH_DATA_SITE . 'classes' . PATH_SEP . $additionalClassName . '.php');
|
2019-04-24 09:43:53 -04:00
|
|
|
|
|
|
|
|
$columnPivot = current($additionalColumns);
|
|
|
|
|
$tableAndColumn = explode(".", $columnPivot);
|
|
|
|
|
$type = PmTable::getTypeOfColumn($listPeer, $tableAndColumn[0], $tableAndColumn[1]);
|
|
|
|
|
$tmpCriteria = $this->defineCriteriaByColumnType($type, $columnPivot, $search);
|
2017-06-02 12:26:03 -04:00
|
|
|
|
|
|
|
|
//We prepare the query related to the custom cases list
|
2019-04-24 09:43:53 -04:00
|
|
|
foreach (array_slice($additionalColumns, 1) as $column) {
|
|
|
|
|
$tableAndColumn = explode(".", $column);
|
|
|
|
|
$type = PmTable::getTypeOfColumn($listPeer, $tableAndColumn[0], $tableAndColumn[1]);
|
|
|
|
|
$tmpCriteria = $this->defineCriteriaByColumnType($type, $column, $search)->addOr($tmpCriteria);
|
|
|
|
|
|
2017-06-02 12:26:03 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 09:43:53 -04:00
|
|
|
if (!empty($tmpCriteria)) {
|
2017-06-02 12:26:03 -04:00
|
|
|
$criteria->add(
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->getNewCriterion($listPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion($listPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion($listPeer::APP_PRO_TITLE, '%' . $search . '%',
|
|
|
|
|
Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion($listPeer::APP_NUMBER, $search, Criteria::EQUAL)->addOr(
|
2019-04-24 09:43:53 -04:00
|
|
|
$tmpCriteria
|
2017-10-05 14:54:41 -04:00
|
|
|
))))
|
2017-06-02 12:26:03 -04:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$criteria->add(
|
2017-10-05 14:54:41 -04:00
|
|
|
$criteria->getNewCriterion($listPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion($listPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion($listPeer::APP_PRO_TITLE, '%' . $search . '%',
|
|
|
|
|
Criteria::LIKE)->addOr(
|
|
|
|
|
$criteria->getNewCriterion($listPeer::APP_NUMBER, $search, Criteria::EQUAL))))
|
2017-06-02 12:26:03 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-13 14:58:43 -04:00
|
|
|
|
2019-04-24 09:43:53 -04:00
|
|
|
/**
|
|
|
|
|
* Define the criteria according to the column type
|
|
|
|
|
*
|
|
|
|
|
* @param string $fieldType
|
|
|
|
|
* @param string $column
|
|
|
|
|
* @param string $search
|
|
|
|
|
*
|
|
|
|
|
* @return Criteria
|
|
|
|
|
*/
|
|
|
|
|
private function defineCriteriaByColumnType($fieldType, $column, $search)
|
|
|
|
|
{
|
|
|
|
|
$newCriteria = new Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
switch ($fieldType) {
|
|
|
|
|
case CreoleTypes::BOOLEAN:
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
|
|
|
|
|
break;
|
|
|
|
|
case CreoleTypes::BIGINT:
|
|
|
|
|
case CreoleTypes::INTEGER:
|
|
|
|
|
case CreoleTypes::SMALLINT:
|
|
|
|
|
case CreoleTypes::TINYINT:
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
|
|
|
|
|
break;
|
|
|
|
|
case CreoleTypes::REAL:
|
|
|
|
|
case CreoleTypes::DECIMAL:
|
|
|
|
|
case CreoleTypes::DOUBLE:
|
|
|
|
|
case CreoleTypes::FLOAT:
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::LIKE);
|
|
|
|
|
break;
|
|
|
|
|
case CreoleTypes::CHAR:
|
|
|
|
|
case CreoleTypes::LONGVARCHAR:
|
|
|
|
|
case CreoleTypes::VARCHAR:
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, "%" . $search . "%", Criteria::LIKE);
|
|
|
|
|
break;
|
|
|
|
|
case CreoleTypes::DATE:
|
|
|
|
|
case CreoleTypes::TIME:
|
|
|
|
|
case CreoleTypes::TIMESTAMP://DATETIME
|
|
|
|
|
//@todo use the same constant in other places
|
|
|
|
|
if (preg_match(UtilDateTime::REGEX_IS_DATE,
|
|
|
|
|
$search, $arrayMatch)) {
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::GREATER_EQUAL);
|
|
|
|
|
} else {
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $criteria;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 14:58:43 -04:00
|
|
|
/**
|
|
|
|
|
* This function get the table.column by order by the result
|
|
|
|
|
* We can include the additional table related to the custom cases list
|
|
|
|
|
*
|
|
|
|
|
* @param string $listPeer, name of the list class
|
|
|
|
|
* @param string $field, name of the fieldName
|
|
|
|
|
* @param string $sort, name of column by sort
|
2017-07-14 11:57:21 -04:00
|
|
|
* @param string $defaultSort, name of column by sort default
|
2017-07-13 14:58:43 -04:00
|
|
|
* @param string $additionalClassName, name of the className of pmTable
|
2017-07-14 15:10:11 -04:00
|
|
|
* @param array $additionalColumns, columns related to the custom cases list with the format TABLE_NAME.COLUMN_NAME
|
2017-10-13 15:02:14 -04:00
|
|
|
* @param string $userDisplayFormat, user information display format
|
|
|
|
|
*
|
2017-10-23 14:23:31 -04:00
|
|
|
* @return string|array could be an string $tableName, could be an array $columnSort
|
2017-07-13 14:58:43 -04:00
|
|
|
*/
|
2017-10-05 14:54:41 -04:00
|
|
|
public function getSortColumn(
|
|
|
|
|
$listPeer,
|
|
|
|
|
$field,
|
|
|
|
|
$sort,
|
|
|
|
|
$defaultSort,
|
|
|
|
|
$additionalClassName = '',
|
2017-10-20 18:51:24 -04:00
|
|
|
$additionalColumns = array(),
|
|
|
|
|
$userDisplayFormat = ''
|
2017-10-05 14:54:41 -04:00
|
|
|
) {
|
2017-07-14 11:57:21 -04:00
|
|
|
$columnSort = $defaultSort;
|
2017-07-14 15:10:11 -04:00
|
|
|
$tableName = '';
|
2017-07-13 14:58:43 -04:00
|
|
|
|
|
|
|
|
//We will check if the column by sort is a LIST table
|
|
|
|
|
$columnsList = $listPeer::getFieldNames($field);
|
|
|
|
|
if (in_array($sort, $columnsList)) {
|
2017-10-13 15:02:14 -04:00
|
|
|
switch ($sort) {
|
|
|
|
|
case 'DEL_PREVIOUS_USR_UID':
|
|
|
|
|
$columnSort = $this->buildOrderFieldFormatted($columnsList, $userDisplayFormat, 'DEL_PREVIOUS_');
|
|
|
|
|
break;
|
|
|
|
|
case 'USR_UID':
|
|
|
|
|
$columnSort = $this->buildOrderFieldFormatted($columnsList, $userDisplayFormat, 'DEL_CURRENT_');
|
2017-11-21 09:35:32 -04:00
|
|
|
if (empty($columnSort)) {
|
|
|
|
|
$columnSort = $this->buildOrderFieldFormatted($columnsList, $userDisplayFormat, '', false);
|
|
|
|
|
}
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
$columnSort = $listPeer::TABLE_NAME . '.' . $sort;
|
|
|
|
|
}
|
2017-07-13 14:58:43 -04:00
|
|
|
} else {
|
|
|
|
|
//We will sort by CUSTOM CASE LIST table
|
2017-07-14 15:10:11 -04:00
|
|
|
if (count($additionalColumns) > 0) {
|
2017-07-13 14:58:43 -04:00
|
|
|
require_once(PATH_DATA_SITE . 'classes' . PATH_SEP . $additionalClassName . '.php');
|
|
|
|
|
$aTable = explode('.', current($additionalColumns));
|
|
|
|
|
if (count($aTable) > 0) {
|
|
|
|
|
$tableName = $aTable[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-14 15:10:11 -04:00
|
|
|
if (in_array($tableName . '.' . $sort, $additionalColumns)) {
|
|
|
|
|
$columnSort = $tableName . '.' . $sort;
|
|
|
|
|
}
|
2017-07-13 14:58:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $columnSort;
|
|
|
|
|
}
|
2017-10-13 15:02:14 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When we order columns related to the user information we need to use the userDisplayFormat
|
|
|
|
|
*
|
|
|
|
|
* @param array $columnsList, the list of columns in the table
|
|
|
|
|
* @param string $format, the user display format
|
|
|
|
|
* @param string $prefix, the initial name of the columns related to the USR_FIRSTNAME USR_LASTNAME USR_USERNAME
|
2017-10-20 18:51:24 -04:00
|
|
|
*
|
2017-10-23 14:23:31 -04:00
|
|
|
* @return array $columnSort, columns by apply the sql command ORDER BY
|
2017-10-13 15:02:14 -04:00
|
|
|
*/
|
2017-11-21 09:35:32 -04:00
|
|
|
public function buildOrderFieldFormatted($columnsList, $format, $prefix = 'DEL_PREVIOUS_', $validate = true)
|
2017-10-13 15:02:14 -04:00
|
|
|
{
|
2017-10-23 14:23:31 -04:00
|
|
|
$columnSort = [];
|
2017-10-13 15:02:14 -04:00
|
|
|
|
2017-11-21 09:35:32 -04:00
|
|
|
if (!$validate || (in_array($prefix . 'USR_FIRSTNAME', $columnsList) &&
|
2017-10-13 15:02:14 -04:00
|
|
|
in_array($prefix . 'USR_LASTNAME', $columnsList) &&
|
2017-11-21 09:35:32 -04:00
|
|
|
in_array($prefix . 'USR_USERNAME', $columnsList))
|
2017-10-13 15:02:14 -04:00
|
|
|
) {
|
|
|
|
|
switch ($format) {
|
|
|
|
|
case '@firstName @lastName':
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_FIRSTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_LASTNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
case '@firstName @lastName (@userName)':
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_FIRSTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_LASTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_USERNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
case '@userName':
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_USERNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
case '@userName (@firstName @lastName)':
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_USERNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_FIRSTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_LASTNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
case '@lastName, @firstName':
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_LASTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_FIRSTNAME');
|
|
|
|
|
break;
|
|
|
|
|
case '@lastName @firstName':
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_LASTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_FIRSTNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
case '@lastName, @firstName (@userName)':
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_LASTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_FIRSTNAME');
|
|
|
|
|
array_push($columnSort, $prefix . 'USR_USERNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-10-23 14:23:31 -04:00
|
|
|
array_push($columnSort, $prefix . 'USR_USERNAME');
|
2017-10-13 15:02:14 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-20 18:51:24 -04:00
|
|
|
|
2017-10-13 15:02:14 -04:00
|
|
|
return $columnSort;
|
|
|
|
|
}
|
2017-10-20 18:51:24 -04:00
|
|
|
|
|
|
|
|
/** This function verify if the user is a supervisor
|
2017-10-05 14:54:41 -04:00
|
|
|
* If we send the formUid we will to review if has the object form assigned
|
|
|
|
|
*
|
|
|
|
|
* @param string $usrUid, Uid related to the user
|
|
|
|
|
* @param string $appUid, Uid related to the case
|
|
|
|
|
* @param string $formUid, Uid related to the dynaform
|
|
|
|
|
* @param string $proUid, Uid related to the process
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function isSupervisorFromForm($usrUid, $appUid, $formUid, $proUid = '')
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//We will to search the proUid related to the appUid
|
|
|
|
|
if (empty($proUid)) {
|
|
|
|
|
$arrayApplicationData = $this->getApplicationRecordByPk($appUid, [], false);
|
|
|
|
|
$proUid = $arrayApplicationData['PRO_UID'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$supervisor = new BmProcessSupervisor();
|
|
|
|
|
$isSupervisor = $supervisor->isUserProcessSupervisor($proUid, $usrUid);
|
|
|
|
|
|
|
|
|
|
//We will check if the supervisor has the object form assigned
|
|
|
|
|
if ($isSupervisor) {
|
|
|
|
|
$cases = new ClassesCases();
|
|
|
|
|
$resultDynaForm = $cases->getAllDynaformsStepsToRevise($appUid);
|
|
|
|
|
$isSupervisor = false;
|
|
|
|
|
while ($resultDynaForm->next()) {
|
|
|
|
|
$row = $resultDynaForm->getRow();
|
|
|
|
|
//Review if the supervisor has the form assigned
|
|
|
|
|
if ($row["STEP_UID_OBJ"] === $formUid) {
|
|
|
|
|
$isSupervisor = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $isSupervisor;
|
|
|
|
|
}
|
2018-11-08 08:42:51 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Upload file in the corresponding folder
|
|
|
|
|
*
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param string $varName
|
|
|
|
|
* @param mixed $inpDocUid
|
|
|
|
|
* @param string $appDocUid
|
2020-09-11 15:02:20 -04:00
|
|
|
* @param int $delegationIndex
|
2018-11-08 08:42:51 -04:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2020-09-11 15:02:20 -04:00
|
|
|
public function uploadFiles($userUid, $appUid, $varName, $inpDocUid = -1, $appDocUid = null, $delegationIndex = null)
|
2018-11-08 08:42:51 -04:00
|
|
|
{
|
|
|
|
|
$response = [];
|
2022-05-04 13:08:12 -04:00
|
|
|
// Review the appUid
|
|
|
|
|
Validator::appUid($appUid, '$appUid');
|
|
|
|
|
|
2018-11-08 08:42:51 -04:00
|
|
|
if (isset($_FILES["form"]["name"]) && count($_FILES["form"]["name"]) > 0) {
|
|
|
|
|
// Get the delIndex related to the case
|
|
|
|
|
$cases = new ClassesCases();
|
2020-09-11 15:02:20 -04:00
|
|
|
if (!empty($delegationIndex)) {
|
|
|
|
|
$delIndex = $delegationIndex;
|
|
|
|
|
} else {
|
|
|
|
|
$delIndex = $cases->getCurrentDelegation($appUid, $userUid);
|
|
|
|
|
}
|
2018-11-08 08:42:51 -04:00
|
|
|
// Get information about the user
|
|
|
|
|
$user = new ModelUsers();
|
|
|
|
|
$userCreator = $user->loadDetailed($userUid)['USR_FULLNAME'];
|
|
|
|
|
$i = 0;
|
|
|
|
|
foreach ($_FILES["form"]["name"] as $fieldIndex => $fieldValue) {
|
|
|
|
|
if (!is_array($fieldValue)) {
|
|
|
|
|
$arrayFileName = [
|
|
|
|
|
'name' => $_FILES["form"]["name"][$fieldIndex],
|
|
|
|
|
'tmp_name' => $_FILES["form"]["tmp_name"][$fieldIndex],
|
|
|
|
|
'error' => $_FILES["form"]["error"][$fieldIndex]
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// We will to review the validation related to the Input document
|
|
|
|
|
$file = [
|
|
|
|
|
'filename' => $arrayFileName["name"],
|
|
|
|
|
'path' => $arrayFileName["tmp_name"]
|
|
|
|
|
];
|
|
|
|
|
$this->canUploadFileRelatedToInput($inpDocUid, $file);
|
|
|
|
|
|
|
|
|
|
// There is no error, the file uploaded with success
|
|
|
|
|
if ($arrayFileName["error"] === UPLOAD_ERR_OK) {
|
|
|
|
|
$appDocument = new AppDocument();
|
|
|
|
|
$objCreated = $appDocument->uploadAppDocument(
|
|
|
|
|
$appUid,
|
|
|
|
|
$userUid,
|
|
|
|
|
$delIndex,
|
|
|
|
|
$inpDocUid ,
|
|
|
|
|
$arrayFileName,
|
|
|
|
|
$varName,
|
|
|
|
|
$appDocUid
|
|
|
|
|
);
|
|
|
|
|
$response[$i] = [
|
|
|
|
|
'appDocUid' => $objCreated->getAppDocUid(),
|
|
|
|
|
'docVersion' => $objCreated->getDocVersion(),
|
|
|
|
|
'appDocFilename' => $objCreated->getAppDocFilename(),
|
|
|
|
|
'appDocCreateDate' => $objCreated->getAppDocCreateDate(),
|
|
|
|
|
'appDocType' => $objCreated->getAppDocType(),
|
|
|
|
|
'appDocIndex' => $objCreated->getAppDocIndex(),
|
|
|
|
|
'appDocCreateUser' => $userCreator
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
} else {
|
|
|
|
|
throw new UploadException($arrayFileName['error']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR'));
|
2020-06-04 10:38:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a case note
|
|
|
|
|
*
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
* @param string $note
|
|
|
|
|
* @param bool $sendMail
|
|
|
|
|
* @param array $files
|
2020-12-16 17:47:42 -04:00
|
|
|
* @param int $appNUmber
|
|
|
|
|
*
|
|
|
|
|
* @see Ajax::cancelCase()
|
|
|
|
|
* @see Ajax::pauseCase()
|
|
|
|
|
* @see Ajax::reassignCase()
|
|
|
|
|
* @see AppProxy::postNote()
|
|
|
|
|
* @see WsBase::addCaseNote()
|
|
|
|
|
* @see Cases::saveCaseNote()
|
2020-06-04 10:38:48 -04:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-12-16 17:47:42 -04:00
|
|
|
public function addNote($appUid, $userUid, $note, $sendMail = false, $files = [], $appNumber = 0)
|
2020-06-04 10:38:48 -04:00
|
|
|
{
|
2020-12-16 17:47:42 -04:00
|
|
|
// Get the appNumber if was not send
|
|
|
|
|
if ($appNumber === 0) {
|
|
|
|
|
$appNumber = ModelApplication::getCaseNumber($appUid);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 10:38:48 -04:00
|
|
|
// Register the note
|
|
|
|
|
$attributes = [
|
|
|
|
|
"APP_UID" => $appUid,
|
2020-12-16 17:47:42 -04:00
|
|
|
"APP_NUMBER" => $appNumber,
|
2020-06-04 10:38:48 -04:00
|
|
|
"USR_UID" => $userUid,
|
|
|
|
|
"NOTE_DATE" => date("Y-m-d H:i:s"),
|
|
|
|
|
"NOTE_CONTENT" => $note,
|
|
|
|
|
"NOTE_TYPE" => "USER",
|
|
|
|
|
"NOTE_AVAILABILITY" => "PUBLIC",
|
|
|
|
|
"NOTE_RECIPIENTS" => ""
|
|
|
|
|
];
|
2020-06-10 12:15:01 -04:00
|
|
|
$newNote = Notes::create($attributes);
|
2020-06-04 10:38:48 -04:00
|
|
|
// Get the FK
|
2020-06-10 12:15:01 -04:00
|
|
|
$noteId = $newNote->NOTE_ID;
|
2020-06-04 10:38:48 -04:00
|
|
|
|
2020-06-10 12:15:01 -04:00
|
|
|
$attachments = [];
|
2020-06-04 10:38:48 -04:00
|
|
|
// Register the files related to the note
|
2020-06-10 12:15:01 -04:00
|
|
|
if (!empty($files) || !empty($_FILES["filesToUpload"])) {
|
|
|
|
|
$filesResponse = $this->uploadFilesInCaseNotes($userUid, $appUid, $files, $noteId);
|
|
|
|
|
foreach ($filesResponse['attachments'] as $key => $value) {
|
|
|
|
|
$attachments[$key] = [];
|
|
|
|
|
$attachments[$key]['APP_DOC_FILENAME'] = $value['APP_DOC_FILENAME'];
|
2020-06-12 15:16:11 -04:00
|
|
|
$attachments[$key]['LINK'] = "../cases/casesShowCaseNotes?a=" . $value["APP_DOC_UID"] . "&v=" . $value["DOC_VERSION"];
|
2020-06-10 12:15:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-06-04 10:38:48 -04:00
|
|
|
|
|
|
|
|
// Send the email
|
|
|
|
|
if ($sendMail) {
|
2020-06-10 12:15:01 -04:00
|
|
|
// Get the recipients
|
2020-06-04 10:38:48 -04:00
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$p = $case->getUsersParticipatedInCase($appUid, 'ACTIVE');
|
|
|
|
|
$noteRecipientsList = [];
|
|
|
|
|
|
|
|
|
|
foreach ($p["array"] as $key => $userParticipated) {
|
|
|
|
|
if ($key != '') {
|
|
|
|
|
$noteRecipientsList[] = $key;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$noteRecipients = implode(",", $noteRecipientsList);
|
|
|
|
|
$note = stripslashes($note);
|
|
|
|
|
|
2020-06-10 12:15:01 -04:00
|
|
|
// Send the notification
|
|
|
|
|
$appNote = new AppNotes();
|
|
|
|
|
$appNote->sendNoteNotification($appUid, $userUid, $note, $noteRecipients, '', 0, $noteId);
|
2020-06-04 10:38:48 -04:00
|
|
|
}
|
2020-06-10 12:15:01 -04:00
|
|
|
|
|
|
|
|
// Prepare the response
|
|
|
|
|
$result = [];
|
|
|
|
|
$result['success'] = 'success';
|
|
|
|
|
$result['message'] = '';
|
|
|
|
|
$result['attachments'] = $attachments;
|
|
|
|
|
$result['attachment_errors'] = [];
|
|
|
|
|
|
|
|
|
|
return $result;
|
2020-06-04 10:38:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Upload file related to the case notes
|
|
|
|
|
*
|
|
|
|
|
* @param string $userUid
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param array $filesReferences
|
2020-06-12 21:07:20 -04:00
|
|
|
* @param int $noteId
|
2020-06-04 10:38:48 -04:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function uploadFilesInCaseNotes($userUid, $appUid, $filesReferences = [], $noteId = 0)
|
|
|
|
|
{
|
2020-06-10 12:15:01 -04:00
|
|
|
$files = [];
|
|
|
|
|
if (!empty($_FILES["filesToUpload"])) {
|
2020-06-04 10:38:48 -04:00
|
|
|
$upload = true;
|
2020-06-10 12:15:01 -04:00
|
|
|
// This format is from ext-js multipart
|
|
|
|
|
$filesName = !empty($_FILES["filesToUpload"]["name"]) ? $_FILES["filesToUpload"]["name"] : [];
|
|
|
|
|
$filesTmpName = !empty($_FILES["filesToUpload"]["tmp_name"]) ? $_FILES["filesToUpload"]["tmp_name"] : [];
|
|
|
|
|
$filesError = !empty($_FILES["filesToUpload"]["error"]) ? $_FILES["filesToUpload"]["error"] : [];
|
|
|
|
|
|
|
|
|
|
foreach ($filesName as $index => $value) {
|
|
|
|
|
if (!empty($value)) {
|
2020-06-04 10:38:48 -04:00
|
|
|
$files[] = [
|
2020-06-10 12:15:01 -04:00
|
|
|
'name' => $filesName[$index],
|
|
|
|
|
'tmp_name' => $filesTmpName[$index],
|
|
|
|
|
'error' => $filesError[$index]
|
2020-06-04 10:38:48 -04:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} elseif (!empty($filesReferences)) {
|
|
|
|
|
$upload = false;
|
|
|
|
|
// Array with path references
|
|
|
|
|
foreach ($filesReferences as $fileIndex => $fileName) {
|
|
|
|
|
$nameFile = !is_numeric($fileIndex) ? basename($fileIndex) : basename($fileName);
|
|
|
|
|
$files[] = [
|
|
|
|
|
'name' => $nameFile,
|
|
|
|
|
'tmp_name' => $fileName,
|
|
|
|
|
'error' => UPLOAD_ERR_OK
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 18:59:01 -04:00
|
|
|
// Rules validation
|
2020-06-12 20:59:28 -04:00
|
|
|
foreach ($files as $key => $value) {
|
|
|
|
|
$entry = [
|
|
|
|
|
"filename" => $value['name'],
|
|
|
|
|
"path" => $value['tmp_name']
|
|
|
|
|
];
|
|
|
|
|
$validator = ValidationUploadedFiles::getValidationUploadedFiles()
|
|
|
|
|
->runRulesForPostFilesOfNote($entry);
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
Notes::where('NOTE_ID', '=', $noteId)->delete();
|
|
|
|
|
$messageError = G::LoadTranslation('ID_THE_FILE_COULDNT_BE_UPLOADED');
|
|
|
|
|
throw new CaseNoteUploadFile($messageError . ' ' . $validator->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-04 10:38:48 -04:00
|
|
|
// Get the delIndex related to the case
|
|
|
|
|
$cases = new ClassesCases();
|
|
|
|
|
$delIndex = $cases->getCurrentDelegation($appUid);
|
|
|
|
|
|
|
|
|
|
// We will to register the files in the database
|
|
|
|
|
$response = [];
|
2020-06-10 12:15:01 -04:00
|
|
|
$response['attachments'] = [];
|
|
|
|
|
$response['attachment_errors'] = [];
|
2020-06-04 10:38:48 -04:00
|
|
|
if (!empty($files)) {
|
|
|
|
|
$i = 0;
|
2020-06-10 12:15:01 -04:00
|
|
|
$j = 0;
|
2020-06-04 10:38:48 -04:00
|
|
|
foreach ($files as $fileIndex => $fileName) {
|
|
|
|
|
// There is no error, the file uploaded with success
|
|
|
|
|
if ($fileName["error"] === UPLOAD_ERR_OK) {
|
|
|
|
|
$appDocUid = G::generateUniqueID();
|
|
|
|
|
|
|
|
|
|
// Upload or move the file
|
|
|
|
|
$isUploaded = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload);
|
|
|
|
|
|
2020-06-10 12:15:01 -04:00
|
|
|
// If the file was uploaded correctly we will to register in the DB
|
|
|
|
|
if ($isUploaded) {
|
|
|
|
|
$attributes = [
|
|
|
|
|
"DOC_ID" => $noteId,
|
|
|
|
|
"APP_DOC_UID" => $appDocUid,
|
|
|
|
|
"DOC_VERSION" => 1,
|
|
|
|
|
"APP_UID" => $appUid,
|
|
|
|
|
"DEL_INDEX" => $delIndex,
|
|
|
|
|
"USR_UID" => $userUid,
|
|
|
|
|
"DOC_UID" => -1,
|
|
|
|
|
"APP_DOC_TYPE" => 'CASE_NOTE',
|
|
|
|
|
"APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),
|
|
|
|
|
"APP_DOC_FILENAME" => $fileName["name"]
|
|
|
|
|
];
|
|
|
|
|
Documents::create($attributes);
|
|
|
|
|
|
|
|
|
|
// List of files uploaded or copy
|
|
|
|
|
$response['attachments'][$i++] = $attributes;
|
|
|
|
|
} else {
|
|
|
|
|
$response['attachment_errors'][$j++] = [
|
|
|
|
|
'error' => 'error',
|
|
|
|
|
'file' => $fileName["name"]
|
|
|
|
|
];
|
|
|
|
|
}
|
2020-06-04 10:38:48 -04:00
|
|
|
} else {
|
|
|
|
|
throw new UploadException($fileName['error']);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-08 08:42:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run the validations related to an Input Document
|
|
|
|
|
*
|
|
|
|
|
* @param array $file
|
|
|
|
|
* @param mixed $inpDocUid
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
* @throws ExceptionRestApi
|
|
|
|
|
*/
|
|
|
|
|
private function canUploadFileRelatedToInput($file, $inpDocUid = -1)
|
|
|
|
|
{
|
|
|
|
|
if ($inpDocUid !== -1) {
|
|
|
|
|
$inputDocument = new InputDocument();
|
|
|
|
|
$inputExist = $inputDocument->InputExists($inpDocUid);
|
|
|
|
|
if ($inputExist) {
|
|
|
|
|
$inputProperties = $inputDocument->load($inpDocUid);
|
|
|
|
|
$inpDocTypeFile = $inputProperties['INP_DOC_TYPE_FILE'];
|
|
|
|
|
$inpDocMaxFileSize = (int)$inputProperties["INP_DOC_MAX_FILESIZE"];
|
|
|
|
|
$inpDocMaxFileSizeUnit = $inputProperties["INP_DOC_MAX_FILESIZE_UNIT"];
|
|
|
|
|
|
|
|
|
|
$validator = new FileValidator();
|
|
|
|
|
// Rule: extension
|
|
|
|
|
$validator->addRule()
|
|
|
|
|
->validate($file, function ($file) use ($inpDocTypeFile) {
|
|
|
|
|
$result = G::verifyInputDocExtension($inpDocTypeFile, $file->filename, $file->path);
|
|
|
|
|
|
|
|
|
|
return $result->status === false;
|
|
|
|
|
})
|
|
|
|
|
->status(415)
|
|
|
|
|
->message(G::LoadTranslation('ID_UPLOAD_INVALID_DOC_TYPE_FILE', [$inpDocTypeFile]))
|
|
|
|
|
->log(function ($rule) {
|
2020-08-10 17:11:55 -04:00
|
|
|
$message = $rule->getMessage();
|
|
|
|
|
$context = [
|
|
|
|
|
'filename' => $rule->getData()->filename,
|
|
|
|
|
'url' => $_SERVER["REQUEST_URI"] ?? ''
|
|
|
|
|
];
|
|
|
|
|
Log::channel(':phpUpload')->notice($message, Bootstrap::context($context));
|
2018-11-08 08:42:51 -04:00
|
|
|
});
|
|
|
|
|
// Rule: maximum file size
|
|
|
|
|
$validator->addRule()
|
|
|
|
|
->validate($file, function ($file) use ($inpDocMaxFileSize, $inpDocMaxFileSizeUnit) {
|
|
|
|
|
if ($inpDocMaxFileSize > 0) {
|
|
|
|
|
$totalMaxFileSize = $inpDocMaxFileSize * ($inpDocMaxFileSizeUnit == self::UNIT_MB ? self::MB_TO_KB * self::MB_TO_KB : self::MB_TO_KB);
|
|
|
|
|
$fileSize = filesize($file->path);
|
|
|
|
|
if ($fileSize > $totalMaxFileSize) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
})
|
|
|
|
|
->status(413)
|
|
|
|
|
->message(G::LoadTranslation("ID_UPLOAD_INVALID_DOC_MAX_FILESIZE",
|
|
|
|
|
[$inpDocMaxFileSize . $inpDocMaxFileSizeUnit]))
|
|
|
|
|
->log(function ($rule) {
|
2020-08-10 17:11:55 -04:00
|
|
|
$message = $rule->getMessage();
|
|
|
|
|
$context = [
|
|
|
|
|
'filename' => $rule->getData()->filename,
|
|
|
|
|
'url' => $_SERVER["REQUEST_URI"] ?? ''
|
|
|
|
|
];
|
|
|
|
|
Log::channel(':phpUpload')->notice($message, Bootstrap::context($context));
|
2018-11-08 08:42:51 -04:00
|
|
|
});
|
|
|
|
|
$validator->validate();
|
|
|
|
|
// We will to review if the validator has some error
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
throw new ExceptionRestApi($validator->getMessage(), $validator->getStatus());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-10-07 09:05:05 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the cases related to the self services timeout that needs to execute the trigger related
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static function executeSelfServiceTimeout()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$casesSelfService = ListUnassigned::selfServiceTimeout();
|
|
|
|
|
$casesExecuted = [];
|
|
|
|
|
foreach ($casesSelfService as $row) {
|
|
|
|
|
$appUid = $row["APP_UID"];
|
|
|
|
|
$appNumber = $row["APP_NUMBER"];
|
|
|
|
|
$delIndex = $row["DEL_INDEX"];
|
|
|
|
|
$delegateDate = $row["DEL_DELEGATE_DATE"];
|
|
|
|
|
$proUid = $row["PRO_UID"];
|
|
|
|
|
$taskUid = $row["TAS_UID"];
|
|
|
|
|
$taskSelfServiceTime = intval($row["TAS_SELFSERVICE_TIME"]);
|
|
|
|
|
$taskSelfServiceTimeUnit = $row["TAS_SELFSERVICE_TIME_UNIT"];
|
|
|
|
|
$triggerUid = $row["TAS_SELFSERVICE_TRIGGER_UID"];
|
|
|
|
|
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
|
|
|
|
$typeOfExecution = $row["TAS_SELFSERVICE_EXECUTION"];
|
|
|
|
|
$flagExecuteOnce = true;
|
|
|
|
|
// This option will be executed just once, can check if was executed before
|
|
|
|
|
if ($typeOfExecution == 'ONCE') {
|
|
|
|
|
$appTimeout = new AppTimeoutAction();
|
|
|
|
|
$appTimeout->setCaseUid($appUid);
|
|
|
|
|
$appTimeout->setIndex($delIndex);
|
|
|
|
|
$caseExecuted = $appTimeout->cases();
|
|
|
|
|
$flagExecuteOnce = !empty($caseExecuted) ? false : true;
|
|
|
|
|
}
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
|
|
|
|
|
|
|
|
|
// Add the time in the corresponding unit to the delegation date
|
|
|
|
|
$delegateDate = calculateDate($delegateDate, $taskSelfServiceTimeUnit, $taskSelfServiceTime);
|
2021-10-27 14:55:44 -04:00
|
|
|
$datetime = new DateTime($delegateDate);
|
|
|
|
|
//please the seconds is variant not must be considered
|
|
|
|
|
$delegateDate = $datetime->format('Y-m-d H:i:00');
|
2019-10-07 09:05:05 -04:00
|
|
|
|
|
|
|
|
// Define the current time
|
|
|
|
|
$datetime = new DateTime('now');
|
2021-10-27 14:55:44 -04:00
|
|
|
//please the seconds is variant not must be considered
|
|
|
|
|
$currentDate = $datetime->format('Y-m-d H:i:00');
|
|
|
|
|
$currentDate = UtilDateTime::convertDataToUtc($currentDate);
|
2019-10-07 09:05:05 -04:00
|
|
|
|
|
|
|
|
// Check if the triggers to be executed
|
|
|
|
|
if ($currentDate >= $delegateDate && $flagExecuteOnce) {
|
|
|
|
|
// Review if the session process is defined
|
|
|
|
|
$sessProcess = null;
|
|
|
|
|
$sessProcessSw = false;
|
|
|
|
|
if (isset($_SESSION["PROCESS"])) {
|
|
|
|
|
$sessProcess = $_SESSION["PROCESS"];
|
|
|
|
|
$sessProcessSw = true;
|
|
|
|
|
}
|
|
|
|
|
// Load case data
|
|
|
|
|
$case = new ClassesCases();
|
|
|
|
|
$appFields = $case->loadCase($appUid);
|
|
|
|
|
$appFields["APP_DATA"]["APPLICATION"] = $appUid;
|
|
|
|
|
// Set the process defined in the case related
|
|
|
|
|
$_SESSION["PROCESS"] = $appFields["PRO_UID"];
|
|
|
|
|
|
|
|
|
|
// Get the trigger related and execute
|
|
|
|
|
$triggersList = [];
|
|
|
|
|
if (!empty($triggerUid)) {
|
|
|
|
|
$trigger = new Triggers();
|
|
|
|
|
$trigger->setTrigger($triggerUid);
|
|
|
|
|
$triggersList = $trigger->triggers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the trigger exist, let's to execute
|
|
|
|
|
if (!empty($triggersList)) {
|
|
|
|
|
// Execute the trigger defined in the self service timeout
|
|
|
|
|
$fieldsCase['APP_DATA'] = $case->executeTriggerFromList(
|
|
|
|
|
$triggersList,
|
|
|
|
|
$appFields['APP_DATA'],
|
|
|
|
|
'SELF_SERVICE_TIMEOUT',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Update the case
|
|
|
|
|
$case->updateCase($appUid, $fieldsCase);
|
|
|
|
|
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
|
|
|
|
if ($typeOfExecution == 'ONCE') {
|
|
|
|
|
// Saving the case`s data if the 'Execution' is set in ONCE.
|
|
|
|
|
$appTimeoutActionExecuted = new AppTimeoutActionExecuted();
|
|
|
|
|
$dataSelf = [];
|
|
|
|
|
$dataSelf["APP_UID"] = $appUid;
|
|
|
|
|
$dataSelf["DEL_INDEX"] = $delIndex;
|
|
|
|
|
$dataSelf["EXECUTION_DATE"] = time();
|
|
|
|
|
$appTimeoutActionExecuted->create($dataSelf);
|
|
|
|
|
}
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
|
|
|
|
|
|
|
|
|
array_push($casesExecuted, $appNumber); // Register the cases executed
|
|
|
|
|
|
|
|
|
|
// Logging this action
|
|
|
|
|
$context = [
|
|
|
|
|
'appUid' => $appUid,
|
|
|
|
|
'appNumber' => $appNumber,
|
|
|
|
|
'triUid' => $triggerUid,
|
|
|
|
|
'proUid' => $proUid,
|
|
|
|
|
'tasUid' => $taskUid,
|
|
|
|
|
'selfServiceTime' => $taskSelfServiceTime,
|
|
|
|
|
'selfServiceTimeUnit' => $taskSelfServiceTimeUnit,
|
2021-10-27 14:55:44 -04:00
|
|
|
'currentDate' => $currentDate,
|
|
|
|
|
'delegateDate' => $delegateDate
|
2019-10-07 09:05:05 -04:00
|
|
|
];
|
2021-10-27 14:55:44 -04:00
|
|
|
Log::channel('taskScheduler:executeSelfServiceTimeout')->info('TriggerExecution', Bootstrap::context($context));
|
2019-10-07 09:05:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($_SESSION["PROCESS"]);
|
|
|
|
|
|
|
|
|
|
if ($sessProcessSw) {
|
|
|
|
|
$_SESSION["PROCESS"] = $sessProcess;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $casesExecuted;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-30 20:01:43 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get DynaForms Uids assigned as steps in the related process by application Uid
|
|
|
|
|
*
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param int $sourceTask
|
|
|
|
|
* @param string $dynUid
|
|
|
|
|
* @param string $caseStatus
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function dynaFormsByApplication($appUid, $sourceTask = 0, $dynUid = '', $caseStatus = '')
|
|
|
|
|
{
|
|
|
|
|
// Select distinct DYN_UID
|
|
|
|
|
$query = ModelApplication::query()->select('STEP.STEP_UID_OBJ AS DYN_UID')->distinct();
|
|
|
|
|
|
|
|
|
|
// Join with STEP table
|
|
|
|
|
$query->join('STEP', function ($join) {
|
|
|
|
|
$join->on('APPLICATION.PRO_UID', '=', 'STEP.PRO_UID');
|
|
|
|
|
$join->on('STEP.STEP_TYPE_OBJ', '=', DB::raw("'DYNAFORM'"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Filter by application Uid
|
|
|
|
|
$query->where('APPLICATION.APP_UID', '=', $appUid);
|
|
|
|
|
|
|
|
|
|
// Filter by source task
|
2021-03-29 09:34:36 -04:00
|
|
|
if (!empty($sourceTask) && (int)$sourceTask != 0) {
|
2020-11-30 20:01:43 +00:00
|
|
|
$query->where('STEP.TAS_UID', '=', $sourceTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter by DynaForm Uid
|
|
|
|
|
if ($dynUid != '' && $dynUid != '0') {
|
|
|
|
|
$query->where('STEP.STEP_UID_OBJ', '=', $dynUid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get results
|
|
|
|
|
$dynaForms = [];
|
|
|
|
|
$items = $query->get();
|
|
|
|
|
$items->each(function ($item) use (&$dynaForms) {
|
|
|
|
|
$dynaForms[] = $item->DYN_UID;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Return results
|
|
|
|
|
return $dynaForms;
|
|
|
|
|
}
|
2016-08-15 09:28:25 -04:00
|
|
|
}
|