export calendar - modifica impostazioni
This commit is contained in:
@@ -6,7 +6,9 @@ use App\Models\Evento;
|
||||
use App\Models\Gruppo;
|
||||
use App\Models\Individuo;
|
||||
use App\Models\TipologiaEvento;
|
||||
use App\Services\IcsExportService;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class EventoController extends Controller
|
||||
{
|
||||
@@ -219,6 +221,55 @@ class EventoController extends Controller
|
||||
return redirect('/eventi')->with('success', count($eventi) . ' eventi eliminati con successo.');
|
||||
}
|
||||
|
||||
public function exportIcs(int $id, IcsExportService $ics): StreamedResponse
|
||||
{
|
||||
$this->authorizeRead('eventi');
|
||||
$evento = Evento::findOrFail($id);
|
||||
$content = $ics->generateSingle($evento);
|
||||
|
||||
return response()->streamDownload(function () use ($content) {
|
||||
echo $content;
|
||||
}, $ics->getFilename($evento), [
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
'Content-Length' => strlen($content),
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportSelectedIcs(Request $request, IcsExportService $ics): StreamedResponse
|
||||
{
|
||||
$this->authorizeRead('eventi');
|
||||
|
||||
$ids = $request->input('ids', []);
|
||||
if (!empty($ids) && is_array($ids)) {
|
||||
$eventi = Evento::whereIn('id', $ids)->get();
|
||||
} else {
|
||||
$query = Evento::query();
|
||||
if ($request->filled('search')) {
|
||||
$query->where('nome_evento', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
if ($request->filled('gruppo_id')) {
|
||||
$query->whereHas('gruppi', fn($q) => $q->where('gruppi.id', $request->gruppo_id));
|
||||
}
|
||||
if ($request->filled('tipo')) {
|
||||
$query->where('tipo_recorrenza', $request->tipo);
|
||||
}
|
||||
$eventi = $query->get();
|
||||
}
|
||||
|
||||
if ($eventi->isEmpty()) {
|
||||
return redirect('/eventi')->with('error', 'Nessun evento da esportare.');
|
||||
}
|
||||
|
||||
$content = $ics->generateCollection($eventi);
|
||||
|
||||
return response()->streamDownload(function () use ($content) {
|
||||
echo $content;
|
||||
}, $ics->getCollectionFilename(), [
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
'Content-Length' => strlen($content),
|
||||
]);
|
||||
}
|
||||
|
||||
public function calendar()
|
||||
{
|
||||
$this->authorizeRead('eventi');
|
||||
|
||||
Reference in New Issue
Block a user