You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.4 KiB
PHTML

<?php
4 years ago
use Engelsystem\Models\Room;
use Engelsystem\Models\User\User;
/**
* @param array $old_shift
* @param array $new_shift
*/
8 years ago
function mail_shift_change($old_shift, $new_shift)
{
$users = ShiftEntries_by_shift($old_shift['SID']);
4 years ago
$old_room = Room::find($old_shift['RID']);
$new_room = Room::find($new_shift['RID']);
8 years ago
$noticeable_changes = false;
8 years ago
$message = __('A Shift you are registered on has changed:');
8 years ago
$message .= "\n";
8 years ago
if ($old_shift['name'] != $new_shift['name']) {
$message .= sprintf(__('* Shift type changed from %s to %s'), $old_shift['name'], $new_shift['name']) . "\n";
$noticeable_changes = true;
8 years ago
}
8 years ago
if ($old_shift['title'] != $new_shift['title']) {
$message .= sprintf(__('* Shift title changed from %s to %s'), $old_shift['title'], $new_shift['title']) . "\n";
$noticeable_changes = true;
8 years ago
}
8 years ago
if ($old_shift['start'] != $new_shift['start']) {
8 years ago
$message .= sprintf(
__('* Shift Start changed from %s to %s'),
date('Y-m-d H:i', $old_shift['start']),
date('Y-m-d H:i', $new_shift['start'])
8 years ago
) . "\n";
$noticeable_changes = true;
8 years ago
}
8 years ago
if ($old_shift['end'] != $new_shift['end']) {
8 years ago
$message .= sprintf(
__('* Shift End changed from %s to %s'),
date('Y-m-d H:i', $old_shift['end']),
date('Y-m-d H:i', $new_shift['end'])
8 years ago
) . "\n";
$noticeable_changes = true;
8 years ago
}
8 years ago
if ($old_shift['RID'] != $new_shift['RID']) {
4 years ago
$message .= sprintf(__('* Shift Location changed from %s to %s'), $old_room->name, $new_room->name) . "\n";
$noticeable_changes = true;
8 years ago
}
8 years ago
if (!$noticeable_changes) {
8 years ago
// There are no changes worth sending an E-Mail
8 years ago
return;
8 years ago
}
8 years ago
8 years ago
$message .= "\n";
$message .= __('The updated Shift:') . "\n";
8 years ago
$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";
4 years ago
$message .= $new_room->name . "\n";
8 years ago
8 years ago
foreach ($users as $user) {
$user = (new User())->forceFill($user);
if ($user->settings->email_shiftinfo) {
engelsystem_email_to_user(
$user,
__('Your Shift has changed'),
$message,
true
);
8 years ago
}
}
}
/**
* @param array $shift
*/
8 years ago
function mail_shift_delete($shift)
{
$users = ShiftEntries_by_shift($shift['SID']);
4 years ago
$room = Room::find($shift['RID']);
8 years ago
$message = __('A Shift you are registered on was deleted:') . "\n";
8 years ago
$message .= $shift['name'] . "\n";
$message .= $shift['title'] . "\n";
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
4 years ago
$message .= $room->name . "\n";
8 years ago
8 years ago
foreach ($users as $user) {
$user = (new User())->forceFill($user);
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);
8 years ago
}
}
}
/**
* @param User $user
* @param array $shift
*/
8 years ago
function mail_shift_assign($user, $shift)
{
if (!$user->settings->email_shiftinfo) {
return;
}
8 years ago
4 years ago
$room = Room::find($shift['RID']);
8 years ago
$message = __('You have been assigned to a Shift:') . "\n";
$message .= $shift['name'] . "\n";
$message .= $shift['title'] . "\n";
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
4 years ago
$message .= $room->name . "\n";
engelsystem_email_to_user($user, __('Assigned to Shift'), $message, true);
}
/**
* @param User $user
* @param array $shift
*/
8 years ago
function mail_shift_removed($user, $shift)
{
if (!$user->settings->email_shiftinfo) {
return;
}
8 years ago
4 years ago
$room = Room::find($shift['RID']);
8 years ago
$message = __('You have been removed from a Shift:') . "\n";
$message .= $shift['name'] . "\n";
$message .= $shift['title'] . "\n";
$message .= date('Y-m-d H:i', $shift['start']) . ' - ' . date('H:i', $shift['end']) . "\n";
4 years ago
$message .= $room->name . "\n";
engelsystem_email_to_user($user, __('Removed from Shift'), $message, true);
}