Skip to content
Snippets Groups Projects
Commit 0132182b authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #17163 TIME 3:00 send all notification types in scheduler

parent a1621e0a
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ if (empty($restUser[0])) { ...@@ -25,7 +25,7 @@ if (empty($restUser[0])) {
$restUser = $restUser[0]; $restUser = $restUser[0];
$GLOBALS['id'] = $restUser['id']; $GLOBALS['id'] = $restUser['id'];
$applicationUrl = UrlController::getCoreUrl(); // TODO get url from configuration ? $applicationUrl = UrlController::getCoreUrl(); // TODO get url from configuration
$schedules = NotificationsScheduleModel::get(); $schedules = NotificationsScheduleModel::get();
...@@ -61,7 +61,7 @@ foreach ($schedules as $schedule) { ...@@ -61,7 +61,7 @@ foreach ($schedules as $schedule) {
continue; continue;
} elseif (!empty($schedule['frequency']) && $schedule['frequency_mode'] == 'minutes' && $difference->i < $schedule['frequency']) { } elseif (!empty($schedule['frequency']) && $schedule['frequency_mode'] == 'minutes' && $difference->i < $schedule['frequency']) {
continue; continue;
} elseif(!empty($schedule['frequency']) && $schedule['frequency_mode'] == 'minutes' && $difference->h < $schedule['frequency']) { } elseif(!empty($schedule['frequency']) && $schedule['frequency_mode'] == 'hours' && $difference->h < $schedule['frequency']) {
continue; continue;
} }
} }
...@@ -71,7 +71,7 @@ foreach ($schedules as $schedule) { ...@@ -71,7 +71,7 @@ foreach ($schedules as $schedule) {
if ($currentDate < $startTime) { if ($currentDate < $startTime) {
continue; continue;
} elseif (!empty($schedule['frequency']) && $lastExecution < $currentDate) { } elseif (!empty($schedule['frequency']) && $endTime < $currentDate) {
continue; continue;
} }
...@@ -88,10 +88,13 @@ foreach ($schedules as $schedule) { ...@@ -88,10 +88,13 @@ foreach ($schedules as $schedule) {
'data' => [$schedule['type']] 'data' => [$schedule['type']]
]); ]);
if ($schedule['type'] == 'next_user') { if (!empty($notificationStack)) {
$result = runNextUserNotification(['stack' => $notificationStack, 'restUser' => $restUser, 'applicationUrl' => $applicationUrl]); $result = sendNotifications([
} elseif ($schedule['type'] == 'typist_END') { 'type' => $schedule['type'],
$result = runTypistEnd(['stack' => $notificationStack, 'restUser' => $restUser, 'applicationUrl' => $applicationUrl]); 'stack' => $notificationStack,
'restUser' => $restUser,
'applicationUrl' => $applicationUrl
]);
} }
NotificationsScheduleModel::update([ NotificationsScheduleModel::update([
...@@ -101,11 +104,31 @@ foreach ($schedules as $schedule) { ...@@ -101,11 +104,31 @@ foreach ($schedules as $schedule) {
]); ]);
} }
function runNextUserNotification(array $args) function sendNotifications(array $args)
{ {
$notificationStack = $args['stack']; $notificationStack = $args['stack'];
$restUser = $args['restUser']; $restUser = $args['restUser'];
if ($args['type'] == 'next_user') {
$subjectKey = 'notificationDocumentsAddedSubject';
$bodyKey = 'notificationDocumentsAddedBody';
} elseif ($args['type'] == 'typist_END') {
$subjectKey = 'notificationEndOfWorkflowsSubject';
$bodyKey = 'notificationEndOfWorkflowsBody';
} elseif ($args['type'] == 'typist_INT') {
$subjectKey = 'notificationInterruptsSubject';
$bodyKey = 'notificationInterruptsBody';
} elseif ($args['type'] == 'typist_DEL') {
$subjectKey = 'notificationInterruptsSubject';
$bodyKey = 'notificationDeletedUsersBody';
} elseif ($args['type'] == 'typist_REF') {
$subjectKey = 'notificationRefusedWorkflowsSubject';
$bodyKey = 'notificationDeletedUsersBody';
} else {
$subjectKey = '';
$bodyKey = '';
}
$recipients = array_unique(array_column($notificationStack, 'recipient_id')); $recipients = array_unique(array_column($notificationStack, 'recipient_id'));
foreach ($recipients as $recipientId) { foreach ($recipients as $recipientId) {
...@@ -113,13 +136,11 @@ function runNextUserNotification(array $args) ...@@ -113,13 +136,11 @@ function runNextUserNotification(array $args)
return $notification['recipient_id'] == $recipientId; return $notification['recipient_id'] == $recipientId;
}); });
$recipient = UserModel::getById(['id' => $recipientId]); $recipient = UserModel::getById(['id' => $recipientId, 'select' => ['email', 'preferences']]);
$recipient['preferences'] = json_decode($recipient['preferences'], true); $recipient['preferences'] = json_decode($recipient['preferences'], true);
$lang = LanguageController::get(['lang' => $recipient['preferences']['lang']]); $lang = LanguageController::get(['lang' => $recipient['preferences']['lang']]);
$emailBody = $lang['notificationDocumentsAddedBody']; $emailBody = $lang[$bodyKey];
$rows = ''; $rows = '';
foreach ($recipientNotifications as $recipientNotification) { foreach ($recipientNotifications as $recipientNotification) {
...@@ -138,17 +159,21 @@ function runNextUserNotification(array $args) ...@@ -138,17 +159,21 @@ function runNextUserNotification(array $args)
'data' => [ 'data' => [
'sender' => 'Notification', 'sender' => 'Notification',
'recipients' => [$recipient['email']], 'recipients' => [$recipient['email']],
'subject' => $lang['notificationDocumentsAddedSubject'], 'subject' => $lang[$subjectKey],
'body' => $emailBody . $lang['notificationFooter'], 'body' => $emailBody . $lang['notificationFooter'],
'isHtml' => true 'isHtml' => true,
'status' => 'EXPRESS'
] ]
]); ]);
} }
return true; // $stackIds = array_column($notificationStack, 'id');
} // NotificationsScheduleModel::delete([
// 'where' => ['id in (?)'],
// 'data' => [$stackIds]
// ]);
function runTypistEnd(array $args)
{
return true; return true;
} }
...@@ -581,6 +581,13 @@ ...@@ -581,6 +581,13 @@
"manage_notificationsAdmin": "Planifier les notifications", "manage_notificationsAdmin": "Planifier les notifications",
"frquencyMonthly": "Chaque mois de <small class=\"primary\">{{months}}</small> le(s) <small class=\"primary\">{{daysOfMonth}}</small>", "frquencyMonthly": "Chaque mois de <small class=\"primary\">{{months}}</small> le(s) <small class=\"primary\">{{daysOfMonth}}</small>",
"frequencyDaily": "Tous les {{0}}", "frequencyDaily": "Tous les {{0}}",
"frequencyHourly": "Toute les <small class=\"primary\">{{frequency}}</small> de <small class=\"primary\">{{startTime}}</small> à <small class=\"primary\">{{endTime}}</small>" "frequencyHourly": "Toute les <small class=\"primary\">{{frequency}}</small> de <small class=\"primary\">{{startTime}}</small> à <small class=\"primary\">{{endTime}}</small>",
"notificationEndOfWorkflowsSubject": "[Maarch Parapheur] Circuits de visa terminés",
"notificationEndOfWorkflowsBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié se sont terminés avec succès.<br/><br/>Cliquez sur les liens ci-dessous pour les consulter :<br/>",
"notificationInterruptsSubject": "[Maarch Parapheur] Circuits de visa interrompus",
"notificationInterruptsBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié ont été interrompu.<br/><br/>Cliquez sur les liens ci-dessous pour les consulter :<br/>",
"notificationDeletedUsersBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié ont été interrompu car un utilisateur a été supprimé.<br/><br/>Cliquez sur les lien ci-dessous pour les consulter :<br/>",
"notificationRefusedWorkflowsSubject": "[Maarch Parapheur] Circuits de visa refusés",
"notificationRefusedWorkflowsBody": "Bonjour,<br/><br/>Des circuits de visa que vous avez initié ont été interrompu car un utilisateur a fait une action de refus.<br/><br/>Cliquez sur les liens ci-dessous pour les consulter :<br/>"
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment