Esempio n. 1
0
 public function edit()
 {
     $result = array('error' => false, 'msgSuccess' => '', 'idsDeleted' => array(), 'msgErrors' => array());
     //Controlar errores en el formulario
     $testDataForm = new Evento();
     if (!$testDataForm->validate(Input::all())) {
         $result['error'] = true;
         $result['msgErrors'] = $testDataForm->errors();
     } else {
         //si el usuario es alumno: comprobamos req2 (MAX HORAS = 12 a la semana en cualquier espacio o medio )
         if (Auth::user()->isUser() && $this->superaHoras()) {
             $result['error'] = true;
             $error = array('hFin' => 'Se supera el máximo de horas a la semana.. (12h)');
             $result['msgErrors'] = $error;
         } else {
             $idSerie = Input::get('idSerie');
             $fechaInicio = Input::get('fInicio');
             $fechaFin = Input::get('fFin');
             //Borrar todos los eventos a modificar
             $event = Evento::find(Input::get('idEvento'));
             if (Input::get('id_recurso') == 0) {
                 Evento::where('evento_id', '=', Input::get('idSerie'))->forceDelete();
             } else {
                 Evento::where('evento_id', '=', Input::get('idSerie'))->where('recurso_id', '=', Input::get('id_recurso'))->forceDelete();
             }
             //Añadir los nuevos
             $result['idEvents'] = $this->editEvents($fechaInicio, $fechaFin, $idSerie);
             //Msg confirmación al usuario (edición de evento)
             $newEvent = Evento::Where('evento_id', '=', $idSerie)->first();
             if ($newEvent->estado == 'aprobada') {
                 $result['msgSuccess'] = '<strong class="alert alert-info" > Reserva registrada con éxito. Puede <a target="_blank" href="' . route('justificante', array('idEventos' => $newEvent->evento_id)) . '">imprimir comprobante</a> de la misma si lo desea.</strong>';
             }
             if ($newEvent->estado == 'pendiente') {
                 $result['msgSuccess'] = '<strong class="alert alert-danger" >Reserva pendiente de validación. Puede <a target="_blank" href="' . route('justificante', array('idEventos' => $newEvent->evento_id)) . '">imprimir comprobante</a> de la misma si lo desea.</strong>';
             }
             //notificar a validadores si espacio requiere validación
             if ($event->recurso->validacion()) {
                 $sgrMail = new sgrMail();
                 $sgrMail->notificaEdicionEvento($newEvent);
             }
         }
         //fin else
     }
     return $result;
 }