public function submit_create_evento()
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         $data["permisos"] = Session::get('permisos');
         if (in_array('side_nuevo_evento', $data["permisos"])) {
             // Validate the info, create rules for the inputs
             $attributes = array('nombre' => 'Título del Evento', 'fecha_evento' => 'Fecha del Evento', 'idcolegios' => 'Colegio', 'direccion' => 'Dirección Exacta', 'voluntarios' => 'Voluntarios', 'latitud' => 'Punto en el Mapa');
             $messages = array();
             $rules = array('nombre' => 'required|alpha_spaces|min:2|max:100', 'fecha_evento' => 'required', 'idcolegios' => 'required', 'direccion' => 'required|max:100', 'voluntarios' => 'required', 'latitud' => 'required');
             // Run the validation rules on the inputs from the form
             $validator = Validator::make(Input::all(), $rules, $messages, $attributes);
             // If the validator fails, redirect back to the form
             if ($validator->fails()) {
                 return Redirect::to('eventos/create_evento')->withErrors($validator)->withInput(Input::all());
             } else {
                 /* Primero creo el evento */
                 $evento = new Evento();
                 $evento->nombre = Input::get('nombre');
                 $evento->fecha_evento = date('Y-m-d H:i:s', strtotime(Input::get('fecha_evento')));
                 //$evento->idtipo_eventos = Input::get('idtipo_eventos');
                 $evento->direccion = Input::get('direccion');
                 $evento->latitud = Input::get('latitud');
                 $evento->longitud = Input::get('longitud');
                 $evento->idperiodos = Input::get('idperiodos');
                 $evento->save();
                 /* Creo los puntos de reunion */
                 if (!empty(Input::get('puntos_reunion'))) {
                     foreach (Input::get('puntos_reunion') as $punto_reunion) {
                         $punto_reunion_evento = new PuntoEvento();
                         $punto_reunion_evento->idpuntos_reunion = $punto_reunion;
                         $punto_reunion_evento->ideventos = $evento->ideventos;
                         $punto_reunion_evento->save();
                     }
                 }
                 /* Creo las asistencias de los usuarios */
                 foreach (Input::get('voluntarios') as $voluntario) {
                     $asistencia = new Asistencia();
                     $asistencia->asistio = 0;
                     $asistencia->idusers = $voluntario;
                     $asistencia->ideventos = $evento->ideventos;
                     $asistencia->save();
                 }
                 /* Creo las asistencias de los niños */
                 $ninhos = Ninho::getNinhosPorColegio(Input::get('idcolegios'))->get();
                 foreach ($ninhos as $ninho) {
                     $asistencia_ninho = new AsistenciaNinho();
                     $asistencia_ninho->idninhos = $ninho->idninhos;
                     $asistencia_ninho->ideventos = $evento->ideventos;
                     $asistencia_ninho->save();
                 }
                 /* Envio las notificaciones via e-mail a los voluntarios */
                 $emails_voluntarios = Asistencia::getUsersPorEvento($evento->ideventos)->get();
                 $emails = array();
                 foreach ($emails_voluntarios as $email_voluntario) {
                     $emails[] = $email_voluntario->email;
                 }
                 Mail::send('emails.eventRegistration', array('evento' => $evento), function ($message) use($emails, $evento) {
                     $message->to($emails)->subject('Tienes un nuevo evento de AFI Perú.');
                 });
                 // Llamo a la función para registrar el log de auditoria
                 $descripcion_log = "Se creó el evento con id {{$evento->ideventos}}";
                 Helpers::registrarLog(3, $descripcion_log);
                 Session::flash('message', 'Se registró correctamente el evento.');
                 return Redirect::to('eventos/create_evento');
             }
         } else {
             // Llamo a la función para registrar el log de auditoria
             $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
             Helpers::registrarLog(10, $descripcion_log);
             Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.');
             return Redirect::to('/dashboard');
         }
     } else {
         return View::make('error/error');
     }
 }
Ejemplo n.º 2
0
 public function submit_enable_ninho()
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         $data["permisos"] = Session::get('permisos');
         if (in_array('side_nuevo_ninho', $data["permisos"])) {
             $ninho_id = Input::get('ninho_id');
             $url = "ninhos/edit_ninho/" . $ninho_id;
             $ninho = Ninho::withTrashed()->find($ninho_id);
             $ninho->restore();
             $descripcion_log = "Se habilitó el niño con id {{$ninho_id}}";
             Helpers::registrarLog(6, $descripcion_log);
             Session::flash('message', 'Se habilitó correctamente al niño.');
             return Redirect::to($url);
         } else {
             $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'";
             Helpers::registrarLog(10, $descripcion_log);
             return View::make('error/error');
         }
     } else {
         return View::make('error/error');
     }
 }
Ejemplo n.º 3
0
 public function show($id)
 {
     $n = \Ninho::find($id);
     if (!$n) {
         return Response::json(['error' => 'No existe niño con id = ' . $id], 200);
     }
     // genero
     $genero = null;
     if ($n->genero == 'm' || $n->genero == 'M') {
         $genero = 0;
     } elseif ($n->genero == 'f' || $n->genero == 'F') {
         $genero = 1;
     }
     // edad
     $from = new \DateTime($n->fecha_nacimiento);
     $to = new \DateTime('today');
     $edad = $from->diff($to)->y;
     // obtener todos los comentarios hechos al niño en todas las sesiones
     $lista_comentarios = [];
     $asistencias = \AsistenciaNinho::where('idninhos', '=', $n->idninhos)->get();
     foreach ($asistencias as $a) {
         $comentarios = \Comentario::where('idasistencia_ninhos', '=', $a->idasistencia_ninhos)->get();
         foreach ($comentarios as $c) {
             $autor = \User::searchUserById($c->idusers)->first();
             $perfiles = \User::getPerfilesPorUsuario2($autor->id)->get();
             $perfiles_array = [];
             foreach ($perfiles as $perfil) {
                 $perfiles_array[] = ['id' => $perfil->idperfiles, 'name' => $perfil->nombre];
             }
             $lista_comentarios[] = ['id' => $c->idcomentarios, 'session_id' => $a->ideventos, 'message' => $c->comentario, 'face' => (int) $c->calificacion, 'author' => ['id' => $autor->id, 'names' => $autor->nombres, 'last_name' => $autor->apellido_pat, 'username' => $autor->num_documento, 'profiles' => $perfiles_array]];
         }
     }
     $response = ['id' => $n->idninhos, 'names' => $n->nombres, 'last_name' => $n->apellido_pat, 'gender' => $genero, 'age' => $edad, 'sessions' => $asistencias->count(), 'joining_date' => strtotime($n->created_at), 'comments' => $lista_comentarios];
     return Response::json($response, 200);
 }