diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index f34586f31..6d39a5039 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -1424,11 +1424,12 @@ class Cases * @access public * @param string $app_uid, Uid for case * @param array $app_data, Data for case variables + * @param string $dyn_uid, Uid for dynaform * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia */ - public function setCaseVariables($app_uid, $app_data) + public function setCaseVariables($app_uid, $app_data, $dyn_uid = null) { Validator::isString($app_uid, '$app_uid'); Validator::appUid($app_uid, '$app_uid'); @@ -1436,7 +1437,18 @@ class Cases $case = new \Cases(); $fields = $case->loadCase($app_uid); - $data['APP_DATA'] = array_merge($fields['APP_DATA'], $app_data); + $_POST['form'] = $app_data; + + if ($dyn_uid) { + $oDynaform = \DynaformPeer::retrieveByPK($dyn_uid); + + if ($oDynaform->getDynVersion() < 2) { + $oForm = new \Form ( $fields['PRO_UID'] . "/" . $dyn_uid, PATH_DYNAFORM ); + $oForm->validatePost(); + } + } + + $data['APP_DATA'] = array_merge($fields['APP_DATA'], $_POST['form']); $case->updateCase($app_uid, $data); } @@ -1905,123 +1917,4 @@ class Cases throw $e; } } - - protected static $excludeFields = array( - "dataFields" => array( - "SYS_LANG", "SYS_SKIN", "SYS_SYS", "APPLICATION", "PROCESS", - "TASK", "INDEX", "USER_LOGGED", "USR_USERNAME", "PIN"), - "dataFieldsPost" => array( - "APP_PARENT", "APP_STATUS", "PRO_UID", "APP_PROC_STATUS", "APP_PROC_CODE", - "APP_PARALLEL", "APP_INIT_USER", "APP_CUR_USER", "APP_CREATE_DATE", "APP_INIT_DATE", - "APP_FINISH_DATE", "APP_UPDATE_DATE", "APP_DATA", "APP_PIN", "APP_DESCRIPTION", - "STATUS", "TITLE", "DESCRIPTION", "CREATOR", "CREATE_DATE", "UPDATE_DATE") - ); - - public static function filterArrayKeys($data, $filter = array()) - { - $result = array(); - - foreach ($data as $key => $value) { - if (! in_array($key, $filter)) { - $result[$key] = $value; - } - } - - return $result; - } - - /** - * Get data - * - * @param string $applicationUid Unique id of Case - * - * return array Return an array with Data - */ - public function getCaseData($applicationUid) - { - try { - $aFieldsAssoc = array(); - - //Verify data - Validator::isString($applicationUid, '$app_uid'); - Validator::appUid($applicationUid, '$app_uid'); - - //Set variables - $case = new \Cases(); - $aFields = $case->loadCase($applicationUid); - - $aFields = $aFields['APP_DATA']; - - $aFields = self::filterArrayKeys($aFields, self::$excludeFields["dataFields"]); - - foreach($aFields as $key => $value) { - $aFieldsAssoc[] = array ('name' => $key, 'value' => $value); - } - - //Return - return $aFieldsAssoc; - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Get data non assoc - * - * @param string $applicationUid Unique id of Case - * - * return array Return an array with all Data - */ - public function getCaseDataNonAssoc($applicationUid) - { - try { - //Verify data - Validator::isString($applicationUid, '$app_uid'); - Validator::appUid($applicationUid, '$app_uid'); - - //Set variables - $case = new \Cases(); - $aFields = $case->loadCase($applicationUid); - - $aFields = $aFields['APP_DATA']; - - $aFields = self::filterArrayKeys($aFields, self::$excludeFields["dataFields"]); - - //Return - return $aFields; - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Post data - * - * @param string $applicationUid Unique id of Case - * @param array $data - * - * return array Return an array with all Data - */ - public function addCaseData($applicationUid, $data) - { - try { - Validator::isString($applicationUid, '$app_uid'); - Validator::appUid($applicationUid, '$app_uid'); - Validator::isArray($data, '$app_data'); - - $case = new \Cases(); - $aFields = $case->loadCase($applicationUid); - - $data['APP_DATA'] = array_merge($aFields['APP_DATA'], $data); - $case->updateCase($applicationUid, $data); - - $aFields = self::filterArrayKeys($aFields, self::$excludeFields["dataFieldsPost"]); - $aFields = array_change_key_case($aFields, CASE_LOWER); - //Return - return $aFields; - - } catch (\Exception $e) { - throw $e; - } - } } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Cases.php b/workflow/engine/src/ProcessMaker/Services/Api/Cases.php index fc62b89b2..3cc9ba728 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Cases.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Cases.php @@ -838,17 +838,18 @@ class Cases extends Api * * @param string $app_uid {@min 1}{@max 32} * @param array $request_data + * @param string $dyn_uid {@from path} * * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia * * @url PUT /:app_uid/variable */ - public function doPutCaseVariables($app_uid, $request_data) + public function doPutCaseVariables($app_uid, $request_data, $dyn_uid = '') { try { $cases = new \ProcessMaker\BusinessModel\Cases(); - $cases->setCaseVariables($app_uid, $request_data); + $cases->setCaseVariables($app_uid, $request_data, $dyn_uid); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } @@ -994,63 +995,5 @@ class Cases extends Api throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); } } - - /** - * @url GET /:app_uid/data/non-assoc - * - * @param string $app_uid {@min 32}{@max 32} - */ - public function doGetCaseDataNonAssoc($app_uid) - { - try { - $case = new \ProcessMaker\BusinessModel\Cases(); - $case->setFormatFieldNameInUppercase(false); - - $response = $case->getCaseDataNonAssoc($app_uid); - - return $response; - } catch (\Exception $e) { - throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); - } - } - - /** - * @url GET /:app_uid/data - * - * @param string $app_uid {@min 32}{@max 32} - */ - public function doGetCaseData($app_uid) - { - try { - $case = new \ProcessMaker\BusinessModel\Cases(); - $case->setFormatFieldNameInUppercase(false); - - $response = $case->getCaseData($app_uid); - - return $response; - } catch (\Exception $e) { - throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); - } - } - - /** - * @url POST /:app_uid/data - * - * @param string $app_uid {@min 32}{@max 32} - * @param array $variables {@from body} - * - */ - public function doPostCaseData($app_uid, $variables = null) - { - try { - $cases = new \ProcessMaker\BusinessModel\Cases(); - - $response = $cases->addCaseData($app_uid, $variables); - - return $response; - } catch (\Exception $e) { - throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); - } - } }