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
@@ -16,6 +16,7 @@ class ContractPdfController extends AbstractController
{}
#[Route('/teamer/disposition/contract/{uuid}', name: 'app_teamer_disposition_contractpdf')]
#[IsGranted('ROLE_TEAMER')]
#[IsGranted('CONTRACT', subject: 'disposition')]
public function index(Disposition $disposition): Response
{
@@ -32,6 +32,7 @@ class DetailController extends AbstractController
}
#[Route('/teamer/disposition/detail/{uuid}', name: 'app_teamer_disposition_detail')]
#[IsGranted('ROLE_TEAMER')]
#[IsGranted('VIEW', subject: 'disposition')]
public function index(Disposition $disposition, Request $request): Response
{
@@ -0,0 +1,38 @@
<?php
namespace App\Controller\Teamer\Disposition;
use App\Entity\Disposition;
use App\Service\Common\IcsGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class IcsController extends AbstractController
{
#[Route('/teamer/disposition/ics/{uuid}', name: 'app_teamer_disposition_ics')]
#[IsGranted('ROLE_TEAMER')]
#[IsGranted('VIEW', subject: 'disposition')]
public function index(Disposition $disposition): Response
{
$assignment = $disposition->getAssignment();
$jobProfile = $assignment->getJobProfile();
$ics = (new IcsGenerator($disposition))->generate();
$filename = sprintf(
'Einteilung_%s_%s-%s.ics',
$jobProfile->getName(),
$assignment->getEffectivePeriod()->start->format('d.m.Y'),
$assignment->getEffectivePeriod()->end->format('d.m.Y')
);
$disposition = HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_INLINE, $filename, md5($filename));
$response = new Response($ics);
$response->setPrivate();
$response->headers->set('Content-type', 'text/calendar');
$response->headers->set('Content-Disposition', $disposition);
return $response;
}
}
@@ -16,6 +16,7 @@ class InvoicePdfController extends AbstractController
{}
#[Route('/teamer/disposition/invoice/{uuid}', name: 'app_teamer_disposition_invoicepdf')]
#[IsGranted('ROLE_TEAMER')]
#[IsGranted('INVOICE', subject: 'disposition')]
public function index(Disposition $disposition): Response
{
+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();
}
}