public function postInscribirProfesores()
 {
     $user = User::fromToken();
     $votacion = VtVotacion::actual($user);
     $profesores = Profesor::fromyear($user->year_id);
     $participantes = [];
     for ($i = 0; $i < count($profesores); $i++) {
         $partic = VtParticipante::where('user_id', $profesores[$i]->user_id)->where('votacion_id', $votacion->id)->first();
         if (!$partic) {
             if (!$profesores[$i]->user_id) {
                 $dirtyName = $profesores[$i]->nombres;
                 $name = preg_replace('/\\s+/', '', $dirtyName);
                 $usuario = new User();
                 $usuario->username = $name;
                 $usuario->password = '******';
                 $usuario->is_superuser = false;
                 $usuario->is_active = true;
                 $usuario->save();
                 $profe = Profesor::find($profesores[$i]->id);
                 $profe->user_id = $usuario->id;
                 $profe->save();
                 $profesores[$i]->user_id = $profe->user_id;
             }
             $partic_trash = VtParticipante::onlyTrashed()->where('user_id', $profesores[$i]->user_id)->where('votacion_id', $votacion->id)->first();
             if ($partic_trash) {
                 $participante = $partic_trash;
                 $participante->restore();
             } else {
                 $participante = new VtParticipante();
                 $participante->user_id = $profesores[$i]->user_id;
                 $participante->votacion_id = $votacion->id;
                 $participante->locked = false;
                 $participante->intentos = 0;
                 $participante->save();
             }
             array_push($participantes, $participante);
         }
     }
     return $participantes;
 }
예제 #2
0
 public function getConyears()
 {
     $user = User::fromToken();
     $profesores = Profesor::fromyear($user->year_id);
     foreach ($profesores as $profesor) {
         $profesor->years = Year::de_un_profesor($profesor->id);
     }
     return $profesores;
 }