From b587302b30a61cda59c9fcc18132162d240e3cda Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Tue, 26 Aug 2025 22:24:23 -0500 Subject: [PATCH] wip: ical calendar export --- .../icons/lets-icons/calendar-add-light.svg | 1 + composer.json | 1 + composer.lock | 61 ++++++++++++++++++- .../Controller/CalendarController.php | 33 ++++++++++ templates/monitor/upcoming-episodes.html.twig | 3 + 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 assets/icons/lets-icons/calendar-add-light.svg create mode 100644 src/Monitor/Framework/Controller/CalendarController.php diff --git a/assets/icons/lets-icons/calendar-add-light.svg b/assets/icons/lets-icons/calendar-add-light.svg new file mode 100644 index 0000000..9b7cda0 --- /dev/null +++ b/assets/icons/lets-icons/calendar-add-light.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/composer.json b/composer.json index 4d80427..2c22e78 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "php-tmdb/api": "^4.1", "predis/predis": "^2.4", "runtime/frankenphp-symfony": "^0.2.0", + "spatie/icalendar-generator": "^3.0", "spomky-labs/pwa-bundle": "^1.2", "stof/doctrine-extensions-bundle": "^1.14", "symfony/asset": "7.3.*", diff --git a/composer.lock b/composer.lock index e03a5c0..68f5b07 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6f57ba35ae317ec6370836bda0012db8", + "content-hash": "9ffd10f98137e8975de2c04ac2412ed5", "packages": [ { "name": "1tomany/rich-bundle", @@ -4757,6 +4757,65 @@ ], "time": "2023-12-12T12:06:11+00:00" }, + { + "name": "spatie/icalendar-generator", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/icalendar-generator.git", + "reference": "32797f6e5afa3142d073f38d5f22ab377f4d8f90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/icalendar-generator/zipball/32797f6e5afa3142d073f38d5f22ab377f4d8f90", + "reference": "32797f6e5afa3142d073f38d5f22ab377f4d8f90", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^8.1" + }, + "require-dev": { + "ext-json": "*", + "larapack/dd": "^1.1", + "nesbot/carbon": "^3.5", + "pestphp/pest": "^2.34", + "phpstan/phpstan": "^2.0", + "spatie/pest-plugin-snapshots": "^2.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\IcalendarGenerator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ruben Van Assche", + "email": "ruben@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Build calendars in the iCalendar format", + "homepage": "https://github.com/spatie/icalendar-generator", + "keywords": [ + "calendar", + "iCalendar", + "ical", + "ics", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/icalendar-generator/issues", + "source": "https://github.com/spatie/icalendar-generator/tree/3.0.0" + }, + "time": "2025-04-17T14:50:03+00:00" + }, { "name": "spomky-labs/pki-framework", "version": "1.3.0", diff --git a/src/Monitor/Framework/Controller/CalendarController.php b/src/Monitor/Framework/Controller/CalendarController.php new file mode 100644 index 0000000..20e9626 --- /dev/null +++ b/src/Monitor/Framework/Controller/CalendarController.php @@ -0,0 +1,33 @@ +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"', + ]); + } +} diff --git a/templates/monitor/upcoming-episodes.html.twig b/templates/monitor/upcoming-episodes.html.twig index 0233633..a59e5f4 100644 --- a/templates/monitor/upcoming-episodes.html.twig +++ b/templates/monitor/upcoming-episodes.html.twig @@ -16,6 +16,9 @@
+ + +