kithkin/app/Http/Controllers/CalendarSettingsController.php

64 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Controllers;
use App\Models\Subscription;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class CalendarSettingsController extends Controller
{
/* landing page list of settings choices */
public function index()
{
return $this->frame('calendar.settings.subscribe');
}
/* show “Subscribe to a calendar” form */
public function subscribeForm()
{
return $this->frame(
'calendar.settings.subscribe',
[
'title' => 'Subscribe to a calendar',
'sub' => 'Add an `.ics` calender from another service'
]);
}
/* handle POST from the subscribe form */
public function subscribeStore(Request $request)
{
$data = $request->validate([
'source' => ['required', 'url'],
'displayname' => ['nullable', 'string', 'max:100'],
'color' => ['nullable', 'regex:/^#[0-9A-F]{6}$/i'],
]);
// create the calendarsubscription and calendar_meta rows in one call via Subscription model
Subscription::createWithMeta(
$request->user(),
[
'source' => $data['source'],
'displayname' => $data['displayname'] ?: $data['source'],
'calendarcolor' => $data['color'] ?? '#1a1a1a',
// you can add 'refreshrate' => 'P1D' here if you like
]
);
return redirect()
->route('calendar.index')
->with('toast', __('Subscription added successfully!'));
}
/**
* content frame handler
*/
private function frame(?string $view = null, array $data = [])
{
return view('calendar.settings.index', [
'view' => $view,
'data' => $data,
]);
}
}