public function getShow()
    {
        $user = User::fromToken();
        $votaciones = VtVotacion::actualesInscrito($user, false);
        // Traer aunque no esté en acción.
        // Votaciones creadas por el usuario.
        $consulta = 'SELECT v.id as votacion_id, v.*
					FROM vt_votaciones v
					where v.user_id=? and v.year_id=? and v.deleted_at is null';
        $votacionesMias = DB::select($consulta, [$user->user_id, $user->year_id]);
        foreach ($votacionesMias as $key => $votMia) {
            // Debo crear otro array para verificar que ya no tenga el mismo evento.
            array_push($votaciones, $votMia);
        }
        $cantVot = count($votaciones);
        for ($j = 0; $j < $cantVot; $j++) {
            if ($votaciones[$j]->can_see_results) {
                $aspiraciones = VtAspiracion::where('votacion_id', $votaciones[$j]->votacion_id)->get();
                $result = array();
                foreach ($aspiraciones as $aspira) {
                    $candidatos = VtCandidato::porAspiracion($aspira->id, $user->year_id);
                    for ($i = 0; $i < count($candidatos); $i++) {
                        $votos = VtVoto::deCandidato($candidatos[$i]->candidato_id, $aspira->id)[0];
                        $candidatos[$i]->cantidad = $votos->cantidad;
                        $candidatos[$i]->total = $votos->total;
                    }
                    $aspira->candidatos = $candidatos;
                    array_push($result, $aspira);
                }
                $votaciones[$j]->aspiraciones = $result;
            }
        }
        return $votaciones;
    }
Exemple #2
0
    public static function verificarNoVoto($aspira_id, $participante_id)
    {
        $consulta = 'SELECT vv.id, vv.participante_id, vv.locked, vv.candidato_id
			from vt_votos vv
			inner join vt_candidatos vc on vc.id=vv.candidato_id 
				and vc.aspiracion_id=:aspiracion_id and vv.participante_id=:participante_id';
        $datos = array(':aspiracion_id' => $aspira_id, ':participante_id' => $participante_id);
        $votos = DB::select(DB::raw($consulta), $datos);
        foreach ($votos as $voto) {
            $voto = VtVoto::destroy($voto->id);
        }
    }
 public function getIndex()
 {
     $user = User::fromToken();
     $votacion = VtVotacion::where('in_action', '=', true)->first();
     $hayVotacion = false;
     $signed = false;
     $voted = false;
     $rutear = false;
     if ($votacion) {
         $hayVotacion = true;
         $signed = VtParticipante::isSigned($user->user_id, $votacion->id);
         if ($signed) {
             $voted = VtVoto::hasVoted($votacion->id, $signed->id);
             $rutear = true;
         }
         $eventos = array('votaciones' => array('hay' => $hayVotacion, 'signed' => $signed, 'voted' => $voted, 'rutear' => $rutear, 'state' => 'votaciones.votar'));
         return $eventos;
     } else {
         $eventos = array('votaciones' => array('hay' => false, 'signed' => false, 'voted' => false, 'rutear' => false, 'state' => ''));
         return $eventos;
     }
 }
 public function getEnAccionInscrito()
 {
     $user = User::fromToken();
     $votaciones = VtVotacion::actualesInscrito($user, true);
     $cantVot = count($votaciones);
     if ($cantVot > 0) {
         for ($i = 0; $i < $cantVot; $i++) {
             $completos = VtVotacion::verificarVotosCompletos($votaciones[$i]->votacion_id, $votaciones[$i]->participante_id);
             $votaciones[$i]->completos = $completos;
             $aspiraciones = VtAspiracion::where('votacion_id', $votaciones[$i]->votacion_id)->get();
             $cantAsp = count($aspiraciones);
             if ($cantAsp > 0) {
                 for ($j = 0; $j < $cantAsp; $j++) {
                     $candidatos = VtCandidato::porAspiracion($aspiraciones[$j]->id, $votaciones[$i]->year_id);
                     for ($k = 0; $k < count($candidatos); $k++) {
                         $votos = VtVoto::deCandidato($candidatos[$k]->candidato_id, $aspiraciones[$j]->id)[0];
                         $candidatos[$k]->cantidad = $votos->cantidad;
                         $candidatos[$k]->total = $votos->total;
                     }
                     $aspiraciones[$j]->candidatos = $candidatos;
                 }
                 $votaciones[$i]->aspiraciones = $aspiraciones;
             } else {
                 $votaciones[$i]->aspiraciones = [];
             }
         }
     } else {
         return ['msg' => 'No está inscrito en algún evento que se encuentre en acción.'];
     }
     return $votaciones;
 }