2014-12-07 18:01:45 +01:00
|
|
|
<?php
|
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
use Engelsystem\Models\Shifts\Shift;
|
2023-01-18 13:02:11 +01:00
|
|
|
use Engelsystem\Models\Shifts\ShiftEntry;
|
2018-10-09 21:47:31 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
2023-01-18 13:02:11 +01:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2018-10-09 21:47:31 +02:00
|
|
|
|
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-18 13:02:11 +01:00
|
|
|
/** @var ShiftEntry[]|Collection $shiftEntries */
|
|
|
|
$shiftEntries = $old_shift->shiftEntries()
|
|
|
|
->with(['user', 'user.settings'])
|
|
|
|
->get();
|
2023-10-15 19:25:55 +02:00
|
|
|
$old_location = $old_shift->location;
|
|
|
|
$new_location = $new_shift->location;
|
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-11-23 14:30:46 +01:00
|
|
|
$old_shift->start->format(__('general.datetime')),
|
|
|
|
$new_shift->start->format(__('general.datetime'))
|
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-11-23 14:30:46 +01:00
|
|
|
$old_shift->end->format(__('general.datetime')),
|
|
|
|
$new_shift->end->format(__('general.datetime'))
|
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-10-15 19:25:55 +02:00
|
|
|
if ($old_shift->location_id != $new_shift->location_id) {
|
|
|
|
$message .= sprintf(__('* Shift Location changed from %s to %s'), $old_location->name, $new_location->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";
|
2023-11-23 14:30:46 +01:00
|
|
|
$message .= $new_shift->start->format(__('general.datetime')) . ' - ' . $new_shift->end->format(__('H:i')) . "\n";
|
2023-10-15 19:25:55 +02:00
|
|
|
$message .= $new_location->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
|
|
|
|
2023-01-18 13:02:11 +01:00
|
|
|
foreach ($shiftEntries as $shiftEntry) {
|
|
|
|
$user = $shiftEntry->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
|
|
|
|
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";
|
2023-11-23 14:30:46 +01:00
|
|
|
$message .= $shift->start->format(__('general.datetime')) . ' - ' . $shift->end->format(__('H:i')) . "\n";
|
2023-10-15 19:25:55 +02:00
|
|
|
$message .= $shift->location->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
|
|
|
|
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";
|
2023-11-23 14:30:46 +01:00
|
|
|
$message .= $shift->start->format(__('general.datetime')) . ' - ' . $shift->end->format(__('H:i')) . "\n";
|
2023-10-15 19:25:55 +02:00
|
|
|
$message .= $shift->location->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
|
|
|
}
|