コード例 #1
0
ファイル: BetController.php プロジェクト: Cclleemm/worldcup
 /**
  * Enregistre un nouveau paris
  *
  * @return Response
  */
 public function store()
 {
     $user = User::getUserWithToken($_GET['token']);
     $input = Input::all();
     $input['user_id'] = $user->id;
     $validator = Validator::make($input, Bet::$rules, BaseController::$messages);
     if ($validator->fails()) {
         return Response::json(array('success' => false, 'payload' => array(), 'error' => $this->errorsArraytoString($validator->messages())), 400);
     }
     //On vérifie si la date du match n'est pas dépassé
     if (new DateTime() > new DateTime(Game::find($input['game_id'])->date)) {
         return Response::json(array('success' => false, 'payload' => array(), 'error' => "Le date du match est dépassé !"), 400);
     }
     $bet = Bet::whereRaw('user_id = ? && game_id = ?', array($input['user_id'], $input['game_id']))->first();
     //Si un paris sur le même match pour cet utilisateur existe, erreur envoyée.
     if ($bet) {
         return Response::json(array('success' => false, 'payload' => array(), 'error' => "Un paris existe déjà sur ce match !"), 400);
     }
     //On vérifie si la somme misé est disponible
     if ($input['points'] > $user->points) {
         return Response::json(array('success' => false, 'payload' => array(), 'error' => "Vous avez miser plus de points que vous en avez !"), 400);
     }
     $game = Game::find($input['game_id']);
     //On vérifie si le winner est bien une équipe du match
     if ($input['winner_id'] != $game->team1_id && $input['winner_id'] != $game->team2_id) {
         return Response::json(array('success' => false, 'payload' => array(), 'error' => "Veuillez mettre une équipe du match !"), 400);
     }
     $bet = Bet::create($input);
     Transaction::addTransaction($input['user_id'], $bet->id, $input['points'], 'bet');
     return Response::json(array('success' => true, 'payload' => $bet->toArray(), 'message' => 'Pari enregistré (' . $bet->points . ' points) sur : ' . $game->team1->name . ' (' . $bet->team1_goals . ') - (' . $bet->team2_goals . ') ' . $game->team2->name));
 }
コード例 #2
0
ファイル: Season_Index.php プロジェクト: xJakub/LCE
    /**
     * @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>
            <?
        }
    }