64 lines
2.1 KiB
PHP
64 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Teamer\Disposition;
|
|
|
|
use App\Entity\Disposition;
|
|
use App\Entity\User;
|
|
use App\Service\Common\IcsGenerator;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\HeaderUtils;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
use Symfony\Component\String\Slugger\AsciiSlugger;
|
|
|
|
class IcsController extends AbstractController
|
|
{
|
|
public function __construct(private readonly LoggerInterface $logger)
|
|
{
|
|
}
|
|
|
|
#[Route('/teamer/disposition/ics/{uuid}', name: 'app_teamer_disposition_ics')]
|
|
#[IsGranted('ROLE_TEAMER')]
|
|
#[IsGranted('VIEW', subject: 'disposition')]
|
|
public function index(Disposition $disposition): Response
|
|
{
|
|
/** @var User $user */
|
|
$user = $this->getUser();
|
|
$teamer = $user->getTeamer();
|
|
$assignment = $disposition->getAssignment();
|
|
$destination = $assignment->getDestination();
|
|
$jobProfile = $assignment->getJobProfile();
|
|
|
|
$ics = (new IcsGenerator($disposition))->generate();
|
|
$filename = sprintf(
|
|
'Einteilung_%s_%s-%s.ics',
|
|
$jobProfile->getName(),
|
|
$destination->getDateFrom()->format('d.m.Y'),
|
|
$destination->getDateTo()->format('d.m.Y')
|
|
);
|
|
$slugger = new AsciiSlugger();
|
|
$filename = $slugger->slug($filename);
|
|
$contentDisposition = 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', $contentDisposition);
|
|
|
|
$this->logger->info('Create ICS file', [
|
|
'assignment_id' => $assignment->getId(),
|
|
'destination' => (string) $destination,
|
|
'teamer_id' => $teamer->getId(),
|
|
'teamer_name' => (string) $teamer,
|
|
]);
|
|
|
|
return $response;
|
|
}
|
|
}
|