engelsystem/includes/mailer/shifts_mailer.php

151 lines
4.6 KiB
PHP
Raw Permalink Normal View History

2014-12-07 18:01:45 +01:00
<?php
2020-09-06 23:50:36 +02:00
use Engelsystem\Models\Room;
2018-10-09 21:47:31 +02:00
use Engelsystem\Models\User\User;
2017-01-03 03:22:48 +01:00
/**
* @param array $old_shift
* @param array $new_shift
*/
2017-01-02 03:57:23 +01:00
function mail_shift_change($old_shift, $new_shift)
{
2017-01-03 14:12:17 +01:00
$users = ShiftEntries_by_shift($old_shift['SID']);
2020-09-06 23:50:36 +02:00
$old_room = Room::find($old_shift['RID']);
$new_room = Room::find($new_shift['RID']);
2017-01-02 15:43:36 +01:00
2017-01-03 03:22:48 +01:00
$noticeable_changes = false;
2017-01-02 15:43:36 +01:00
$message = __('A Shift you are registered on has changed:');
2017-01-02 03:57:23 +01:00
$message .= "\n";
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
if ($old_shift['name'] != $new_shift['name']) {
$message .= sprintf(__('* Shift type changed from %s to %s'), $old_shift['name'], $new_shift['name']) . "\n";
2017-01-03 03:22:48 +01:00
$noticeable_changes = true;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
if ($old_shift['title'] != $new_shift['title']) {
$message .= sprintf(__('* Shift title changed from %s to %s'), $old_shift['title'], $new_shift['title']) . "\n";
2017-01-03 03:22:48 +01:00
$noticeable_changes = true;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
if ($old_shift['start'] != $new_shift['start']) {
2017-01-02 15:43:36 +01:00
$message .= sprintf(
__('* Shift Start changed from %s to %s'),
2017-01-03 14:12:17 +01:00
date('Y-m-d H:i', $old_shift['start']),
date('Y-m-d H:i', $new_shift['start'])
2017-01-02 15:43:36 +01:00
) . "\n";
2017-01-03 03:22:48 +01:00
$noticeable_changes = true;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
if ($old_shift['end'] != $new_shift['end']) {
2017-01-02 15:43:36 +01:00
$message .= sprintf(
__('* Shift End changed from %s to %s'),
2017-01-03 14:12:17 +01:00
date('Y-m-d H:i', $old_shift['end']),
date('Y-m-d H:i', $new_shift['end'])
2017-01-02 15:43:36 +01:00
) . "\n";
2017-01-03 03:22:48 +01:00
$noticeable_changes = true;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
if ($old_shift['RID'] != $new_shift['RID']) {
2020-09-06 23:50:36 +02:00
$message .= sprintf(__('* Shift Location changed from %s to %s'), $old_room->name, $new_room->name) . "\n";
2017-01-03 03:22:48 +01:00
$noticeable_changes = true;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
2017-01-03 03:22:48 +01:00
if (!$noticeable_changes) {
2017-01-02 03:57:23 +01:00
// There are no changes worth sending an E-Mail
2017-01-02 15:43:36 +01:00
return;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
$message .= "\n";
$message .= __('The updated Shift:') . "\n";
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
$message .= $new_shift['name'] . "\n";
$message .= $new_shift['title'] . "\n";
$message .= date('Y-m-d H:i', $new_shift['start']) . ' - ' . date('H:i', $new_shift['end']) . "\n";
$message .= $new_room->name . "\n\n";
$message .= url('/shifts', ['action' => 'view', 'shift_id' => $new_shift['SID']]) . "\n";
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
foreach ($users as $user) {
2018-10-17 01:30:10 +02:00
$user = (new User())->forceFill($user);
2018-10-14 18:24:42 +02:00
if ($user->settings->email_shiftinfo) {
2017-12-25 23:12:52 +01:00
engelsystem_email_to_user(
$user,
__('Your Shift has changed'),
2017-12-25 23:12:52 +01:00
$message,
true
);
2017-01-02 03:57:23 +01:00
}
}
}
2014-12-07 18:01:45 +01:00
2017-01-03 03:22:48 +01:00
/**
* @param array $shift
*/
2017-01-02 03:57:23 +01:00
function mail_shift_delete($shift)
{
2017-01-03 14:12:17 +01:00
$users = ShiftEntries_by_shift($shift['SID']);
2020-09-06 23:50:36 +02:00
$room = Room::find($shift['RID']);
2017-01-02 15:43:36 +01:00
$message = __('A Shift you are registered on was deleted:') . "\n";
2017-01-02 15:43:36 +01:00
2017-01-03 14:12:17 +01:00
$message .= $shift['name'] . "\n";
$message .= $shift['title'] . "\n";
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
2020-09-06 23:50:36 +02:00
$message .= $room->name . "\n";
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
foreach ($users as $user) {
2018-10-17 01:30:10 +02:00
$user = (new User())->forceFill($user);
2018-10-14 18:24:42 +02:00
if ($user->settings->email_shiftinfo) {
$userMessage = $message;
if ($shift['start'] < time() && !$user['freeloaded']) {
$userMessage .= "\n" . __('Since the deleted shift was already done, we added a worklog entry instead, to keep your work hours correct.') . "\n";
}
engelsystem_email_to_user($user, __('Your Shift was deleted'), $userMessage, true);
2017-01-02 03:57:23 +01:00
}
}
}
2014-12-07 18:01:45 +01:00
2017-01-03 03:22:48 +01:00
/**
2018-10-09 21:47:31 +02:00
* @param User $user
2017-01-03 03:22:48 +01:00
* @param array $shift
*/
2017-01-02 03:57:23 +01:00
function mail_shift_assign($user, $shift)
{
2018-10-09 21:47:31 +02:00
if (!$user->settings->email_shiftinfo) {
2017-01-03 03:22:48 +01:00
return;
}
2017-01-02 15:43:36 +01:00
2020-09-06 23:50:36 +02:00
$room = Room::find($shift['RID']);
2017-01-02 15:43:36 +01:00
$message = __('You have been assigned to a Shift:') . "\n";
2017-01-03 14:12:17 +01:00
$message .= $shift['name'] . "\n";
$message .= $shift['title'] . "\n";
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
$message .= $room->name . "\n\n";
$message .= url('/shifts', ['action' => 'view', 'shift_id' => $shift['SID']]) . "\n";
2017-01-03 03:22:48 +01:00
engelsystem_email_to_user($user, __('Assigned to Shift'), $message, true);
}
2014-12-07 18:01:45 +01:00
2017-12-25 23:12:52 +01:00
/**
2018-10-09 21:47:31 +02:00
* @param User $user
2017-12-25 23:12:52 +01:00
* @param array $shift
*/
2017-01-02 03:57:23 +01:00
function mail_shift_removed($user, $shift)
{
2018-10-09 21:47:31 +02:00
if (!$user->settings->email_shiftinfo) {
2017-01-03 03:22:48 +01:00
return;
}
2017-01-02 15:43:36 +01:00
2020-09-06 23:50:36 +02:00
$room = Room::find($shift['RID']);
2017-01-02 15:43:36 +01:00
$message = __('You have been removed from a Shift:') . "\n";
2017-01-03 14:12:17 +01:00
$message .= $shift['name'] . "\n";
$message .= $shift['title'] . "\n";
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
2020-09-06 23:50:36 +02:00
$message .= $room->name . "\n";
2017-01-03 03:22:48 +01:00
engelsystem_email_to_user($user, __('Removed from Shift'), $message, true);
2014-12-07 18:01:45 +01:00
}