Exemplo n.º 1
0
 public function store(SaveGamesRequest $request)
 {
     $input = $request->except('_token');
     $count = count($input['home_id']);
     for ($i = 0; $i < $count; $i++) {
         $match = new Matches();
         $match->home_id = $input['home_id'][$i];
         $match->away_id = $input['away_id'][$i];
         $match->matchday = $input['matchday'];
         $match->home_goals = NULL;
         $match->away_goals = NULL;
         $match->date = $input['date'][$i];
         $match->season = $input['season'];
         $match->league_id = $input['league_id'];
         $match->save();
     }
     return redirect('admin/spielplan');
 }
Exemplo n.º 2
0
 /**
  * Saves matches into database
  *
  * 
  */
 public function storeGamesForm(SaveGamesRequest $request)
 {
     $input = $request->except('_token');
     $count = count($input['match_id']);
     for ($i = 0; $i < $count; $i++) {
         if ($input['home_goals'][$i] != '') {
             DB::table('matches')->where('id', $input['match_id'][$i])->update(['home_goals' => $input['home_goals'][$i], 'away_goals' => $input['away_goals'][$i]]);
         }
     }
     // Update Tables .tables
     for ($i = 0; $i < $count; $i++) {
         if ($input['home_goals'][$i] != '') {
             // Update der Heimmannschaft
             $homePoints = 0;
             if ($input['home_goals'][$i] > $input['away_goals'][$i]) {
                 $homePoints = 3;
             } elseif ($input['home_goals'][$i] === $input['away_goals'][$i]) {
                 $homePoints = 1;
             }
             //TODO: Check if club_id exists in table
             if (Table::where('club_id', $input['home_id'][$i])->first() != NULL) {
                 Table::where('club_id', $input['home_id'][$i])->update(['goals' => DB::raw('goals +' . $input['home_goals'][$i]), 'goals_against' => DB::raw('goals_against +' . $input["away_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $homePoints)]);
             } else {
                 Table::insert(['club_id' => $input['home_id'][$i], 'goals' => DB::raw('goals +' . $input['home_goals'][$i]), 'goals_against' => DB::raw('goals_against +' . $input["away_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $homePoints), 'league_id' => $input['league'], 'season' => $input['season']]);
             }
             //Update der Auswärtsmannschaft
             $awayPoints = 0;
             if ($input['home_goals'][$i] < $input['away_goals'][$i]) {
                 $awayPoints = 3;
             } elseif ($input['home_goals'][$i] == $input['away_goals'][$i]) {
                 $awayPoints = 1;
             }
             if (Table::where('club_id', $input['away_id'][$i])->first() != NULL) {
                 Table::where('club_id', $input['away_id'][$i])->update(['goals' => DB::raw('goals + ' . $input["away_goals"][$i]), 'goals_against' => DB::raw('goals_against + ' . $input["home_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $awayPoints)]);
             } else {
                 Table::insert(['club_id' => $input['away_id'][$i], 'goals' => DB::raw('goals + ' . $input["away_goals"][$i]), 'goals_against' => DB::raw('goals_against + ' . $input["home_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $awayPoints), 'league_id' => $input['league'], 'season' => $input['season']]);
             }
         }
     }
     return redirect('spiele');
 }