Feat: Add ICS generator for disposition dates
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user