Skip to content

Commit 47fc147

Browse files
committed
Pausetraining: Update send mail conditions BT#16298
1 parent 9cc1fce commit 47fc147

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

main/inc/lib/message.lib.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ public static function send_message(
501501
if ($allowPauseFormation) {
502502
$extraFieldValue = new ExtraFieldValue('user');
503503
$allowEmailNotifications = $extraFieldValue->get_values_by_handler_and_field_variable(
504-
$receiverUserInfo['user_id'],
504+
$receiverUserId,
505505
'allow_notifications'
506506
);
507507

@@ -518,25 +518,29 @@ public static function send_message(
518518
}
519519

520520
if ($sendEmail) {
521-
$startDate = $extraFieldValue->get_values_by_handler_and_field_variable(
522-
$receiverUserInfo['user_id'],
523-
'start_pause_date'
524-
);
525-
$endDate = $extraFieldValue->get_values_by_handler_and_field_variable(
526-
$receiverUserInfo['user_id'],
527-
'end_pause_date'
528-
);
529-
530-
if (
531-
!empty($startDate) && isset($startDate['value']) && !empty($startDate['value']) &&
532-
!empty($endDate) && isset($endDate['value']) && !empty($endDate['value'])
533-
) {
534-
$now = time();
535-
$start = api_strtotime($startDate['value']);
536-
$end = api_strtotime($startDate['value']);
521+
// Check if user pause his formation.
522+
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($receiverUserId, 'pause_formation');
523+
if (!empty($pause) && isset($pause['value']) && 1 === (int) $pause['value']) {
524+
$startDate = $extraFieldValue->get_values_by_handler_and_field_variable(
525+
$receiverUserInfo['user_id'],
526+
'start_pause_date'
527+
);
528+
$endDate = $extraFieldValue->get_values_by_handler_and_field_variable(
529+
$receiverUserInfo['user_id'],
530+
'end_pause_date'
531+
);
537532

538-
if ($now > $start && $now < $end) {
539-
$sendEmail = false;
533+
if (
534+
!empty($startDate) && isset($startDate['value']) && !empty($startDate['value']) &&
535+
!empty($endDate) && isset($endDate['value']) && !empty($endDate['value'])
536+
) {
537+
$now = time();
538+
$start = api_strtotime($startDate['value']);
539+
$end = api_strtotime($startDate['value']);
540+
541+
if ($now > $start && $now < $end) {
542+
$sendEmail = false;
543+
}
540544
}
541545
}
542546
}

plugin/pausetraining/PauseTraining.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ public function runCron()
160160

161161
foreach ($userList as $userId) {
162162
$userInfo = api_get_user_info($userId);
163-
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'pause_formation');
164-
if (!empty($pause) && isset($pause['value']) && 1 == $pause['value']) {
165-
// Skip user because he paused his formation.
166-
continue;
167-
}
168-
169163
$template->assign('days', $day);
170164
$template->assign('user', $userInfo);
171165
$content = $template->fetch('pausetraining/view/notification_content.tpl');

0 commit comments

Comments
 (0)