Example #1
0
 public static function getUserVotes($userid = null)
 {
     if ($userid === null) {
         $userid = TwitterAuth::getUserId();
     }
     return ApplicationVote::find('userid = ?', [$userid]);
 }
Example #2
0
 /**
  * @param null $userid
  * @return static
  */
 public static function exists($userid = null)
 {
     if ($userid === null) {
         if (!TwitterAuth::isLogged()) {
             return null;
         } else {
             $userid = TwitterAuth::getUserId();
         }
     }
     return Application::findOne('userid = ?', [$userid]);
 }
Example #3
0
File: Match.php Project: xJakub/LCE
 function hasVoted($userid = null)
 {
     if ($userid == null) {
         $userid = TwitterAuth::getUserId();
     }
     $bet = Bet::findOne('matchid = ? and userid = ?', array($this->matchid, $userid));
     if (!$bet) {
         return false;
     } else {
         return $bet->teamid;
     }
 }
Example #4
0
    /**
     * @return void
     */
    public function show()
    {

        $resultNames = [
            ['Sin resultado', 'Sin resultado'],
        ];
        for ($i=6; $i>=0; $i--) {
            $resultNames[] = ["Victoria $i-0", "Derrota 0-$i"];
        }
        for ($i=0; $i<=6; $i++) {
            $resultNames[] = ["Derrota 0-$i", "Victoria $i-0"];
        }
        $resultNames[] = ["Victoria 6-0 (sin jugar)", "Derrota 0-6 (sin jugar)"];
        $resultNames[] = ["Derrota 0-6 (sin jugar)", "Victoria 6-0 (sin jugar)"];
        $resultNames[] = ["Aplazado", "Aplazado"];

        if (!($csrf = $_SESSION['csrf'])) {
            $_SESSION['csrf'] = $csrf = rand(1, 1000000) . "";
        }
        $postCsrf = HTMLResponse::fromPOST('csrf', '');

        if ($postCsrf == $csrf) {
            if (HTMLResponse::fromPOST('color') !== null) {
                $this->team->color = HTMLResponse::fromPOST('color');
                $this->team->save();
            }
        }
        $color = $this->team->color;

        ?>
        <div class="inblock" style="margin-right: 16px">
            <a target="_blank" href="/<?=$this->team->getImageLink()?>">
                <img src="/<?=$this->team->getImageLink(300, 200)?>" alt="Logo" class="teamlogo"><br>
            </a>
            <a href="https://twitter.com/hashtag/<?=$this->team->getHashtag()?>" target="_blank">#<?=$this->team->getHashtag()?></a>
            <div style="height:2px"></div>
            <a href="https://twitter.com/<?=$this->team->username?>" target="_blank">@<?=$this->team->username?></a>
            <div style="height: 6px"></div>

            <span style="text-decoration: underline;">Color oficial</span>: <?
            if (preg_match("'^#[abcdefABCDEF0-9]{6}$'", $color)) {
                ?><span id="teamcolor"><?= $color ?></span><?
            } else {
                ?><i id="teamcolor">Sin color</i><?
                $color = '#000000';
            }
            ?>
            <div class="teamcolor" style="background: <?=$color?>"></div>

            <br><?
            if ($this->team->isManager()) {
                ?>
                <br>Eres el Manager del equipo.

                <form action="<?=HTMLResponse::getRoute()?>" method="post" id="colorform">
                    <input type="hidden" name="color" value="<?=$color?>">
                    <input type="hidden" name="csrf" value="<?=$csrf?>">
                </form>
                <?
                $this->design->addJavaScript('/js/jquery-ui.min.js');
                $this->design->addStyleSheet('/css/jquery-ui.min.css');
                $this->design->addStyleSheet('/css/jquery.colorpicker.css');
                $this->design->addJavaScript('/js/jquery.colorpicker.js');
                $this->design->addJavaScript("
                    $('.teamcolor').colorpicker({
                    inline: false,
                    color: '{$color}',
                    colorFormat: '#HEX',
                    closeOnOutside: false,
                    closeOnEscape: false,
                    ok: function(event, color) {
                        $('#colorform input[name=\"color\"]').val(color.formatted);
                        $('#colorform').submit();
                    }
                    }).css('cursor', 'pointer');
                    ", false);
            }
            ?>
        </div>
        <div class="inblock">
            <?

            ?>
            <h2>Calendario de enfrentamientos</h2>
            <table>
                <thead>
                <tr>
                    <td>Jornada</td>
                    <td>Fecha</td>
                    <td>Oponentes</td>
                    <td>Resultado</td>
                    <td>Vídeos</td>
                </tr>
                </thead>
                <tbody>
                <? foreach(Match::find('(team1id = ? or team2id = ?) and seasonid = ? order by week asc',
                    [$this->team->teamid, $this->team->teamid, $this->season->seasonid]) as $match) {

                    if (!$this->team->isManager() && !$this->season->weekIsPublic($match->week)) {
                        continue;
                    }

                    if (HTMLResponse::fromPOST('matchid', '') === $match->matchid &&
                        strlen($newResult = HTMLResponse::fromPOST('result', ''))) {
                        $match->result = $newResult;
                        $match->save();
                        HTMLResponse::exitWithRoute(HTMLResponse::getRoute());
                    }

                    $date = $this->season->getPublishTimeForWeek($match->week);

                    if ($match->team1id == $this->team->teamid) {
                        $posIndex = 0;
                    } else {
                        $posIndex = 1;
                    }

                    $opponentsId = ($match->team1id != $this->team->teamid) ? $match->team1id : $match->team2id;
                    $opponents = Team::get($opponentsId);

                    ?>
                    <tr>
                        <td style="height:3em">
                            <?
                            echo $this->season->getWeekName($match->week);
                            ?>
                        </td>
                        <td><?= date("Y-m-d", $date) ?></td>
                        <td style="text-align: center">
                            <!--
                            <?=htmlentities($this->team->name)?>
                            VS
                            -->
                            <a href="/<?=$this->season->getLink()?>/equipos/<?=$opponents->getLink()?>/">
                                <?=htmlentities($opponents->name)?>
                            </a>
                        </td>
                        <td>
                            <i style="color: #666" <? if ($this->team->isManager()) { ?>class="editableResult"<?}?>>
                                <?= ($this->team->isManager() || $match->isPublished()) ? $resultNames[$match->result][$posIndex] : $resultNames[0][0] ?>
                            </i>

                            <form class="editResult" method="POST" action="<?=HTMLResponse::getRoute()?>">
                                <select name="result">
                                    <? foreach($resultNames as $index => $names) {
                                        ?><option <?=($index==$match->result?'selected':'')?> value="<?=$index?>"><?=$names[$posIndex]?></option><?
                                    } ?>
                                </select>
                                <input type="hidden" name="matchid" value="<?=$match->matchid?>">
                            </form>

                        </td>
                        <td>
                            <? $this->showMatchVideo($this->team, $match, 2, "Ver Team Preview") ?>
                            <? $this->showMatchVideo($this->team, $match, 1, "Ver Combate") ?>

                        </td>
                    </tr>
                <? } ?>
                </tbody>
            </table>
            <?
            $this->showFriendlyMatches();

            if ($this->team->isManager()) {
                $this->checkPlayerChanges();
            }
            $this->showPlayers();
            if ($this->team->isManager()) {
                $this->showPlayersEditor();
            }

            $sanctionLevels = Sanction::getLevelNames();

            $sanctions = Sanction::find('seasonid = ? and teamid = ? order by dateline desc',
                [$this->season->seasonid, $this->team->teamid]);

            if ($sanctions && Team::isMember()) {
                ?>
                <h2>Sanciones recibidas</h2>
                <table style="min-width: 512px">
                    <thead>
                    <tr>
                        <!-- <td>Fecha</td> -->
                        <td>Tipo</td>
                        <td>Razón</td>
                    </tr>
                    </thead>

                    <? foreach($sanctions as $sanction) { ?>
                        <tr>
                            <!-- <td style="font-style: italic">
                                <?= date("Y-m-d H:i:s", $sanction->dateline) ?>
                            </td> -->
                            <td>
                                <?= $sanctionLevels[$sanction->level] ?>
                                <? if (Team::isAdmin()) { ?>
                                    <i style="color: #666">
                                        por
                                    </i>
                                    <?= htmlentities($sanction->adminname) ?>
                                <? } ?>
                            </td>
                            <td>
                                <?= htmlentities($sanction->reason) ?>
                            </td>
                        </tr>
                    <? } ?>
                </table><br>

                <?
            }

            if (Team::isAdmin()) {

                $postCsrf = HTMLResponse::fromPOST('sanctioncsrf', '');

                if ($postCsrf == $csrf) {
                    if (strlen($reason = HTMLResponse::fromPOST('sanctionreason'))) {
                        $sanction = Sanction::create();
                        $sanction->adminid = TwitterAuth::getUserId();
                        $sanction->adminname = TwitterAuth::getUserName();
                        $sanction->dateline = time();
                        $sanction->reason = $reason;
                        $sanction->seasonid = $this->season->seasonid;
                        $sanction->teamid = $this->team->teamid;
                        $sanction->level = HTMLResponse::fromPOST('sanctionlevel', 0);
                        $sanction->save();
                        HTMLResponse::exitWithRoute(HTMLResponse::getRoute());
                    }
                }

                ?>
                <h2>Añadir nueva sanción</h2>
                <form action="<?=HTMLResponse::getRoute()?>" method="post">
                    <table style="min-width: 512px">
                        <thead>
                        <tr>
                            <td>Tipo</td>
                            <td>Razón</td>
                        </tr>
                        </thead>

                        <tr>
                            <td>
                                <select name="sanctionlevel">
                                    <? foreach ($sanctionLevels as $index => $label) { ?>
                                        <option value="<?=$index?>">
                                            <?= $label ?>
                                        </option>
                                    <? } ?>
                                </select>
                            </td>
                            <td>
                                <textarea name="sanctionreason" style="width: 250px"></textarea>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" name="sanctioncsrf" value="<?=$csrf?>">
                    <div style="height: 6px"></div>
                    <button type="submit">Añadir sanción</button>
                </form>
                <?
            } ?><br>
            <?
            $this->showTeamSeasons();
            ?>
        </div>
        <?
    }
Example #5
0
    /**
     * @return void
     */
    public function show()
    {
        if (!TwitterAuth::isLogged()) {
            ?>
            Sólo los administradores pueden ver esta página.
            <a href="<?=HTMLResponse::getRoute()?>?authenticate=1">
                Inicia sesión.
            </a><br>
            <?
            return;
        }
        else if (!Team::isAdmin()) {
            ?>
            Sólo los administradores pueden ver esta página.<br>
            <?
            return;
        }
        else {
            $title = trim(HTMLResponse::fromPOST('title', ''));
            $description = trim(HTMLResponse::fromPOST('description', ''));
            $options = [];
            for ($i=1; $i<6; $i++) {
                $value = trim(HTMLResponse::fromPOST('option'.$i, ''));
                if (strlen($value)) {
                    $options[] = $value;
                }
            }

            if (strlen($title) && count($options)>=2) {
                $poll = Poll::create();
                $poll->title = $title;
                $poll->description = $description;
                $poll->isvisible = true;
                $poll->isopen = true;
                $poll->username = TwitterAuth::getUserName();
                $poll->userid = TwitterAuth::getUserId();
                $poll->dateline = time();
                $poll->avatar = TwitterAuth::getAvatar();
                $poll->save();

                foreach($options as $index => $option) {
                    $pollOption = PollOption::create();
                    $pollOption->pollid = $poll->pollid;
                    $pollOption->userid = TwitterAuth::getUserId();
                    $pollOption->username = TwitterAuth::getUserName();
                    $pollOption->title = $option;
                    $pollOption->save();
                }

                HTMLResponse::exitWithRoute("/votaciones/{$poll->pollid}/");
            }

            ?>
            <form action="<?=HTMLResponse::getRoute()?>" method="post">
                <div style="padding:3px">
                    <div class="inblock middle" style="width:120px">
                        Título
                    </div>
                    <input name="title" value="<?=htmlentities($title)?>">
                </div>

                <div style="padding:3px">
                    <div class="inblock middle" style="width:120px">
                        Descripción
                    </div>
                    <input name="description" value="<?=htmlentities($description)?>">
                </div>

                <?
                for ($i=1; $i<=6; $i++) {
                    ?>
                    <div style="padding:3px">
                        <div class="inblock middle" style="width:120px">
                            Opción <?=$i?>
                        </div>
                        <input name="option<?=$i?>" value="<?=htmlentities($options[$i-1])?>">
                    </div>
                    <?
                }
                ?>

                <div style="padding:3px">
                    <div class="inblock middle" style="width:120px">

                    </div>
                    <input type="submit" value="Crear votación">
                </div>
            </form>
            <?


        }
    }
Example #6
0
    /**
     * @return void
     */
    public function show()
    {
        $week = $this->week;
        $canVote = $this->canVote;

        $publishTime = $this->season->getPublishTimeForWeek($week);

        if ($publishTime >= 1000) {

            $days = explode(',', 'Domingo,Lunes,Martes,Miércoles,Jueves,Viernes,Sábado');
            $months = explode(',', 'enero,febrero,marzo,abril,mayo,junio,julio,agosto,septiembre,octubre,noviembre,diciembre')

            ?>
            <div>
                <?= $days[date('w', $publishTime)] ?>
                <?= date('j', $publishTime)?> de <?= $months[date('m', $publishTime)-1] ?> de <?= date('Y', $publishTime) ?>,
                <?= date('H:i', $publishTime) ?> (hora española)
            </div>
        <? } ?>
        <div style="height: 6px"></div>
        <table style="border: 0; padding: 0; margin: 0; width: 100%">
            <tr>
                <td style="width: 150px; border: 0; padding: 0; margin: 0; text-align: left">
                    <?
                    if ($this->week > 1) {
                        ?>
                        <a style="float:left; margin-left: 24px" href="/<?=$this->season->getLink()?>/jornadas/<?=$this->week-1?>/">
                            &lt;&lt;
                            Ver <?= strtolower($this->season->getWeekName($this->week-1)) ?>
                        </a>
                        <?
                    }
                    ?>
                </td>
                <td style="border: 0; padding: 0; margin: 0; text-align: center">
                    <?
                    if (time() >= $publishTime) {
                        ?>
                        <a href="javascript:void(0)" onclick="$('._grayscale').toggleClass('grayscale'); $('.result').toggle(); $(this).find('span').toggle()">
                            <span>Mostrar resultados</span>
                            <span style="display: none">Ocultar resultados</span>
                        </a>
                        <?
                    }
                    ?>
                </td>
                <td style="width: 150px; border: 0; padding: 0; margin: 0; text-align: right"><?
                    if ($this->week < $this->maxWeek) {
                        ?>
                        <a style="float:right; margin-right: 24px" href="/<?=$this->season->getLink()?>/jornadas/<?=$this->week+1?>/">
                            Ver <?= strtolower($this->season->getWeekName($this->week+1)) ?>
                            &gt;&gt;
                        </a>
                        <?
                    }
                    ?>
                </td>
            </tr>
        </table>
        <?

        $matches = Match::find('seasonid = ? and week = ? order by matchid asc', [$this->season->seasonid, $week]);
        #shuffle($matches);

        if (!$matches) {
            ?>
            No hay enfrentamientos disponibles en estos momentos.<br><br>
            <?
            return;
        }

        foreach($matches as $match) {
            $team1 = $match->getTeam1();
            $team2 = $match->getTeam2();

            if (false && rand(0,1) == 1) {
                $tmp = $team2;
                $team2 = $team1;
                $team1 = $tmp;
            }


            $voteTeamid = HTMLResponse::fromPOST('teamid','') * 1;
            $voteMatchid = HTMLResponse::fromPOST('matchid','') * 1;
            $voteUnteamid = HTMLResponse::fromPOST('unteamid','') * 1;
            $voteUnmatchid = HTMLResponse::fromPOST('unmatchid','') * 1;

            if ($canVote && TwitterAuth::isLogged() && !$match->hasVoted() && $match->matchid &&
                $voteMatchid == $match->matchid && ($voteTeamid == $team1->teamid || $voteTeamid == $team2->teamid)) {
                $bet = Bet::create();
                $bet->matchid = $match->matchid;
                $bet->dateline = time();
                $bet->userid = TwitterAuth::getUserId();
                $bet->teamid = $voteTeamid;
                $bet->username = TwitterAuth::getUserName();
                $bet->avatar = $_SESSION['twitter-avatar'];
                $bet->save();
            }

            if ($canVote && TwitterAuth::isLogged() && $match->hasVoted() &&
                $voteUnmatchid == $match->matchid && ($voteUnteamid == $team1->teamid || $voteUnteamid == $team2->teamid)) {
                $bet = Bet::findOne('matchid = ? and teamid = ? and userid = ?', array($voteUnmatchid, $voteUnteamid, TwitterAuth::getUserId()));
                $bet->delete();
            }

            $votes = $match->getVotes();
            $votesCount = array_sum($votes);

            $team1votes = 0;
            $team2votes = 0;
            if ($votesCount != 0) {
                $team1votes = $votes[$team1->teamid]*1;
                $team2votes = $votes[$team2->teamid]*1;
            }

            ?>

            <div class="matchbox">
                <? $this->showTeamBox($match, $team1, $team1votes, $votesCount) ?>
                <div class="vsbox">
                    <? if ($match->isPublished() && $match->getWinner()) {
                        $score1 = $team1->teamid==$match->getWinner() ? 6-$match->getLooserKills() : 0;
                        $score2 = $team2->teamid==$match->getWinner() ? 6-$match->getLooserKills() : 0;
                        ?>
                        <div style="font-size:90%; display: none" class="result">
                            <?=$score1?>-<?=$score2?>
                        </div>
                        <?
                    } else if ($match->isPublished() && $match->isDelayed()) { ?>
                        <div style="font-size:90%; display: none" class="result">
                            Apl.
                        </div>
                    <? } ?>
                    VS
                </div>
                <? $this->showTeamBox($match, $team2, $team2votes, $votesCount) ?>
            </div>
            <?
        }
    }
Example #7
0
    /**
     * @return void
     */
    public function show()
    {
        if (!TwitterAuth::isLogged()) {
            ?>
            Sólo los miembros pueden ver esta página.
            <a href="<?=HTMLResponse::getRoute()?>?authenticate=1">
                Inicia sesión.
            </a><br>
            <?
            return;
        }
        else {
            if (!Team::isMember()) {
                HTMLResponse::exitWithRoute('/votaciones/');
            }

            $answer = PollVote::findOne('userid = ? and pollid = ?',
                [TwitterAuth::getUserId(), $this->poll->pollid]);

            $options = PollOption::find('pollid = ? order by polloptionid asc', [$this->poll->pollid]);


            if (!$answer && strlen($hash = HTMLResponse::fromGET('hash', ''))) {
                $optionid = HTMLResponse::fromGET('vote');

                foreach($options as $index => $option) {
                    if ($option->polloptionid == $optionid && $option->getHash() == $hash) {
                        $answer = PollVote::create();
                        $answer->userid = TwitterAuth::getUserId();
                        $answer->dateline = time();
                        $answer->avatar = TwitterAuth::getAvatar();
                        $answer->pollid = $this->poll->pollid;
                        $answer->polloptionid = $option->polloptionid;
                        $answer->username = TwitterAuth::getUserName();
                        $answer->save();
                    }
                }
            }

            $answers = Model::groupBy(PollVote::find('pollid = ?', [$this->poll->pollid]), 'polloptionid');

            $hasAnswered = !!$answer;

            ?><div style="text-align:left; margin: 0 auto" class="inblock">
            <table style="width:640px">
                <thead>
                <tr>
                    <td>Lista de opciones</td>
                </tr>
                </thead>
                <?

                foreach($options as $index => $option) {
                    ?>
                    <tr><td class="row" style="text-align: left">
                            <div style="height: 6px"></div>
                            <div class="inblock middle" style="width:320px">
                                <b>Opción <?=$index+1?></b>: <?= htmlentities($option->title) ?>
                            </div>
                            <div class="inblock middle">
                                <div class="moreless inblock middle" style="width: 150px">
                                    <a href="javascript:void(0)" onclick="$(this).closest('.row').find('.moreless').toggle(); $(this).closest('.row').find('.onmore').slideDown(500);">+ Mostrar más</a>
                                </div>
                                <div class="moreless inblock middle" style="width: 150px; display: none">
                                    <a href="javascript:void(0)" onclick="$(this).closest('.row').find('.moreless').toggle(); $(this).closest('.row').find('.onmore').slideUp(400);">- Mostrar menos</a>
                                </div>
                            </div>
                            <div class="inblock middle">
                                <? if (!$hasAnswered) { ?>
                                    <a href="<?=HTMLResponse::getRoute()?>?vote=<?=$option->polloptionid?>&hash=<?=$option->getHash()?>" onclick="return confirm('¿Votas <?=htmlentities($option->title)?>?')">
                                        Votar esta opción
                                    </a>
                                <? } else if ($answer->polloptionid == $option->polloptionid) { ?>
                                    <i>Votaste esta opción</i>
                                <? } ?>
                            </div>
                            <div class="onmore" style="display: none; padding: 12px">
                                <?= $option->description ?>
                            </div>
                            <div style="height: 6px"></div>
                            <?
                            if (!$hasAnswered) {
                                ?><i>Vota primero para ver los resultados</i><?
                            }
                            else {
                                $optionAnswers = $answers[$option->polloptionid];
                                ?>
                                Votado por: <?= $optionAnswers
                                    ? '<b>'.implode(', ', Model::pluck($optionAnswers, 'username')).'</b> ('.count($optionAnswers).' votos)'
                                    : '<i>Nadie</i>'; ?>
                                <?
                            }
                            ?>
                            <div style="height: 6px"></div>
                        </td></tr>
                    <?
                }

                ?></table></div><br><br><?
        }
    }
Example #8
0
    /**
     * @return void
     */
    public function show()
    {
        $matches = Match::find('seasonid = ? and result != 0', [$this->season->seasonid]);
        $matches = Model::indexBy($matches, 'matchid');

        $teams = Model::indexBy(Team::find('1=1'), 'teamid');

        $matchWinner = [];

        foreach($matches as $match) {
            if ($this->season->weekIsPublished($match->week) && !$match->isDelayed()) {
                $matchWinner[$match->matchid] = $match->getWinner();
            }
        }

        $totalBets = [];
        $correctBets = [];

        $usernames = [];
        $avatars = Model::pluck(Avatar::find('1=1'), 'url', 'userid');

        foreach(Bet::find('1=1') as $bet) {
            if (isset($matchWinner[$bet->matchid])) {
                if ($bet->teamid && $matchWinner[$bet->matchid] == $bet->teamid) {
                    $correctBets[$bet->userid]++;
                }
                $totalBets[$bet->userid]++;
            }
            if ($bet->username) {
                $usernames[$bet->userid] = $bet->username;
            }
        }

        $tiebreakers = [];
        foreach(array_keys($correctBets) as $userid) {
            $tiebreakers[$userid] = [-$correctBets[$userid], $totalBets[$userid], strtolower($usernames[$userid])];
        }
        asort($tiebreakers);


        if (TwitterAuth::isLogged()) {
            $userid = TwitterAuth::getUserId();
            $userBets = Bet::find('userid = ? order by matchid desc', [$userid]);

            $userpos = array_search($userid, array_keys($tiebreakers));
            $userpos = ($userpos === FALSE) ? 0 : $userpos+1;

            ?>
            <div class="inblock" style="text-align: left; margin-right: 20px">
                <h2>Tus estadísticas</h2>
                <table>
                    <thead>
                    <tr>
                        <td>Puesto</td>
                        <td>Nombre</td>
                        <td>Aciertos</td>
                        <td>Fallos</td>
                    </tr>
                    </thead>
                    <tr>
                        <td><?= $userpos ?>º</td>
                        <td style="text-align: left">
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <img src="<?= htmlentities($avatars[$userid]) ?>" style="width:40px; height:40px; border-radius: 20px">
                                </a>
                            </div>
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <?= htmlentities($usernames[$userid]) ?>
                                    <? if (!isset($usernames[$userid])) echo "<i>$userid</i>"; ?>
                                </a>
                            </div>
                        </td>
                        <td><?= $correctBets[$userid] ?></td>
                        <td><?= $totalBets[$userid]-$correctBets[$userid] ?></td>
                    </tr>
                </table>

                <h2>Tus apuestas</h2>
                <table>
                    <thead>
                    <tr>
                        <td>Jornada</td>
                        <td>Enfrentamiento</td>
                        <td>Acierto</td>
                    </tr>
                    </thead>
                    <? foreach($userBets as $bet) {
                        if (!isset($matches[$bet->matchid])) continue;
                        /**
                         * @var $match Match
                         */
                        $match = $matches[$bet->matchid];
                        if (!$match->isPublished() || $match->isDelayed()) continue;

                        $team1 = $teams[$match->team1id];
                        $team2 = $teams[$match->team2id];

                        $success = $match->getWinner() == $bet->teamid;
                        ?>
                        <tr>
                            <td><?= $match->week ?></td>
                            <td>
                                <div class="inblock">
                                    <div class="teamimg64">
                                        <img src="/<?= $team1->getImageLink(64, 64) ?>" class="<?= $match->getWinner() == $team1->teamid ? '' : 'grayscale' ?>">
                                    </div>
                                    <? if ($bet->teamid == $team1->teamid) { ?>
                                        <br><i style="font-size:11px">Votado</i>
                                    <? } ?>
                                </div>

                                <div class="inblock" style="line-height: 64px; margin: 0px 4px">
                                    VS
                                </div>

                                <div class="inblock">
                                    <div class="teamimg64">
                                        <img src="/<?= $team2->getImageLink(64, 64) ?>" class="<?= $match->getWinner() == $team2->teamid ? '' : 'grayscale' ?>">
                                    </div>
                                    <? if ($bet->teamid == $team2->teamid) { ?>
                                        <br><i style="font-size:11px">Votado</i>
                                    <? } ?>
                                </div>
                            </td>
                            <td>
                                <?= $success
                                    ? '<div class="success-icon">&#x2714;</div>'
                                    : '<div class="fail-icon">&#x2718</div>' ?>
                            </td>

                        </tr>
                        <?
                    } ?>
                </table>
            </div>
            <?
        }


        ?>
        <div class="inblock">
            <h2>Clasificación</h2>
            <table>
                <thead>
                <tr>
                    <td>Puesto</td>
                    <td>Nombre</td>
                    <td>Aciertos</td>
                    <td>Fallos</td>
                </tr>
                </thead>

                <?
                $lastTiebreakers = null;
                $lastPos = 0;
                foreach(array_keys($tiebreakers) as $pos => $userid) {
                    unset($tiebreakers[$userid][2]);

                    if ($lastTiebreakers != $tiebreakers[$userid]) {
                        $lastPos = $pos;
                    }

                    if (!isset($avatars[$userid])) {
                        Avatar::setUsersAvatar($userid, $usernames[$userid]);
                    }
                    ?>
                    <tr>
                        <td><?= $lastPos+1 ?>º</td>
                        <td style="text-align: left">
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <img src="<?= htmlentities($avatars[$userid]) ?>" style="width:40px; height:40px; border-radius: 20px">
                                </a>
                            </div>
                            <div class="inblock" style="vertical-align: middle">
                                <a href="http://twitter.com/<?=htmlentities($usernames[$userid])?>" target="_blank">
                                    <?= htmlentities($usernames[$userid]) ?>
                                    <? if (!isset($usernames[$userid])) echo "<i>$userid</i>"; ?>
                                </a>
                            </div>
                        </td>
                        <td><?= $correctBets[$userid] ?></td>
                        <td><?= $totalBets[$userid]-$correctBets[$userid] ?></td>
                    </tr>
                    <?
                    $lastTiebreakers = $tiebreakers[$userid];
                }
                ?>
            </table>
        </div>
        <?
    }