mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions. You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root. For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Meetup;
|
|
use App\Models\MeetupEvent;
|
|
use Illuminate\Http\Request;
|
|
use Spatie\IcalendarGenerator\Components\Calendar;
|
|
use Spatie\IcalendarGenerator\Components\Event;
|
|
|
|
class DownloadMeetupCalendar extends Controller
|
|
{
|
|
/**
|
|
* Handle the incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function __invoke(Request $request)
|
|
{
|
|
if ($request->has('meetup')) {
|
|
$meetup = Meetup::query()
|
|
->with([
|
|
'meetupEvents',
|
|
])
|
|
->findOrFail($request->input('meetup'));
|
|
$events = $meetup->meetupEvents;
|
|
$image = $meetup->getFirstMediaUrl('logo');
|
|
} else {
|
|
$events = MeetupEvent::query()
|
|
->with([
|
|
'meetup',
|
|
])
|
|
->get();
|
|
$image = asset('img/einundzwanzig-horizontal.png');
|
|
}
|
|
|
|
$entries = [];
|
|
foreach ($events as $event) {
|
|
$entries[] = Event::create($event->meetup->name)
|
|
->uniqueIdentifier(str($event->meetup->name)->slug().$event->id)
|
|
->address($event->location ?? __('no location set'))
|
|
->description(str_replace(["\r", "\n"], '', $event->description).' Link: '.$event->link)
|
|
->image($image)
|
|
->startsAt($event->start);
|
|
}
|
|
|
|
$calendar = Calendar::create()
|
|
->refreshInterval(5)
|
|
->event($entries);
|
|
|
|
return response($calendar->get())
|
|
->header('Content-Type', 'text/calendar; charset=utf-8');
|
|
}
|
|
}
|