|
|
|
@ -125,9 +125,28 @@ class PauseTraining extends Plugin |
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
$usersNotificationPerDay = []; |
|
|
|
$usersNotificationPerDay = []; |
|
|
|
$users = []; |
|
|
|
$users = []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$extraFieldValue = new ExtraFieldValue('user'); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($enableDaysList as $day) { |
|
|
|
foreach ($enableDaysList as $day) { |
|
|
|
$day = (int) $day; |
|
|
|
$day = (int) $day; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (0 === $day) { |
|
|
|
|
|
|
|
echo 'Day = 0 avoided '.PHP_EOL; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hourStart = $day * 24; |
|
|
|
|
|
|
|
$hourEnd = $day + 1 * 24; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$date = new DateTime($now); |
|
|
|
|
|
|
|
$date->sub(new DateInterval('P'.$hourStart.'H')); |
|
|
|
|
|
|
|
$hourStart = $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$date = new DateTime($now); |
|
|
|
|
|
|
|
$date->sub(new DateInterval('P'.$hourEnd.'H')); |
|
|
|
|
|
|
|
$hourEnd = $date->format('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT |
|
|
|
$sql = "SELECT |
|
|
|
t.user_id, |
|
|
|
t.user_id, |
|
|
|
MAX(t.logout_course_date) max_course_date, |
|
|
|
MAX(t.logout_course_date) max_course_date, |
|
|
|
@ -142,23 +161,62 @@ class PauseTraining extends Plugin |
|
|
|
u.active = 1 |
|
|
|
u.active = 1 |
|
|
|
GROUP BY t.user_id |
|
|
|
GROUP BY t.user_id |
|
|
|
HAVING |
|
|
|
HAVING |
|
|
|
DATE_SUB('$now', INTERVAL '$day' DAY) > max_course_date AND |
|
|
|
(max_course_date BETWEEN '$hourStart' AND '$hourEnd') AND |
|
|
|
DATE_SUB('$now', INTERVAL '$day' DAY) > max_login_date |
|
|
|
(max_login_date BETWEEN '$hourStart' AND '$hourEnd') |
|
|
|
"; |
|
|
|
"; |
|
|
|
|
|
|
|
|
|
|
|
$rs = Database::query($sql); |
|
|
|
$rs = Database::query($sql); |
|
|
|
while ($user = Database::fetch_array($rs)) { |
|
|
|
while ($user = Database::fetch_array($rs)) { |
|
|
|
$userId = $user['user_id']; |
|
|
|
$userId = $user['user_id']; |
|
|
|
|
|
|
|
|
|
|
|
if (in_array($userId, $users)) { |
|
|
|
if (in_array($userId, $users)) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Take max date value. |
|
|
|
|
|
|
|
$maxCourseDate = $user['max_course_date']; |
|
|
|
|
|
|
|
$maxLoginDate = $user['max_login_date']; |
|
|
|
|
|
|
|
$maxDate = $maxCourseDate; |
|
|
|
|
|
|
|
if ($maxLoginDate > $maxCourseDate) { |
|
|
|
|
|
|
|
$maxDate = $maxLoginDate; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if user has selected to pause formation. |
|
|
|
|
|
|
|
$pause = $extraFieldValue->get_values_by_handler_and_field_variable($userId, 'pause_formation'); |
|
|
|
|
|
|
|
if (!empty($pause) && isset($pause['value']) && 1 == $pause['value']) { |
|
|
|
|
|
|
|
$startDate = $extraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$userId, |
|
|
|
|
|
|
|
'start_pause_date' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
$endDate = $extraFieldValue->get_values_by_handler_and_field_variable( |
|
|
|
|
|
|
|
$userId, |
|
|
|
|
|
|
|
'end_pause_date' |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
!empty($startDate) && isset($startDate['value']) && !empty($startDate['value']) && |
|
|
|
|
|
|
|
!empty($endDate) && isset($endDate['value']) && !empty($endDate['value']) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
$startDate = $startDate['value']; |
|
|
|
|
|
|
|
$endDate = $endDate['value']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ignore date if is between the pause formation. |
|
|
|
|
|
|
|
if ($maxDate > $startDate && $maxDate < $endDate) { |
|
|
|
|
|
|
|
echo "Message skipped for user #$userId because latest login is $maxDate and pause formation between $startDate - $endDate ".PHP_EOL; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo "User #$userId added to message queue because latest login is $maxDate between $hourStart AND $hourEnd".PHP_EOL; |
|
|
|
|
|
|
|
|
|
|
|
$users[] = $userId; |
|
|
|
$users[] = $userId; |
|
|
|
$usersNotificationPerDay[$day][] = $userId; |
|
|
|
$usersNotificationPerDay[$day][] = $userId; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($usersNotificationPerDay)) { |
|
|
|
if (!empty($usersNotificationPerDay)) { |
|
|
|
|
|
|
|
echo 'Now processing messages ...'.PHP_EOL; |
|
|
|
|
|
|
|
|
|
|
|
ksort($usersNotificationPerDay); |
|
|
|
ksort($usersNotificationPerDay); |
|
|
|
foreach ($usersNotificationPerDay as $day => $userList) { |
|
|
|
foreach ($usersNotificationPerDay as $day => $userList) { |
|
|
|
$template = new Template(); |
|
|
|
$template = new Template(); |
|
|
|
@ -169,8 +227,8 @@ class PauseTraining extends Plugin |
|
|
|
$template->assign('days', $day); |
|
|
|
$template->assign('days', $day); |
|
|
|
$template->assign('user', $userInfo); |
|
|
|
$template->assign('user', $userInfo); |
|
|
|
$content = $template->fetch('pausetraining/view/notification_content.tpl'); |
|
|
|
$content = $template->fetch('pausetraining/view/notification_content.tpl'); |
|
|
|
|
|
|
|
echo 'Ready to send a message "'.$title.'" to user #'.$userId.' '.$userInfo['complete_name'].PHP_EOL; |
|
|
|
MessageManager::send_message_simple($userId, $title, $content, $senderId); |
|
|
|
MessageManager::send_message_simple($userId, $title, $content, $senderId); |
|
|
|
echo 'Sending message "'.$title.'" to user #'.$userId.' '.$userInfo['complete_name'].PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|