/** * Display the form to edit a match * @param [type] $league_id [description] * @param [type] $match_id [description] * @return [type] [description] */ public function editMatch($league_id, $match_id) { $league = League::find($league_id); $players = \DB::table('league_players')->where('leage_id', '=', $league_id)->orderby('last_name')->orderby('first_name'); //dropdown list $players_list = Player::orderby('last_name')->orderby('first_name')->get(); $players_list = $players_list->lists('last_first_name', 'player_id'); //get the match $match = Match::find($match_id); if (!is_null($match)) { //Get the game $match_game = MatchGame::find($match_id); if (!is_null($match_game)) { $game = Game::find($match_game->game_id); } else { $game = new Game(); } } return view('pages/tools.league.match.edit', compact('match', 'game', 'league', 'players_list')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $league = League::find($id); $path = $league->logo_path; $name = $league->logo_name; $file = $path . $name; if (\File::isFile($file)) { \File::delete($file); } $league->delete(); flash()->success('', 'Lyga ištrinta!'); return redirect()->back(); }
public function GetLeagueById($id) { return League::find($id); }
public function viewGame($id) { $roundGame = Game::find($id); if (!count($roundGame)) { return redirect()->route('home'); } $league = League::find($roundGame->league_id); $players = [User::find($roundGame->user_1_id), User::find($roundGame->user_2_id)]; $round = $roundGame->round; $gameDate = []; $dayOffset = 0; for ($i = 0; $i < 20; $i++) { if (date("U", strtotime(date('d-m-Y'))) > date("U", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset)) { if ($round == $i + 1) { $gameDate['day'] = date("j", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset); $gameDate['month'] = date("n", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset); $gameDate['year'] = date("Y", strtotime('first monday of ' . $league->year . '-' . $league->month) + 86400 * $dayOffset); } } if (($i + 1) % 5 == 0) { $dayOffset = $dayOffset + 3; } else { $dayOffset++; } } if (!count($gameDate)) { return redirect()->route('home'); } $roundQuestions = Question::where('year', intval($gameDate['year']))->where('month', intval($gameDate['month']))->where('day', intval($gameDate['day']))->get(); $roundAnswers = array(array()); $filetype = []; foreach ($roundQuestions as $roundQuestion) { $filetype[$roundQuestion->id] = pathinfo($roundQuestion->filename, PATHINFO_EXTENSION); $roundAnswers[0][$roundQuestion->id] = Answer::where('submitted', 1)->where('user_id', $roundGame->user_1_id)->where('question_id', $roundQuestion->id)->first(); $roundAnswers[1][$roundQuestion->id] = Answer::where('submitted', 1)->where('user_id', $roundGame->user_2_id)->where('question_id', $roundQuestion->id)->first(); if (count($roundAnswers[0][$roundQuestion->id]) && count($roundAnswers[1][$roundQuestion->id])) { $roundAnswers[0][$roundQuestion->id]['pointsAttr'] = $roundAnswers[1][$roundQuestion->id]->points; $roundAnswers[1][$roundQuestion->id]['pointsAttr'] = $roundAnswers[0][$roundQuestion->id]->points; $roundAnswers[0][$roundQuestion->id]['pointsWon'] = $roundAnswers[0][$roundQuestion->id]->correct * $roundAnswers[1][$roundQuestion->id]->points; $roundAnswers[1][$roundQuestion->id]['pointsWon'] = $roundAnswers[1][$roundQuestion->id]->correct * $roundAnswers[0][$roundQuestion->id]->points; $players[0]['points'] += $roundAnswers[0][$roundQuestion->id]['pointsWon']; $players[1]['points'] += $roundAnswers[1][$roundQuestion->id]['pointsWon']; $players[0]['corrects'] += $roundAnswers[0][$roundQuestion->id]->correct; $players[1]['corrects'] += $roundAnswers[1][$roundQuestion->id]->correct; } else { if (count($roundAnswers[0][$roundQuestion->id])) { $roundAnswers[1][$roundQuestion->id]['correct'] = 0; $roundAnswers[0][$roundQuestion->id]['pointsWon'] = 'Correcta'; $roundAnswers[1][$roundQuestion->id]['pointsWon'] = 'Falta'; $roundAnswers[0][$roundQuestion->id]['pointsAttr'] = 'Errada'; $players[0]['corrects'] += $roundAnswers[0][$roundQuestion->id]->correct; $players[1]['corrects'] = 'F'; $players[1]['points'] = 'F'; switch ($players[0]['corrects']) { case 0: $players[0]['points'] = 0; break; case 1: $players[0]['points'] = 2; break; case 2: $players[0]['points'] = 3; break; case 3: $players[0]['points'] = 5; break; case 4: $players[0]['points'] = 6; break; case 5: $players[0]['points'] = 8; break; case 6: $players[0]['points'] = 9; break; case 7: $players[0]['points'] = 10; break; case 8: $players[0]['points'] = 12; break; } } else { if (count($roundAnswers[1][$roundQuestion->id])) { $roundAnswers[0][$roundQuestion->id]['correct'] = 0; $roundAnswers[0][$roundQuestion->id]['pointsWon'] = 'Falta'; $roundAnswers[1][$roundQuestion->id]['pointsWon'] = 'Correcta'; $roundAnswers[1][$roundQuestion->id]['pointsAttr'] = 'Errada'; $players[0]['corrects'] = 'F'; $players[1]['corrects'] += $roundAnswers[1][$roundQuestion->id]->correct; $players[0]['points'] = 'F'; switch ($players[1]['corrects']) { case 0: $players[1]['points'] = 0; break; case 1: $players[1]['points'] = 2; break; case 2: $players[1]['points'] = 3; break; case 3: $players[1]['points'] = 5; break; case 4: $players[1]['points'] = 6; break; case 5: $players[1]['points'] = 8; break; case 6: $players[1]['points'] = 9; break; case 7: $players[1]['points'] = 10; break; case 8: $players[1]['points'] = 12; break; } } else { $roundAnswers[0][$roundQuestion->id]['correct'] = 0; $roundAnswers[1][$roundQuestion->id]['correct'] = 0; $roundAnswers[0][$roundQuestion->id]['pointsAttr'] = 'Falta'; $roundAnswers[1][$roundQuestion->id]['pointsAttr'] = 'Falta'; $players[0]['points'] = 'F'; $players[1]['points'] = 'F'; } } } $corrects = count(Answer::where('submitted', 1)->where('question_id', $roundQuestion->id)->where('correct', 1)->get()); $total = count(Answer::where('submitted', 1)->where('question_id', $roundQuestion->id)->get()); $roundAnswers['percentage'][$roundQuestion->id] = round($corrects / $total * 100, 2); } return view('game')->with(['date' => $gameDate, 'players' => $players, 'roundQuestions' => $roundQuestions, 'filetype' => $filetype, 'roundAnswers' => $roundAnswers]); }