Beispiel #1
0
 private function setRound()
 {
     $start_stage_id = Stage::getStartStage()->id;
     $next_stage_id = $start_stage_id;
     while ($next_stage_id) {
         $games = array();
         $this->labels[] = Stage::find($next_stage_id)->name;
         $next_stage_id_tmp = Stage::find($next_stage_id)->next_stage;
         foreach (Game::whereRaw('stage_id = ?', array($next_stage_id))->orderBy('stage_game_num', 'ASC')->get() as $value) {
             $score1 = $value->team1_goals;
             $score2 = $value->team2_goals;
             if ($value->team1_kick_at_goal != null && $value->team2_kick_at_goal != null) {
                 $score1 .= " (" . $value->team1_kick_at_goal . ")";
             }
             if ($value->team1_kick_at_goal != null && $value->team2_kick_at_goal != null) {
                 $score2 .= " (" . $value->team2_kick_at_goal . ")";
             }
             $games[] = array(array('name' => $value->team1()->first() ? $value->team1()->first()->name : "-", 'id' => $value->team1_id, 'score' => $score1), array('name' => $value->team2()->first() ? $value->team2()->first()->name : "-", 'id' => $value->team2_id, 'score' => $score2));
         }
         $this->rounds[] = $games;
         if ($next_stage_id_tmp == null) {
             $gamme = Game::whereRaw('stage_id = ? && stage_game_num = 1', array($next_stage_id))->first();
             //Vinqueur
             $this->rounds[] = array(array(array('name' => $gamme->winner()->first() ? $gamme->winner()->first()->name : "-", 'id' => $gamme->winner_id)));
         }
         $next_stage_id = $next_stage_id_tmp;
     }
     /////////////////////////////////////////////////
     //******************* 3e place ****************//
     /////////////////////////////////////////////////
     $stage_third = Stage::getThirdStage()->id;
     $gamme_third = Game::whereRaw('stage_id = ?', array($stage_third))->first();
     if ($gamme_third != null) {
         $score1 = $value->team1_goals;
         $score2 = $value->team2_goals;
         if ($gamme_third->team1_kick_at_goal != null && $gamme_third->team2_kick_at_goal != null) {
             $score1 .= " (" . $gamme_third->team1_kick_at_goal . ")";
         }
         if ($gamme_third->team1_kick_at_goal != null && $gamme_third->team2_kick_at_goal != null) {
             $score2 .= " (" . $gamme_third->team2_kick_at_goal . ")";
         }
         $this->third[] = array(array(array('name' => $gamme_third->team1()->first() ? $gamme_third->team1()->first()->name : "-", 'id' => $gamme_third->team1_id, 'score' => $score2), array('name' => $gamme_third->team2()->first() ? $gamme_third->team2()->first()->name : "-", 'id' => $gamme_third->team2_id, 'score' => $score2)));
         //Vinqueur 3e place
         $this->third[] = array(array(array('name' => $gamme_third->winner()->first() ? $gamme_third->winner()->first()->name : "-", 'id' => $gamme_third->winner_id)));
     }
 }
Beispiel #2
0
 public function setFinished($num_team)
 {
     //Si l'équipe une a gagnée, on redistribue les points pour les paris corrects (paris sur l'équipe une)
     if ($num_team == 1) {
         foreach (Bet::whereRaw('game_id = ? && winner_id = ?', array($this->id, $this->team1_id))->get() as $bet) {
             $cote = $this->getTeam1CoteAttribute();
             $points = $bet->points * $cote;
             if ($this->team1_goals == $bet->team1_goals && $this->team2_goals == $bet->team2_goals) {
                 $points += $bet->points / 10 * $cote;
             }
             Transaction::addTransaction($bet->user_id, $bet->id, $points, 'gain');
         }
         $this->winner_id = $this->team1_id;
         //Si l'équipe deux a gagnée, on redistribue les points pour les paris corrects (paris sur l'équipe deux)
     } else {
         foreach (Bet::whereRaw('game_id = ? && winner_id = ?', array($this->id, $this->team2_id))->get() as $bet) {
             $cote = $this->getTeam2CoteAttribute();
             $points = $bet->points * $cote;
             if ($this->team1_goals == $bet->team1_goals && $this->team2_goals == $bet->team2_goals) {
                 $points += $bet->points / 10 * $cote;
             }
             Transaction::addTransaction($bet->user_id, $bet->id, $points, 'gain');
         }
         $this->winner_id = $this->team2_id;
     }
     /////////////////////////////////////////////////
     //******************* ROUND X *****************//
     /////////////////////////////////////////////////
     //On inscrit l'équipe gagnante dans son prochain match
     $id = $this->stage()->first()->next_stage()->first()->id;
     $num_game = round($this->stage_game_num / 2);
     $game = Game::whereRaw("stage_id = ? && stage_game_num = ?", array($id, $num_game))->first();
     if ($this->stage_game_num % 2 == 1) {
         $game->team1_id = $this->winner_id;
     } else {
         $game->team2_id = $this->winner_id;
     }
     $game->save();
     /////////////////////////////////////////////////
     //******************* 3e place ****************//
     /////////////////////////////////////////////////
     //Si on est lors des demi, on va définir aussi la 3e finale
     if ($this->stage()->first()->next_stage()->first()->next_stage == null) {
         $stage_third = Stage::getThirdStage()->id;
         $gamme_third = Game::whereRaw('stage_id = ?', array($stage_third))->first();
         //Si équipe 1 a gagné on met l'équipe 2 en 3e place
         if ($num_game == 1) {
             if ($this->stage_game_num % 2 == 1) {
                 $gamme_third->team1_id = $this->team1_id;
             } else {
                 $gamme_third->team2_id = $this->team1_id;
             }
         } else {
             if ($this->stage_game_num % 2 == 1) {
                 $gamme_third->team1_id = $this->team2_id;
             } else {
                 $gamme_third->team2_id = $this->team2_id;
             }
         }
         $gamme_third->save();
     }
     $this->save();
 }