2022-07-31 19:17:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Events\Listener;
|
|
|
|
|
2023-01-03 22:19:03 +01:00
|
|
|
use Carbon\Carbon;
|
2022-07-31 19:17:44 +02:00
|
|
|
use Engelsystem\Helpers\Shifts;
|
|
|
|
use Engelsystem\Mail\EngelsystemMailer;
|
2023-10-15 19:25:55 +02:00
|
|
|
use Engelsystem\Models\Location;
|
2022-07-31 19:17:44 +02:00
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
use Engelsystem\Models\Worklog;
|
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
|
|
|
|
class Shift
|
|
|
|
{
|
|
|
|
public function __construct(
|
2022-12-15 19:57:02 +01:00
|
|
|
protected LoggerInterface $log,
|
|
|
|
protected EngelsystemMailer $mailer
|
2022-07-31 19:17:44 +02:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deletedEntryCreateWorklog(
|
|
|
|
User $user,
|
|
|
|
Carbon $start,
|
|
|
|
Carbon $end,
|
|
|
|
string $name,
|
|
|
|
string $title,
|
|
|
|
string $type,
|
2023-10-15 19:25:55 +02:00
|
|
|
Location $location,
|
2022-07-31 19:17:44 +02:00
|
|
|
bool $freeloaded
|
|
|
|
): void {
|
|
|
|
if ($freeloaded || $start > Carbon::now()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$workLog = new Worklog();
|
|
|
|
$workLog->user()->associate($user);
|
|
|
|
$workLog->creator()->associate(auth()->user());
|
|
|
|
$workLog->worked_at = $start->copy()->startOfDay();
|
|
|
|
$workLog->hours =
|
|
|
|
(($end->timestamp - $start->timestamp) / 60 / 60)
|
|
|
|
* Shifts::getNightShiftMultiplier($start, $end);
|
|
|
|
$workLog->comment = sprintf(
|
2023-02-04 02:43:47 +01:00
|
|
|
__('%s (%s as %s) in %s, %s - %s'),
|
2022-07-31 19:17:44 +02:00
|
|
|
$name,
|
|
|
|
$title,
|
|
|
|
$type,
|
2023-10-15 19:25:55 +02:00
|
|
|
$location->name,
|
2023-11-23 14:30:46 +01:00
|
|
|
$start->format(__('general.datetime')),
|
|
|
|
$end->format(__('general.datetime'))
|
2022-07-31 19:17:44 +02:00
|
|
|
);
|
|
|
|
$workLog->save();
|
|
|
|
|
|
|
|
$this->log->info(
|
|
|
|
'Created worklog entry from shift for {user} ({uid}): {worklog})',
|
|
|
|
['user' => $workLog->user->name, 'uid' => $workLog->user->id, 'worklog' => $workLog->comment]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deletedEntrySendEmail(
|
|
|
|
User $user,
|
|
|
|
Carbon $start,
|
|
|
|
Carbon $end,
|
|
|
|
string $name,
|
|
|
|
string $title,
|
|
|
|
string $type,
|
2023-10-15 19:25:55 +02:00
|
|
|
Location $location,
|
2022-07-31 19:17:44 +02:00
|
|
|
bool $freeloaded
|
|
|
|
): void {
|
|
|
|
if (!$user->settings->email_shiftinfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-01 21:52:42 +02:00
|
|
|
$this->mailer->sendViewTranslated(
|
|
|
|
$user,
|
|
|
|
'notification.shift.deleted',
|
|
|
|
'emails/worklog-from-shift',
|
|
|
|
[
|
|
|
|
'name' => $name,
|
|
|
|
'title' => $title,
|
|
|
|
'start' => $start,
|
|
|
|
'end' => $end,
|
2023-10-15 19:25:55 +02:00
|
|
|
'location' => $location,
|
2023-10-01 21:52:42 +02:00
|
|
|
'freeloaded' => $freeloaded,
|
|
|
|
'username' => $user->displayName,
|
|
|
|
]
|
|
|
|
);
|
2022-07-31 19:17:44 +02:00
|
|
|
}
|
|
|
|
}
|