-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(calendar): Calendar export ical file event
- Loading branch information
Showing
12 changed files
with
404 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/Http/Controllers/Calendar/CalendarExportController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Calendar; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Calendar as CalendarModel; | ||
use DateTime; | ||
use Spatie\IcalendarGenerator\Components\Calendar; | ||
use Spatie\IcalendarGenerator\Components\Event; | ||
|
||
class CalendarExportController extends Controller | ||
{ | ||
public function exportICal(int $id): \Symfony\Component\HttpFoundation\BinaryFileResponse | ||
{ | ||
// Buscar el evento de calendario por su ID | ||
$calendarEvent = CalendarModel::find($id); | ||
|
||
// Verificar si el evento existe | ||
if (! $calendarEvent) { | ||
abort(404, 'Evento de calendario no encontrado.'); | ||
} | ||
|
||
// Crear el objeto Calendar | ||
$calendar = Calendar::create($calendarEvent->title); | ||
|
||
// Crear el objeto Event con los detalles del evento de calendario | ||
$event = Event::create($calendarEvent->title) | ||
->startsAt(new DateTime($calendarEvent->start_date)) | ||
->endsAt(new DateTime($calendarEvent->end_date)) | ||
->description((string) $calendarEvent->description); // Puedes agregar más propiedades según necesites | ||
|
||
// Agregar el organizador si existe el user_id | ||
if ($calendarEvent->user_id) { | ||
// Obtener información del organizador según el user_id | ||
$organizerEmail = $calendarEvent->organizer->email; | ||
$organizerName = $calendarEvent->organizer->getFullName(); | ||
|
||
$event->organizer($organizerEmail, $organizerName); | ||
} | ||
|
||
// Agregar el evento al calendario | ||
$calendar->event($event); | ||
|
||
// Generar el archivo iCalendar y obtener su contenido | ||
$iCalContent = $calendar->get(); | ||
|
||
// Guardar el contenido en un archivo temporal | ||
$tempFilePath = tempnam(sys_get_temp_dir(), 'calendar'); | ||
file_put_contents($tempFilePath, $iCalContent); | ||
|
||
// Descargar el archivo iCalendar | ||
return response() | ||
->download($tempFilePath, $calendarEvent->title.'.ics') | ||
->deleteFileAfterSend(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/Http/Controllers/Calendar/CalendarUpdateEventController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Calendar; | ||
|
||
use App\Http\Controllers\MainController; | ||
use App\Models\Calendar; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
|
||
class CalendarUpdateEventController extends MainController | ||
{ | ||
public function update(Request $request, int $id): JsonResponse | ||
{ | ||
$calendar = Calendar::find($id); | ||
|
||
return response()->json(['calendar' => $calendar]); | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
app/Http/Controllers/Calendar/UpdateCalendarEventController.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.