| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class EventosController extends Controller
- {
- public function eventosActivos()
- {
- $evento = DB::table('calendario_eventos_colegioabc')
- ->where('idEscuela', 'COLEGIOABC')
- // ->where('estatus', 'Activo')
- ->get();
- return response()->json($evento, 200);
- }
- public function crear(Request $request)
- {
- try {
- DB::table('calendario_eventos_colegioabc')->insert([
- 'idEscuela' => 'COLEGIOABC',
- 'idUsuario' => 'PR011',
- 'estatus' => 'Activo',
- 'titulo' => $request->titulo,
- 'fechaInicio' => $request->fechaInicio,
- 'fechaFin' => $request->fechaFin,
- // var_dump($request->todoDia),
- 'diaCompleto' => $request->todoDia === true ? 'Si' : 'No',
- 'colorEvento' => $request->categoria,
- 'colorTexto' => '#FFFFFF',
- 'descripcion' => $request->contenido,
- 'visualizarListaInvitados' => 'No',
- 'mostrarConfirmacion' => 'No',
- 'solicitarConfirmacionAsistencia' => 'No',
- 'jsonInvitados' => '{}',
- 'numeroAdjuntos' => '0',
- 'jsonAdjuntos' => '{}',
- 'videollamada' => 'No',
- 'tipoGrabacion' => 'No_Grabar',
- 'tipoChat' => 'Publico_Moderador',
- 'idUsuarioCc' => 'PR011',
- ]);
- return response()->json([
- 'mensaje' => 'Evento creado exitosamente',
- 'idEvento' => DB::getPdo()->lastInsertId()
- ], 201);
- } catch (\Exception $e) {
- return response()->json(['mensaje' => 'Error al actualizar el evento: ' . $e->getMessage()], 500);
- }
- }
- public function savecalendarioUsuarios(Request $request)
- {
- try {
- DB::table('calendario_usuarios_colegioabc')->insert([
- 'idEscuela' => 'COLEGIOABC',
- 'idEvento' => $request->idEvento,
- 'idUsuario' => $request->idUsuario,
- 'tipo' => 'Invitado',
- 'estatus' => 'Activo',
- 'asistencia' => 'Sin Confirmación',
- 'idUsuarioCc' => 'PR011',
- ]);
- return response()->json([
- 'mensaje' => 'Evento asignado exitosamente',
- ], 201);
- } catch (\Exception $e) {
- return response()->json(['mensaje' => 'Error al actualizar el evento: ' . $e->getMessage()], 500);
- }
- }
- public function getWeekEvents()
- {
- // Obtener fechas de la semana actual (lunes a viernes)
- $now = Carbon::now();
- $monday = $now->startOfWeek(Carbon::MONDAY);
- $weekDays = [
- 'Lunes' => $monday->copy()->format('Y-m-d'),
- 'Martes' => $monday->copy()->addDay()->format('Y-m-d'),
- 'Miércoles' => $monday->copy()->addDays(2)->format('Y-m-d'),
- 'Jueves' => $monday->copy()->addDays(3)->format('Y-m-d'),
- 'Viernes' => $monday->copy()->addDays(4)->format('Y-m-d'),
- ];
- $result = [];
- foreach ($weekDays as $dayName => $date) {
- $events = DB::table('calendario_eventos_colegioabc')
- ->where('idEscuela', 'COLEGIOABC')
- ->where('estatus', 'Activo')
- ->whereDate('fechaInicio', '<=', $date)
- ->whereDate('fechaFin', '>=', $date)
- ->get();
- $eventCount = $events->count();
- $eventDescription = $this->getEventDescription($eventCount);
- // Si hay solo un evento, obtener el título
- if ($eventCount === 1) {
- $eventDescription = $events->first()->titulo;
- }
- $result[] = [
- 'day' => $dayName,
- 'event' => $eventDescription,
- 'num' => Carbon::parse($date)->day,
- 'completeDate' => $date
- ];
- }
- return $result;
- }
- protected function getEventDescription($count)
- {
- if ($count === 0) {
- return 'Sin Evento';
- } elseif ($count === 1) {
- return '1 evento';
- } else {
- return "+ de 1 evento";
- }
- }
- }
|