diff --git a/workflow/engine/classes/class.derivation.php b/workflow/engine/classes/class.derivation.php index bb3f8c6bc..39fb57488 100755 --- a/workflow/engine/classes/class.derivation.php +++ b/workflow/engine/classes/class.derivation.php @@ -1401,6 +1401,7 @@ class Derivation { $iAppThreadIndex = $appFields['DEL_THREAD']; $delType = 'NORMAL'; + $sendNotificationsMobile = false; if (is_numeric( $nextDel['DEL_PRIORITY'] )) { $nextDel['DEL_PRIORITY'] = (isset( $nextDel['DEL_PRIORITY'] ) ? ($nextDel['DEL_PRIORITY'] >= 1 && $nextDel['DEL_PRIORITY'] <= 5 ? $nextDel['DEL_PRIORITY'] : '3') : '3'); @@ -1523,6 +1524,8 @@ class Derivation } } + $sendNotificationsMobile = $this->sendNotificationsMobile($aOldFields, $aSP, $aNewCase['INDEX']); + //If not is SYNCHRONOUS derivate one more time if ($aSP['SP_SYNCHRONOUS'] == 0) { $this->case->setDelInitDate( $currentDelegation['APP_UID'], $iNewDelIndex ); @@ -1553,6 +1556,10 @@ class Derivation } } } //end switch + + if($iNewDelIndex !== 0 && !$sendNotificationsMobile){ + $sendNotificationsMobile = $this->sendNotificationsMobile($appFields, $nextDel, $iNewDelIndex); + } return $iNewDelIndex; } @@ -1800,5 +1807,24 @@ class Derivation } } } + + /** + * @param $appFields + * @param $nextDel + * @param $iNewDelIndex + * @return bool + */ + private function sendNotificationsMobile($appFields, $nextDel, $iNewDelIndex) + { + try { + $notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice(); + if ($notificationMobile->checkMobileNotifications()) { + $notificationMobile->routeCaseNotificationDevice($appFields, $nextDel, $iNewDelIndex); + } + return true; + } catch (Exception $e) { + \G::log(G::loadTranslation('ID_NOTIFICATION_ERROR') . '|' . $e->getMessage(), PATH_DATA, "mobile.log"); + } + } } diff --git a/workflow/engine/classes/class.wsBase.php b/workflow/engine/classes/class.wsBase.php index 583b4a96e..5cc7103f5 100755 --- a/workflow/engine/classes/class.wsBase.php +++ b/workflow/engine/classes/class.wsBase.php @@ -2518,20 +2518,6 @@ class wsBase $oCase->sendNotifications( $appdel['TAS_UID'], $nextDelegations, $appFields['APP_DATA'], $caseId, $delIndex, $sFromName ); - // Send notifications Mobile - Start - try { - $notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice(); - if ($notificationMobile->checkMobileNotifications()) { - $oLight = new \ProcessMaker\BusinessModel\Light(); - $nextIndex = $oLight->getInformationDerivatedCase($appFields['APP_UID'], $delIndex); - $notificationMobile->routeCaseNotification($userId, $_SESSION["PROCESS"], $appdel['TAS_UID'], - $appFields, $nextDelegations, $nextIndex, $delIndex); - } - } catch (Exception $e) { - \G::log(G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . '|' . $e->getMessage() , PATH_DATA, "mobile.log"); - } - // Send notifications Mobile - End - //Save data - Start //$appFields = $oCase->loadCase($caseId); //$oCase->updateCase($caseId, $appFields); diff --git a/workflow/engine/methods/cases/cases_Derivate.php b/workflow/engine/methods/cases/cases_Derivate.php index fcb3195e5..237687f35 100755 --- a/workflow/engine/methods/cases/cases_Derivate.php +++ b/workflow/engine/methods/cases/cases_Derivate.php @@ -194,21 +194,6 @@ try { G::SendTemporalMessage( G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . ' - ' . $e->getMessage(), 'warning', 'string', null, '100%' ); } // Send notifications - End - - // Send notifications Mobile - Start - try { - $notificationMobile = new \ProcessMaker\BusinessModel\Light\NotificationDevice(); - if ($notificationMobile->checkMobileNotifications()) { - $oLight = new \ProcessMaker\BusinessModel\Light(); - $nextIndex = $oLight->getInformationDerivatedCase($appFields['APP_UID'], $appFields['DEL_INDEX']); - $notificationMobile->routeCaseNotification($_SESSION['USER_LOGGED'], $_SESSION['PROCESS'], $_SESSION['TASK'], - $appFields, $_POST['form']['TASKS'], $nextIndex, $appFields['DEL_INDEX']); - } - } catch (Exception $e) { - \G::log(G::loadTranslation( 'ID_NOTIFICATION_ERROR' ) . '|' . $e->getMessage() , PATH_DATA, "mobile.log"); - } - // Send notifications Mobile - End - // Events - Start $oEvent = new Event(); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php b/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php index a53f3649b..c1e369cd7 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Light/NotificationDevice.php @@ -154,107 +154,92 @@ class NotificationDevice } /** - * Send Message each user id - * - * @param array $request_data - * @author Ronald Quenta - * + * @param $appFields + * @param $nextDel + * @param $iNewDelIndex + * @return array + * @throws \Exception */ - public function routeCaseNotification($currentUserId, $processId, $currentTaskId, $appFields, $aTasks, - $nextIndex, $currentDelIndex) + public function routeCaseNotificationDevice($appFields, $nextDel, $iNewDelIndex) { try { $response = array(); $typeList = 'todo'; - foreach ($aTasks as $aTask) { - $arrayTaskUser = array(); - switch ($aTask["TAS_ASSIGN_TYPE"]) { - case "SELF_SERVICE": - $arrayTaskUser = $this->getTaskUserSelfService($aTask["TAS_UID"], $appFields); - $typeList = 'unassigned'; - break; - default: - if (isset($aTask["USR_UID"]) && !empty($aTask["USR_UID"])) { - $arrayTaskUser = $aTask["USR_UID"]; - } - break; + $arrayTaskUser = array(); + switch ($nextDel["TAS_ASSIGN_TYPE"]) { + case "SELF_SERVICE": + $arrayTaskUser = $this->getTaskUserSelfService($nextDel["TAS_UID"], $appFields); + $typeList = 'unassigned'; + break; + default: + if (isset($nextDel["USR_UID"]) && !empty($nextDel["USR_UID"])) { + $arrayTaskUser = $nextDel["USR_UID"]; + } + break; + } + + $userIds = $arrayTaskUser; + $message = '#' . $appFields['APP_NUMBER'] . ' : ' . $appFields['APP_TITLE']; + $data = array( + 'processId' => $appFields['PRO_UID'], + 'taskId' => $nextDel["TAS_UID"], + 'caseId' => $appFields['APP_UID'], + 'caseTitle' => $appFields['APP_TITLE'], + 'delIndex' => $iNewDelIndex, + 'typeList' => $typeList + ); + + if ($userIds) { + $oNoti = new \NotificationDevice(); + if (is_array($userIds)) { + $devices = $oNoti->loadUsersArrayId($userIds); + } else { + $devices = $oNoti->loadByUsersId($userIds); + $lists = new \ProcessMaker\BusinessModel\Lists(); + $counter = $lists->getCounters($userIds); + $light = new \ProcessMaker\Services\Api\Light(); + $result = $light->parserCountersCases($counter); + $data['counters'] = $result; } - $delIndex = null; - foreach ($nextIndex as $nIndex) { - if ($aTask['TAS_UID'] == $nIndex['TAS_UID']) { - $delIndex = $nIndex['DEL_INDEX']; - break; + $devicesAndroidIds = array(); + $devicesAppleIds = array(); + foreach ($devices as $dev) { + switch ($dev['DEV_TYPE']) { + case "apple": + $devicesAppleIds[] = $dev['DEV_REG_ID']; + break; + case "android": + $devicesAndroidIds[] = $dev['DEV_REG_ID']; + break; } } - - $userIds = $arrayTaskUser; - $message = '#'. $appFields['APP_NUMBER'] . ' : '.$appFields['APP_TITLE']; - $data = array( - 'processId' => $processId, - 'taskId' => $aTask["TAS_UID"], - 'caseId' => $appFields['APP_UID'], - 'caseTitle' => $appFields['APP_TITLE'], - 'delIndex' => $delIndex, - 'typeList' => $typeList - ); - - if ($userIds) { - $oNoti = new \NotificationDevice(); - $devices = array(); - if (is_array($userIds)) { - $devices = $oNoti->loadUsersArrayId($userIds); - } else { - $devices = $oNoti->loadByUsersId($userIds); - $lists = new \ProcessMaker\BusinessModel\Lists(); - $counter = $lists->getCounters($userIds); - $light = new \ProcessMaker\Services\Api\Light(); - $result = $light->parserCountersCases($counter); - $data['counters'] = $result; - } - - $devicesAndroidIds = array(); - $devicesAppleIds = array(); - foreach ($devices as $dev) { - switch ($dev['DEV_TYPE']) { - case "apple": - $devicesAppleIds[] = $dev['DEV_REG_ID']; - break; - case "android": - $devicesAndroidIds[] = $dev['DEV_REG_ID']; - break; - } - } - $isExistNextNotifications = $oNoti->isExistNextNotification($appFields['APP_UID'], - $currentDelIndex); - if (count($devicesAppleIds) > 0 && $isExistNextNotifications) { - $arrayData = array(); - $arrayData['NOT_FROM'] = $currentUserId; - $arrayData['DEV_TYPE'] = 'apple'; - $arrayData['DEV_UID'] = serialize($devicesAppleIds); - $arrayData['NOT_MSG'] = $message; - $arrayData['NOT_DATA'] = serialize($data); - $arrayData['NOT_STATUS'] = "pending"; - $notQueue = new \NotificationQueue(); - $notQueue->create($arrayData); - } - if (count($devicesAndroidIds) > 0 && $isExistNextNotifications) { - $arrayData = array(); - $arrayData['NOT_FROM'] = $currentUserId; - $arrayData['DEV_TYPE'] = 'android'; - $arrayData['DEV_UID'] = serialize($devicesAndroidIds); - $arrayData['NOT_MSG'] = $message; - $arrayData['NOT_DATA'] = serialize($data); - $arrayData['NOT_STATUS'] = "pending"; - $notQueue = new \NotificationQueue(); - $notQueue->create($arrayData); - } + if (count($devicesAppleIds) > 0) { + $arrayData = array(); + $arrayData['NOT_FROM'] = $appFields['APP_CUR_USER']; + $arrayData['DEV_TYPE'] = 'apple'; + $arrayData['DEV_UID'] = serialize($devicesAppleIds); + $arrayData['NOT_MSG'] = $message; + $arrayData['NOT_DATA'] = serialize($data); + $arrayData['NOT_STATUS'] = "pending"; + $notQueue = new \NotificationQueue(); + $notQueue->create($arrayData); + } + if (count($devicesAndroidIds) > 0) { + $arrayData = array(); + $arrayData['NOT_FROM'] = $appFields['APP_CUR_USER']; + $arrayData['DEV_TYPE'] = 'android'; + $arrayData['DEV_UID'] = serialize($devicesAndroidIds); + $arrayData['NOT_MSG'] = $message; + $arrayData['NOT_DATA'] = serialize($data); + $arrayData['NOT_STATUS'] = "pending"; + $notQueue = new \NotificationQueue(); + $notQueue->create($arrayData); } } } catch (\Exception $e) { throw new \Exception($e->getMessage(), Api::STAT_APP_EXCEPTION); } - return $response; }