From 392fc8951dc68aaeac86d12c3c0fea096c63b2f1 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Wed, 10 Aug 2016 15:33:49 -0400 Subject: [PATCH] HOR-1466 --- workflow/engine/classes/class.pmDynaform.php | 7 +++++++ .../src/ProcessMaker/BusinessModel/Cases.php | 20 +++++++++++++++++++ .../src/ProcessMaker/Services/Api/Light.php | 8 ++++++++ 3 files changed, 35 insertions(+) diff --git a/workflow/engine/classes/class.pmDynaform.php b/workflow/engine/classes/class.pmDynaform.php index d2f8354be..f88c6b441 100644 --- a/workflow/engine/classes/class.pmDynaform.php +++ b/workflow/engine/classes/class.pmDynaform.php @@ -678,6 +678,7 @@ class pmDynaform var sysLang = \"" . SYS_LANG . "\"; var isRTL = \"" . $this->isRTL . "\"; var pathRTLCss = \"" . $this->pathRTLCss . "\"; + var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . "; $(window).load(function () { var data = jsondata; @@ -736,6 +737,7 @@ class pmDynaform "var sysLang = '" . SYS_LANG . "';\n" . "var isRTL = " . $this->isRTL . ";\n" . "var pathRTLCss = '" . $this->pathRTLCss . "';\n" . + "var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . ";\n" . "$(window).load(function () {\n" . " var data = jsondata;\n" . " window.dynaform = new PMDynaform.core.Project({\n" . @@ -811,6 +813,7 @@ class pmDynaform "var sysLang = '" . SYS_LANG . "';\n" . "var isRTL = " . $this->isRTL . ";\n" . "var pathRTLCss = '" . $this->pathRTLCss . "';\n" . + "var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . ";\n" . "\n" . "\n" . "\n" . @@ -866,6 +869,7 @@ class pmDynaform var sysLang = \"" . SYS_LANG . "\"; var isRTL = \"" . $this->isRTL . "\"; var pathRTLCss = \"" . $this->pathRTLCss . "\"; + var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . "; @@ -908,6 +912,7 @@ class pmDynaform "var sysLang = '" . SYS_LANG . "';\n" . "var isRTL = " . $this->isRTL . ";\n" . "var pathRTLCss = '" . $this->pathRTLCss . "';\n" . + "var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . ";\n" . "\n" . "\n" . "
\n" . @@ -948,6 +953,7 @@ class pmDynaform "var sysLang = '" . SYS_LANG . "';\n" . "var isRTL = " . $this->isRTL . ";\n" . "var pathRTLCss = '" . $this->pathRTLCss . "';\n" . + "var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . ";\n" . "\n" . "\n" . "
\n" . @@ -1007,6 +1013,7 @@ class pmDynaform "var sysLang = '" . SYS_LANG . "';\n" . "var isRTL = " . $this->isRTL . ";\n" . "var pathRTLCss = '" . $this->pathRTLCss . "';\n" . + "var delIndex = " . (isset($this->fields["DEL_INDEX"]) ? $this->fields["DEL_INDEX"] : "null") . ";\n" . "\n" . "\n" . "
\n" . diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 0b39df0d3..6456fde2f 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -2914,5 +2914,25 @@ class Cases return G::json_encode($dataResponse); } + + /** + * if case already routed + * + * @param type $app_uid + * @param type $del_index + * @param type $usr_uid + * @throws type + */ + public function caseAlreadyRouted($app_uid, $del_index, $usr_uid = '') + { + $c = new \Criteria('workflow'); + $c->add(\AppDelegationPeer::APP_UID, $app_uid); + $c->add(\AppDelegationPeer::DEL_INDEX, $del_index); + if (!empty($usr_uid)) { + $c->add(\AppDelegationPeer::USR_UID, $usr_uid); + } + $c->add(\AppDelegationPeer::DEL_FINISH_DATE, null, \Criteria::ISNULL); + return !(boolean) \AppDelegationPeer::doCount($c); + } } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Light.php b/workflow/engine/src/ProcessMaker/Services/Api/Light.php index 709a0a4ff..f3bbd6e78 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Light.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Light.php @@ -1542,8 +1542,16 @@ class Light extends Api public function doPutCaseVariables($app_uid, $request_data, $dyn_uid = '', $del_index = 0) { try { + if ($del_index === null) { + throw (new \Exception(G::LoadTranslation('ID_CAN_NOT_BE_NULL', array('del_index')), Api::STAT_APP_EXCEPTION)); + } $usr_uid = $this->getUserId(); $cases = new \ProcessMaker\BusinessModel\Cases(); + if ($del_index > 0) { + if ($cases->caseAlreadyRouted($app_uid, $del_index, $usr_uid)) { + throw (new \Exception(G::LoadTranslation('ID_CASE_ALREADY_DERIVATED'), Api::STAT_APP_EXCEPTION)); + } + } $request_data = \ProcessMaker\Util\DateTime::convertDataToUtc($request_data); $cases->setCaseVariables($app_uid, $request_data, $dyn_uid, $usr_uid, $del_index); } catch (\Exception $e) {