Handling ICAL import

This commit is contained in:
2026-04-25 16:50:32 +02:00
parent 6f8be58943
commit 1ee6b9968f
22 changed files with 510 additions and 19 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Domains\Event\Actions\GenerateIcal;
class GenerateIcalCommand
{
public function __construct(public GenerateIcalRequest $request)
{
}
public function execute(): GenerateIcalResponse
{
$participant = $this->request->participant;
$event = $participant->event;
$uid = $participant->identifier . '@' . app('tenant')->slug;
$dtStart = $event->start_date->format('Ymd');
$dtEnd = $event->end_date->copy()->addDay()->format('Ymd');
$now = now()->format('Ymd\THis\Z');
$summary = $this->escapeIcal($event->name);
$location = $this->escapeIcal(trim($event->postal_code . ' ' . $event->location));
$description = $this->escapeIcal('Teilnahme als: ' . $participant->getOfficialName());
$icalContent = implode("\r\n", [
'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:-//' . app('tenant')->name . '//Veranstaltungskalender//DE',
'CALSCALE:GREGORIAN',
'METHOD:PUBLISH',
'BEGIN:VEVENT',
'UID:' . $uid,
'DTSTAMP:' . $now,
'DTSTART;VALUE=DATE:' . $dtStart,
'DTEND;VALUE=DATE:' . $dtEnd,
'SUMMARY:' . $summary,
'LOCATION:' . $location,
'DESCRIPTION:' . $description,
'END:VEVENT',
'END:VCALENDAR',
]) . "\r\n";
$filename = 'veranstaltung-' . $participant->event()->first()->name . '.ics';
return new GenerateIcalResponse($icalContent, $filename);
}
private function escapeIcal(string $value): string
{
return str_replace(
['\\', ';', ',', "\n"],
['\\\\', '\\;', '\\,', '\\n'],
$value
);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Domains\Event\Actions\GenerateIcal;
use App\Models\EventParticipant;
class GenerateIcalRequest
{
public function __construct(public EventParticipant $participant)
{
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Domains\Event\Actions\GenerateIcal;
class GenerateIcalResponse
{
public function __construct(
public string $icalContent,
public string $filename,
) {
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Domains\Event\Actions\GenerateIcalForDeadline;
class GenerateIcalForDeadlineCommand {
public function __construct(public GenerateIcalForDeadlineRequest $request)
{
}
public function execute(): GenerateIcalForDeadlineResponse
{
$event = $this->request->event;
$deadlineDate = $event->registration_final_end->copy()->subDays(2);
$dtDate = $deadlineDate->format('Ymd');
$now = now()->format('Ymd\THis\Z');
$summary = $this->escapeIcal('Zahlungsfrist: ' . $event->name);
$description = $this->escapeIcal(
'Bitte überweise den Teilnahmebeitrag für "' . $event->name . '" bis zu diesem Datum.'
);
$icalContent = implode("\r\n", [
'BEGIN:VCALENDAR',
'VERSION:2.0',
'PRODID:-//' . app('tenant')->name . '//Veranstaltungskalender//DE',
'CALSCALE:GREGORIAN',
'METHOD:PUBLISH',
'BEGIN:VEVENT',
'UID:payment-deadline-' . $event->identifier . '@' . app('tenant')->slug,
'DTSTAMP:' . $now,
'DTSTART;VALUE=DATE:' . $dtDate,
'DTEND;VALUE=DATE:' . $dtDate,
'SUMMARY:' . $summary,
'DESCRIPTION:' . $description,
'END:VEVENT',
'END:VCALENDAR',
]) . "\r\n";
$filename = 'zahlungsziel-' . $event->name . '.ics';
return new GenerateIcalForDeadlineResponse($icalContent, $filename);
}
private function escapeIcal(string $value): string
{
return str_replace(
['\\', ';', ',', "\n"],
['\\\\', '\\;', '\\,', '\\n'],
$value
);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Domains\Event\Actions\GenerateIcalForDeadline;
use App\Models\Event;
class GenerateIcalForDeadlineRequest {
public function __construct(public Event $event) {
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Domains\Event\Actions\GenerateIcalForDeadline;
class GenerateIcalForDeadlineResponse
{
public function __construct(
public string $icalContent,
public string $filename,
) {
}
}