diff --git a/workflow/engine/classes/class.wsBase.php b/workflow/engine/classes/class.wsBase.php index 806dbff6e..031a2f05e 100755 --- a/workflow/engine/classes/class.wsBase.php +++ b/workflow/engine/classes/class.wsBase.php @@ -2585,6 +2585,7 @@ class wsBase $oCriteria = new Criteria( 'workflow' ); $oCriteria->addSelectColumn( AppDelayPeer::APP_UID ); $oCriteria->addSelectColumn( AppDelayPeer::APP_DEL_INDEX ); + $oCriteria->addSelectColumn( AppDelayPeer::APP_DISABLE_ACTION_USER ); $oCriteria->add( AppDelayPeer::APP_TYPE, '' ); $oCriteria->add( $oCriteria->getNewCriterion( AppDelayPeer::APP_TYPE, 'PAUSE' )->addOr( $oCriteria->getNewCriterion( AppDelayPeer::APP_TYPE, 'CANCEL' ) ) ); $oCriteria->addAscendingOrderByColumn( AppDelayPeer::APP_ENABLE_ACTION_DATE ); diff --git a/workflow/engine/classes/model/AdditionalTables.php b/workflow/engine/classes/model/AdditionalTables.php index a51ee0338..7448f60d3 100755 --- a/workflow/engine/classes/model/AdditionalTables.php +++ b/workflow/engine/classes/model/AdditionalTables.php @@ -831,6 +831,9 @@ class AdditionalTables extends BaseAdditionalTables //switching by report table type case 'NORMAL': // parsing empty values to null + if (!is_array($caseData)) { + $caseData = unserialize($caseData); + } foreach ($caseData as $i => $v) { foreach ($fieldTypes as $key => $fieldType) { foreach ($fieldType as $name => $type) { diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php index 6cd2af457..5141aa304 100755 --- a/workflow/engine/classes/model/AppDelegation.php +++ b/workflow/engine/classes/model/AppDelegation.php @@ -290,7 +290,7 @@ class AppDelegation extends BaseAppDelegation $aCalendarUID = ''; } - //use the dates class to calculate dates + //use the dates class to calculate dates $calendar = new calendar(); if ($calendar->pmCalendarUid == '') { @@ -509,5 +509,18 @@ class AppDelegation extends BaseAppDelegation $rs->next(); return $rs->getRow(); } + + public function getCurrentIndex ($appUid) + { + $oCriteria = new Criteria(); + $oCriteria->addSelectColumn( AppDelegationPeer::DEL_INDEX ); + $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 (int)$data['DEL_INDEX']; + } } diff --git a/workflow/engine/src/BusinessModel/Cases.php b/workflow/engine/src/BusinessModel/Cases.php index 86c6f0698..9090bfc63 100644 --- a/workflow/engine/src/BusinessModel/Cases.php +++ b/workflow/engine/src/BusinessModel/Cases.php @@ -404,4 +404,118 @@ class Cases } } + /** + * Put cancel case + * + * @access public + * @param string $app_uid, Uid for case + * @param string $usr_uid, Uid for user + * @param string $del_index, Index for case + * @return array + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function putCancelCase($app_uid, $usr_uid, $del_index = false) { + Validator::appUid($app_uid, '$cas_uid'); + Validator::usrUid($usr_uid, '$usr_uid'); + + if ($del_index === false) { + $del_index = \AppDelegation::getCurrentIndex($app_uid); + } + + $case = new \Cases(); + $case->cancelCase( $app_uid, $del_index, $usr_uid ); + } + + /** + * Put pause case + * + * @access public + * @param string $app_uid , Uid for case + * @param string $usr_uid , Uid for user + * @param bool|string $del_index , Index for case + * @param null|string $unpaused_date, Date for unpaused + * @return array + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function putPauseCase($app_uid, $usr_uid, $del_index = false, $unpaused_date = null) { + Validator::appUid($app_uid, '$cas_uid'); + Validator::usrUid($usr_uid, '$usr_uid'); + if ($unpaused_date != null) { + Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date'); + } + + if ($del_index === false) { + $del_index = \AppDelegation::getCurrentIndex($app_uid); + } + + $case = new \Cases(); + $case->pauseCase( $app_uid, $del_index, $usr_uid, $unpaused_date ); + } + + /** + * Put unpause case + * + * @access public + * @param string $app_uid , Uid for case + * @param string $usr_uid , Uid for user + * @param bool|string $del_index , Index for case + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function putUnpauseCase($app_uid, $usr_uid, $del_index = false) { + Validator::appUid($app_uid, '$cas_uid'); + Validator::usrUid($usr_uid, '$usr_uid'); + + if ($del_index === false) { + $del_index = \AppDelegation::getCurrentIndex($app_uid); + } + + $case = new \Cases(); + $case->unpauseCase( $app_uid, $del_index, $usr_uid ); + } + + /** + * Put unpause case + * + * @access public + * @param string $app_uid , Uid for case + * @param string $usr_uid , Uid for user + * @param bool|string $del_index , Index for case + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function putExecuteTriggerCase($app_uid, $tri_uid, $usr_uid, $del_index = false) { + Validator::appUid($app_uid, '$cas_uid'); + Validator::triUid($tri_uid, '$tri_uid'); + Validator::usrUid($usr_uid, '$usr_uid'); + + if ($del_index === false) { + $del_index = \AppDelegation::getCurrentIndex($app_uid); + } + + $case = new \wsBase(); + $case->executeTrigger( $usr_uid, $app_uid, $tri_uid, $del_index ); + } + + /** + * Delete case + * + * @access public + * @param string $app_uid, Uid for case + * @return array + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + */ + public function deleteCase($app_uid) { + Validator::appUid($app_uid, '$cas_uid'); + $case = new \Cases(); + $case->removeCase( $app_uid ); + } } diff --git a/workflow/engine/src/BusinessModel/Validator.php b/workflow/engine/src/BusinessModel/Validator.php index 0e81a0c68..85324878e 100644 --- a/workflow/engine/src/BusinessModel/Validator.php +++ b/workflow/engine/src/BusinessModel/Validator.php @@ -98,8 +98,9 @@ class Validator{ /** * Validate usr_uid - * @var string $dep_uid. Uid for Departament - * @var string $nameField. Name of field for message + * + * @param string $usr_uid, Uid for user + * @param string $nameField . Name of field for message * * @access public * @author Brayan Pereyra (Cochalo) @@ -120,6 +121,81 @@ class Validator{ return $usr_uid; } + /** + * Validate app_uid + * + * @param string $app_uid, Uid for application + * @param string $nameField . Name of field for message + * + * @access public + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return string + */ + static public function appUid($app_uid, $nameField = 'app_uid') + { + $app_uid = trim($app_uid); + if ($app_uid == '') { + throw (new \Exception("The application with $nameField: '' does not exist.")); + } + $oApplication = new \Application(); + if (!($oApplication->exists($app_uid))) { + throw (new \Exception("The application with $nameField: '$app_uid' does not exist.")); + } + return $app_uid; + } + + /** + * Validate app_uid + * + * @param string $tri_uid, Uid for trigger + * @param string $nameField . Name of field for message + * + * @access public + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return string + */ + static public function triUid($tri_uid, $nameField = 'tri_uid') + { + $tri_uid = trim($tri_uid); + if ($tri_uid == '') { + throw (new \Exception("The trigger with $nameField: '' does not exist.")); + } + $oTriggers = new \Triggers(); + if (!($oTriggers->TriggerExists($tri_uid))) { + throw (new \Exception("The trigger with $nameField: '$tri_uid' does not exist.")); + } + return $tri_uid; + } + + /** + * Validate date + * + * @param string $date, Date for validate + * @param string $nameField . Name of field for message + * + * @access public + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return string + */ + static public function isDate($date, $format = 'Y-m-d H:i:s', $nameField = 'app_uid') + { + $date = trim($date); + if ($date == '') { + throw (new \Exception("The value '' is not valid fot the format '$format'.")); + } + $d = \DateTime::createFromFormat($format, $date); + if (!($d && $d->format($format) == $date)) { + throw (new \Exception("The value '$date' is not valid fot the format '$format'.")); + } + return $date; + } + /** * Validate is array * @var array $field. Field type array diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Cases.php b/workflow/engine/src/Services/Api/ProcessMaker/Cases.php index 34f0e83a5..845bac5a7 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Cases.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Cases.php @@ -18,7 +18,6 @@ class Cases extends Api /** * Get list Cases To Do * - * @access public * @param array $request_data , Data for list * @return array * @@ -30,6 +29,8 @@ class Cases extends Api public function doGetCasesListToDo($request_data = array()) { try { + \G::pr($this->getUserId()); + die('fin'); $request_data['action'] = 'todo'; $request_data['userId'] = $this->getUserId(); $oCases = new \BusinessModel\Cases(); @@ -43,7 +44,6 @@ class Cases extends Api /** * Get list Cases Draft * - * @access public * @param array $request_data , Data for list * @return array * @@ -68,7 +68,6 @@ class Cases extends Api /** * Get list Cases Participated * - * @access public * @param array $request_data , Data for list * @return array * @@ -93,7 +92,6 @@ class Cases extends Api /** * Get list Cases Unassigned * - * @access public * @param array $request_data , Data for list * @return array * @@ -118,7 +116,6 @@ class Cases extends Api /** * Get list Cases Paused * - * @access public * @param array $request_data , Data for list * @return array * @@ -143,7 +140,6 @@ class Cases extends Api /** * Get list Cases Advanced Search * - * @access public * @param array $request_data , Data for list * @return array * @@ -256,8 +252,7 @@ class Cases extends Api $arrayData = $cases->updateReassignCase($cas_uid, $userUid, $del_index, $usr_uid_source, $usr_uid_target); $response = $arrayData; return $response; - } catch (\Exception $e) { - throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } @@ -280,5 +275,115 @@ class Cases extends Api throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } + + /** + * Cancel Case + * + * @param string $cas_uid {@min 1}{@max 32} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url PUT /:cas_uid/cancel-case + */ + public function doPutCancelCase($cas_uid) + { + try { + $userUid = $this->getUserId(); + $cases = new \BusinessModel\Cases(); + $cases->putCancelCase($cas_uid, $userUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * Pause Case + * + * @param string $cas_uid {@min 1}{@max 32} + * @param string $unpaused_date {@from body} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url PUT /:cas_uid/pause-case + */ + public function doPutPauseCase($cas_uid, $unpaused_date = null) + { + try { + $userUid = $this->getUserId(); + $cases = new \BusinessModel\Cases(); + if ($unpaused_date == null) { + $cases->putPauseCase($cas_uid, $userUid); + } else { + $cases->putPauseCase($cas_uid, $userUid, false, $unpaused_date); + } + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * Unpause Case + * + * @param string $cas_uid {@min 1}{@max 32} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url PUT /:cas_uid/unpause-case + */ + public function doPutUnpauseCase($cas_uid) + { + try { + $userUid = $this->getUserId(); + $cases = new \BusinessModel\Cases(); + $cases->putUnpauseCase($cas_uid, $userUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * Unpause Case + * + * @param string $cas_uid {@min 1}{@max 32} + * @param string $tri_uid {@min 1}{@max 32} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url PUT /:cas_uid/execute-trigger/:tri_uid + */ + public function doPutExecuteTriggerCase($cas_uid, $tri_uid) + { + try { + $userUid = $this->getUserId(); + $cases = new \BusinessModel\Cases(); + $cases->putExecuteTriggerCase($cas_uid, $tri_uid, $userUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * Delete Case + * + * @param string $cas_uid {@min 1}{@max 32} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url DELETE /:cas_uid + */ + public function doDeleteCase($cas_uid) + { + try { + $cases = new \BusinessModel\Cases(); + $cases->deleteCase($cas_uid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } }