2014-12-07 18:01:45 +01:00
|
|
|
<?php
|
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
use Engelsystem\Models\Shifts\Shift;
|
2018-10-09 21:47:31 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
function mail_shift_change(Shift $old_shift, Shift $new_shift)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2023-01-03 22:19:03 +01:00
|
|
|
$users = ShiftEntries_by_shift($old_shift->id);
|
|
|
|
$old_room = $old_shift->room;
|
|
|
|
$new_room = $new_shift->room;
|
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
|
|
|
|
2018-08-29 21:55:32 +02: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
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
if ($old_shift->shift_type_id != $new_shift->shift_type_id) {
|
|
|
|
$message .= sprintf(
|
|
|
|
__('* Shift type changed from %s to %s'),
|
|
|
|
$old_shift->shiftType->name,
|
|
|
|
$new_shift->shiftType->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
|
|
|
|
2023-01-03 22:19:03 +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
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
if ($old_shift->start->timestamp != $new_shift->start->timestamp) {
|
2017-01-02 15:43:36 +01:00
|
|
|
$message .= sprintf(
|
2022-10-18 19:15:22 +02:00
|
|
|
__('* Shift Start changed from %s to %s'),
|
2023-01-03 22:19:03 +01:00
|
|
|
$old_shift->start->format('Y-m-d H:i'),
|
|
|
|
$new_shift->start->format('Y-m-d H:i')
|
2022-10-18 19:15:22 +02: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
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
if ($old_shift->end->timestamp != $new_shift->end->timestamp) {
|
2017-01-02 15:43:36 +01:00
|
|
|
$message .= sprintf(
|
2022-10-18 19:15:22 +02:00
|
|
|
__('* Shift End changed from %s to %s'),
|
2023-01-03 22:19:03 +01:00
|
|
|
$old_shift->end->format('Y-m-d H:i'),
|
|
|
|
$new_shift->end->format('Y-m-d H:i')
|
2022-10-18 19:15:22 +02: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
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
if ($old_shift->room_id != $new_shift->room_id) {
|
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";
|
2018-08-29 21:55:32 +02:00
|
|
|
$message .= __('The updated Shift:') . "\n";
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
$message .= $new_shift->shiftType->name . "\n";
|
|
|
|
$message .= $new_shift->title . "\n";
|
|
|
|
$message .= $new_shift->start->format('Y-m-d H:i') . ' - ' . $new_shift->end->format('H:i') . "\n";
|
2021-12-25 17:08:29 +01:00
|
|
|
$message .= $new_room->name . "\n\n";
|
2023-01-03 22:19:03 +01:00
|
|
|
$message .= url('/shifts', ['action' => 'view', 'shift_id' => $new_shift->id]) . "\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,
|
2018-10-05 15:35:14 +02:00
|
|
|
__('Your Shift has changed'),
|
2017-12-25 23:12:52 +01:00
|
|
|
$message,
|
|
|
|
true
|
|
|
|
);
|
2017-01-02 03:57:23 +01:00
|
|
|
}
|
2016-09-29 09:50:31 +02:00
|
|
|
}
|
2014-12-07 19:43:48 +01:00
|
|
|
}
|
2014-12-07 18:01:45 +01:00
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
function mail_shift_assign(User $user, Shift $shift)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
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
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
$room = $shift->room;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-08-29 21:55:32 +02:00
|
|
|
$message = __('You have been assigned to a Shift:') . "\n";
|
2023-01-03 22:19:03 +01:00
|
|
|
$message .= $shift->shiftType->name . "\n";
|
|
|
|
$message .= $shift->title . "\n";
|
|
|
|
$message .= $shift->start->format('Y-m-d H:i') . ' - ' . $shift->end->format('H:i') . "\n";
|
2021-12-25 17:08:29 +01:00
|
|
|
$message .= $room->name . "\n\n";
|
2023-01-03 22:19:03 +01:00
|
|
|
$message .= url('/shifts', ['action' => 'view', 'shift_id' => $shift->id]) . "\n";
|
2017-01-03 03:22:48 +01:00
|
|
|
|
2018-10-05 15:35:14 +02:00
|
|
|
engelsystem_email_to_user($user, __('Assigned to Shift'), $message, true);
|
2014-12-07 19:43:48 +01:00
|
|
|
}
|
2014-12-07 18:01:45 +01:00
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
function mail_shift_removed(User $user, Shift $shift)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
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
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
$room = $shift->room;
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-08-29 21:55:32 +02:00
|
|
|
$message = __('You have been removed from a Shift:') . "\n";
|
2023-01-03 22:19:03 +01:00
|
|
|
$message .= $shift->shiftType->name . "\n";
|
|
|
|
$message .= $shift->title . "\n";
|
|
|
|
$message .= $shift->start->format('Y-m-d H:i') . ' - ' . $shift->end->format('H:i') . "\n";
|
2020-09-06 23:50:36 +02:00
|
|
|
$message .= $room->name . "\n";
|
2017-01-03 03:22:48 +01:00
|
|
|
|
2018-10-05 15:35:14 +02:00
|
|
|
engelsystem_email_to_user($user, __('Removed from Shift'), $message, true);
|
2014-12-07 18:01:45 +01:00
|
|
|
}
|