static function getUsersTeam() { if (!TwitterAuth::isLogged()) { return null; } return Team::find('username = ?', [TwitterAuth::getUserName()]); }
/** * @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]); }
/** * @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()) { ?> Sólo los miembros pueden ver esta página.<br> <? return; } else { ?><div style="text-align: left; margin: 0 auto" class="inblock"><? if (Team::isMember()) { ?><ul><? foreach(Poll::find('isvisible order by dateline desc') as $poll) { ?> <li> <a href="/votaciones/<?=$poll->pollid?>/"> <?=htmlentities($poll->title)?> </a> </li> <? } ?></ul><? ?> <a href="/votaciones/crear/"> Haz click aquí para añadir una nueva votación. </a> <? } ?></div><br><br><? } }
/** * @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> <? } }
/** * @param $match Match * @param $team Team * @param $team1votes * @param $votesCount */ private function showTeamBox($match, $team, $team1votes, $votesCount) { $video = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $team->teamid, 1]); $canVote = $this->canVote; $team1per = 50; if ($votesCount != 0) { $team1per = round($team1votes / $votesCount * 100); } $team2 = ($match->team1id == $team->teamid) ? $match->getTeam2() : $match->getTeam1(); $isGray = ($match->isPublished() && $match->getWinner() && $match->getWinner() != $team->teamid); ?> <div class="teambox"> <div class="votecount"><?=$team1votes?> votos (<?=$team1per?>%)</div> <? if ($canVote) { ?> <? if (TwitterAuth::isLogged()) { ?> <? if (!$match->hasVoted()) { ?> <form method="post" action="<?=HTMLResponse::getRoute()?>"> <button type="submit" class="vote">Votar</button> <input type="hidden" name="teamid" value="<?=$team->teamid?>"> <input type="hidden" name="matchid" value="<?=$match->matchid?>"> </form> <? } else if ($match->hasVoted() == $team->teamid) { ?> <form method="post" action="<?=HTMLResponse::getRoute()?>"> <div class="login"> <button type="submit">Quitar voto</button> <a target="_blank" class="twitter-share-button" href="https://twitter.com/intent/tweet?text=<?=urlencode("¡He votado que #".$team->getHashtag()." ganará a #".$team2->getHashtag()." en la @LCE_Pokemon! http://lce.wz.tl")?>"> ¡Twittear!</a> </div> <input type="hidden" name="unteamid" value="<?=$team->teamid?>"> <input type="hidden" name="unmatchid" value="<?=$match->matchid?>"> </form> <? } ?> <? } else { ?> <a href="<?= HTMLResponse::getRoute() ?>?authenticate=1" class="login">¡Usa Twitter para votar!</a> <? } ?> <? } else { ?> <? if (TwitterAuth::isLogged()) { ?> <? if (!$match->isPublished() || !$match->getWinner()) { ?> <? if ($match->hasVoted() == $team->teamid) { ?> <span class="login">Has votado por este equipo</span> <? } ?> <? } else if ($video) { ?> <a class="login" href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? } ?> <? } else if (!$match->isPublished()) { ?> <a href="<?= HTMLResponse::getRoute() ?>?authenticate=1" class="login">¡Entra para ver tus votos!</a> <? } else if ($video) { ?> <a class="login" href="<?=htmlentities($video->link)?>" target="_blank"> Ver combate </a> <? } ?> <? } ?> <a href="/<?=$this->season->getLink()?>/equipos/<?=$team->getLink()?>/"><img class="<?=$isGray?'_grayscale':''?>" src="/<?=$team->getImageLink(200, 150)?>"></a> </div> <? }
/** * @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><? } }
/** * @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">✔</div>' : '<div class="fail-icon">✘</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> <? }
public function showBody() { ?> <div id="main" class="public"> <div class="content"> <div class="banner"></div> <div class="nav" style="text-align: left"> <?php foreach ($this->topMenu as $arr) { list($link, $label, $re) = $arr; $status = ''; if (preg_match("'^$re$'", HTMLResponse::getRoute())) { $status = 'selected'; } ?><a href="<?= $link ?>" class="<?= $status ?>"><?= $label ?></a><?php } ?> <div style="float: right"> <select name="season" id="navSeason"> <?php $seasons = Team::isSuperAdmin() ? Season::find('1=1') : Season::find('ispublic'); foreach($seasons as $season) { $selected = $season->seasonid == $this->season->seasonid ? 'selected' : ''; ?> <option value="<?=$season->getLink()?>" <?=$selected?>> <?=htmlentities($season->name)?> </option> <? } ?> </select> </div> </div> <div style="padding: 6px"> <?php if (TwitterAuth::isLogged()) { ?> Estás identificado como <?=htmlentities(TwitterAuth::getUserName())?>. <a href="<?=HTMLResponse::getRoute()?>?logout=1">Cerrar sesión</a> <?php if (Team::isMember()) { ?>/ <a href="/votaciones/">Votaciones</a><?php } ?> <?php if (Team::isSuperAdmin()) { ?>/ <a href="/admin/">Panel de admin</a><?php } ?> <br> <?php if (TwitterAuth::isBot()) { $botConfig = TwitterAuth::getBotConfig(); ?> <br>Eres la cuenta oficial de la LCE, haz <a href="/?authenticatebot=1">click aquí</a> para autorizar esta web a usarte como un bot.<br> <b>Última autorización:</b> <?= isset($botConfig['dateline']) ? date('Y/m/d H:i:s', $botConfig['dateline']) : 'Nunca' ?> <?php } ?> <?php } else { ?> No estás identificado. <a href="<?=HTMLResponse::getRoute()?>?authenticate=1">Iniciar sesión</a><br> <?php } ?> </div> <div class="title"> <?= $this->section->getSubtitle() ?> </div> <?=$this->contents?> </div> </div> <?php }