Feat: Add ICS generator for disposition dates

This commit is contained in:
Björn Fromme
2023-10-20 14:26:52 +02:00
parent 004b189be9
commit 096ef06a1e
9 changed files with 224 additions and 4 deletions
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Service\Common;
use App\Entity\Disposition;
use Spatie\IcalendarGenerator\Components\Calendar;
use Spatie\IcalendarGenerator\Components\Event;
class IcsGenerator
{
public function __construct(private readonly Disposition $disposition)
{}
public function generate(): string
{
$assignment = $this->disposition->getAssignment();
$calendar = Calendar::create('MyE&P Team');
$label = sprintf('E&P: Einteilung als %s', $assignment->getJobProfile()->getName());
$address = sprintf("%s\n%s", $assignment->getDestination()->getProduct(), $assignment->getDestination()->getHotel());
$event = Event::create($label)
->startsAt($assignment->getEffectivePeriod()->start)
->endsAt($assignment->getEffectivePeriod()->end->modify('+1 day'))
->address($address)
->description($label)
;
if (null !== $contact = $assignment->getContact()) {
$event->organizer($contact->getEmail(), $contact);
}
$calendar->event($event);
return $calendar->get();
}
}