34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Monitor\Framework\Controller;
|
|
|
|
use Aimeos\Map;
|
|
use App\Monitor\Framework\Repository\MonitorRepository;
|
|
use Spatie\IcalendarGenerator\Components\Calendar;
|
|
use Spatie\IcalendarGenerator\Components\Event;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
class CalendarController extends AbstractController
|
|
{
|
|
#[Route('/monitors/ical.ics', name: 'app.monitors.ical')]
|
|
public function icalAction(MonitorRepository $monitorRepository)
|
|
{
|
|
$calendar = new Calendar();
|
|
$monitors = $monitorRepository->whereAirDateNotNull();
|
|
$events = Map::from($monitors)->map(function ($monitor) {
|
|
return new Event($monitor->getTitle())
|
|
->startsAt($monitor->getAirDate())
|
|
->withoutTimezone()
|
|
->fullDay()
|
|
;
|
|
});
|
|
$calendar->event($events->toArray());
|
|
return new Response($calendar->get(), 200, [
|
|
'Content-Type' => 'text/calendar',
|
|
'Content-Disposition' => 'attachment; filename="upcoming-episodes.ics"',
|
|
]);
|
|
}
|
|
}
|