2021-11-25 16:19:13 -03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\Dia;
|
|
|
|
use App\Models\Evento;
|
|
|
|
use App\Models\HoraFlag;
|
|
|
|
use App\Models\Utils;
|
2021-12-18 10:33:28 -03:00
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2021-11-25 16:19:13 -03:00
|
|
|
use Illuminate\Http\Request;
|
2021-12-18 10:33:28 -03:00
|
|
|
use Illuminate\Http\Response;
|
2021-11-25 16:19:13 -03:00
|
|
|
|
|
|
|
class EventoController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @return Response
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @return Response
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @param Request $request
|
|
|
|
* @return RedirectResponse
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$request->validate([
|
2021-12-18 10:33:28 -03:00
|
|
|
'nombre' => 'required'
|
2021-11-25 16:19:13 -03:00
|
|
|
]);
|
|
|
|
$evento = new Evento();
|
|
|
|
$evento->nombre = $request->input("nombre");
|
2021-12-28 18:07:01 -03:00
|
|
|
$evento->setSlug();
|
2021-11-25 16:19:13 -03:00
|
|
|
$evento->save();
|
|
|
|
return redirect()->route("edit", ['evento' => $evento]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @param Evento $evento
|
|
|
|
* @return Application|Factory|View|Response
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
|
|
|
public function show(Evento $evento)
|
|
|
|
{
|
|
|
|
// evento->coordinar devuelve los tres mejores marzullos de los días que tiene asociados
|
|
|
|
// dia->marzullo devuelve array de
|
|
|
|
// [dia::string, cantidad::integer, inicio::integer, fin::integer, duracion::integer
|
|
|
|
// inicioLindo::string, finLindo::string, duracionLinda::string]
|
|
|
|
$marzullos = $evento->coordinar();
|
|
|
|
return view("resultado", ['marzullos' => $marzullos, 'evento' => $evento]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @param Evento $evento
|
|
|
|
* @return Application|Factory|View|Response
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
2021-12-02 12:10:13 -03:00
|
|
|
public function edit(Evento $evento) {
|
2021-11-25 16:19:13 -03:00
|
|
|
return view("edit", ['evento' => $evento]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @param Request $request
|
|
|
|
* @param Evento $evento
|
|
|
|
* @return RedirectResponse
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
|
|
|
public function update(Request $request, Evento $evento) {
|
|
|
|
|
|
|
|
// Validación.
|
|
|
|
request()->validate([
|
|
|
|
'dia' => 'array',
|
|
|
|
'dia.*' => 'required|string|max:100',
|
|
|
|
'salida' => 'array',
|
|
|
|
'llegada.*' => 'required|date_format:H:i',
|
|
|
|
'llegada' => 'array',
|
|
|
|
'salida.*' => 'required|date_format:H:i|after:llegada.*'
|
|
|
|
],[
|
|
|
|
'salida.*.after' => 'La hora de llegada debe ser anterior a la de salida.'
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Adición de días y horas.
|
|
|
|
foreach ($request->input('dia') as $i => $dia) {
|
|
|
|
|
|
|
|
// Busqueda en la lista de días del evento, y adición en su defecto.
|
|
|
|
$diaNombre = strtolower(trim($dia)); // ¿HACER FUNCIÓN PARA NORMALIZAR NOMBRES?
|
|
|
|
$arrayAux = $evento->dias()->where('nombre',$diaNombre)->get();
|
|
|
|
$diaID = null;
|
|
|
|
if ($arrayAux->count() == 0) {
|
|
|
|
$nuevo = new Dia(['nombre' => $diaNombre]);
|
|
|
|
$nuevo->evento_id = $evento->id;
|
|
|
|
$nuevo->save();
|
|
|
|
$diaID = $nuevo->id;
|
|
|
|
} else {
|
|
|
|
$diaID = $arrayAux[0]->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creación de hora_flags ingresados para cada día.
|
|
|
|
$llegadaDia = new HoraFlag([
|
|
|
|
'dia_id' => $diaID,
|
|
|
|
'minutoDelDia' => Utils::formatMinutos($request->input('llegada')[$i]),
|
|
|
|
'flag' => 1
|
|
|
|
]);
|
|
|
|
$salidaDia = new HoraFlag([
|
|
|
|
'dia_id' => $diaID,
|
|
|
|
'minutoDelDia' => Utils::formatMinutos($request->input('salida')[$i]),
|
|
|
|
'flag' => -1
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Adición de hora_flags ingresados para cada día.
|
|
|
|
$llegadaDia->save();
|
|
|
|
$salidaDia->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route("show", ['evento' => $evento]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2021-12-18 10:33:28 -03:00
|
|
|
* @param Evento $evento
|
|
|
|
* @return Response
|
2021-11-25 16:19:13 -03:00
|
|
|
*/
|
|
|
|
public function destroy(Evento $evento)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2021-12-09 17:10:56 -03:00
|
|
|
public function mostrarResultado(Request $request)
|
2021-11-25 16:19:13 -03:00
|
|
|
{
|
2021-12-28 18:35:21 -03:00
|
|
|
return redirect()->route('show',['evento' => Evento::find($request->id)]);
|
2021-11-25 16:19:13 -03:00
|
|
|
}
|
|
|
|
}
|