diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index 5141aa304..1993e047c 100755 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -522,5 +522,18 @@ class AppDelegation extends BaseAppDelegation $data = $oRuleSet->getRow(); return (int)$data['DEL_INDEX']; } + + public function getCurrentTask ($appUid) + { + $oCriteria = new Criteria(); + $oCriteria->addSelectColumn( AppDelegationPeer::TAS_UID ); + $oCriteria->add( AppDelegationPeer::APP_UID, $appUid ); + $oCriteria->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX ); + $oRuleSet = AppDelegationPeer::doSelectRS( $oCriteria ); + $oRuleSet->setFetchmode( ResultSet::FETCHMODE_ASSOC ); + $oRuleSet->next(); + $data = $oRuleSet->getRow(); + return $data['TAS_UID']; + } } diff --git a/workflow/engine/src/BusinessModel/Cases.php b/workflow/engine/src/BusinessModel/Cases.php index cdd0dd79b..b59b5199d 100644 --- a/workflow/engine/src/BusinessModel/Cases.php +++ b/workflow/engine/src/BusinessModel/Cases.php @@ -1338,7 +1338,7 @@ class Cases * @author Brayan Pereyra (Cochalo) * @copyright Colosa - Bolivia */ - public function putCaseVariables($app_uid, $app_data) { + public function setCaseVariables($app_uid, $app_data) { Validator::isString($app_uid, '$app_uid'); Validator::appUid($app_uid, '$app_uid'); Validator::isArray($app_data, '$app_data'); @@ -1348,4 +1348,83 @@ class Cases $data = array_merge($fields['APP_DATA'], array('APP_DATA' => $app_data)); $case->updateCase($app_uid, $data); } + + /** + * Get Case Notes + * + * @access public + * @param string $app_uid, Uid for case + * @return array + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function getCaseNotes($app_uid, $usr_uid) { + Validator::isString($app_uid, '$app_uid'); + Validator::appUid($app_uid, '$app_uid'); + + $case = new \Cases(); + $caseLoad = $case->loadCase($app_uid); + $pro_uid = $caseLoad['PRO_UID']; + $tas_uid = \AppDelegation::getCurrentTask($app_uid); + $respView = $case->getAllObjectsFrom( $pro_uid, $app_uid, $tas_uid, $usr_uid, 'VIEW' ); + $respBlock = $case->getAllObjectsFrom( $pro_uid, $app_uid, $tas_uid, $usr_uid, 'BLOCK' ); + if ($respView['CASES_NOTES'] == 0 && $respBlock['CASES_NOTES'] == 0) { + throw (new \Exception("You do not have permission to cases notes.")); + } + + $appNote = new \AppNotes(); + $note_data = $appNote->getNotesList($app_uid); + $response = array(); + $response['total'] = $note_data['array']['totalCount']; + $response['notes'] = array(); + $con = 0; + foreach ($note_data['array']['notes'] as $value) { + $response['notes'][$con]['app_uid'] = $value['APP_UID']; + $response['notes'][$con]['usr_uid'] = $value['USR_UID']; + $response['notes'][$con]['note_date'] = $value['NOTE_DATE']; + $response['notes'][$con]['note_content'] = $value['NOTE_CONTENT']; + $con++; + } + return $response; + } + + /** + * Save new case note + * + * @access public + * @param string $app_uid, Uid for case + * @param array $app_data, Data for case variables + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function saveCaseNote($app_uid, $usr_uid, $note_content, $send_mail = false) { + Validator::isString($app_uid, '$app_uid'); + Validator::appUid($app_uid, '$app_uid'); + + Validator::isString($usr_uid, '$usr_uid'); + Validator::usrUid($usr_uid, '$usr_uid'); + + Validator::isString($note_content, '$note_content'); + if (strlen($note_content) > 500) { + throw (new \Exception("Invalid value for '$note_content', the permitted maximum length of 500 characters.")); + } + + Validator::isBoolean($send_mail, '$send_mail'); + + $case = new \Cases(); + $caseLoad = $case->loadCase($app_uid); + $pro_uid = $caseLoad['PRO_UID']; + $tas_uid = \AppDelegation::getCurrentTask($app_uid); + $respView = $case->getAllObjectsFrom( $pro_uid, $app_uid, $tas_uid, $usr_uid, 'VIEW' ); + $respBlock = $case->getAllObjectsFrom( $pro_uid, $app_uid, $tas_uid, $usr_uid, 'BLOCK' ); + if ($respView['CASES_NOTES'] == 0 && $respBlock['CASES_NOTES'] == 0) { + throw (new \Exception("You do not have permission to cases notes.")); + } + + $note_content = addslashes($note_content); + $appNote = new \AppNotes(); + $appNote->addCaseNote($app_uid, $usr_uid, $note_content, intval($send_mail)); + } } \ No newline at end of file diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Cases.php b/workflow/engine/src/Services/Api/ProcessMaker/Cases.php index 54225af89..8cd13b9e2 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Cases.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Cases.php @@ -859,7 +859,53 @@ class Cases extends Api { try { $cases = new \BusinessModel\Cases(); - $cases->putCaseVariables($app_uid, $request_data); + $cases->setCaseVariables($app_uid, $request_data); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * Get Case Notes + * + * @param string $app_uid {@min 1}{@max 32} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url GET /:app_uid/notes + */ + public function doGetCaseNotes($app_uid) + { + try { + $usr_uid = $this->getUserId(); + $cases = new \BusinessModel\Cases(); + $response = $cases->getCaseNotes($app_uid, $usr_uid); + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * Put Case Variables + * + * @param string $app_uid {@min 1}{@max 32} + * @param string $note_content {@min 1}{@max 500} + * @param int $send_mail {@choice 1,0} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url POST /:app_uid/note + */ + public function doPostCaseNote($app_uid, $note_content, $send_mail = 0) + { + try { + $usr_uid = $this->getUserId(); + $cases = new \BusinessModel\Cases(); + $send_mail = ($send_mail == 0) ? false : true; + $cases->saveCaseNote($app_uid, $usr_uid, $note_content, $send_mail); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); }