225 lines
No EOL
7.1 KiB
PHP
225 lines
No EOL
7.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Leagues;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Leagues;
|
|
|
|
|
|
use Auth;
|
|
use App\Season;
|
|
use App\Round;
|
|
use App\User;
|
|
|
|
use App\Leagues\League;
|
|
use App\Leagues\LeagueMember;
|
|
use App\Leagues\Match;
|
|
|
|
use Log;
|
|
use DB;
|
|
|
|
use App\MyClasses\TimeLogger;
|
|
|
|
class LeaguesController extends Controller
|
|
{
|
|
public function index() {
|
|
$a=new TimeLogger("LeaguesController.index");
|
|
Log::info($a->getStartMessage());
|
|
|
|
$season=Season::getCurrent();
|
|
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
if (!Auth::user()->admin) { return redirect("/"); }
|
|
|
|
$season = Season::where('id','=',$season->id)->first();
|
|
if (!$season) return redirect("/seasons");
|
|
|
|
$start_round_name="Einstellen";
|
|
|
|
$rounds = Round::where('season_id','=',$season->id)->orderBy('id')->get();
|
|
if (!$rounds) return redirect("/seasons");
|
|
|
|
$round_count = 18;
|
|
$start_round_name="Einstellen";
|
|
$start_round_id=$rounds[0]->id;
|
|
$league_mode="Einstellen";
|
|
|
|
$league = League::where('season_id','=',$season->id)->first();
|
|
if ($league) {
|
|
$startround = Round::where('season_id', '=', $season->id)->orderBy('id')->first();
|
|
$start_round_id = $startround->id;
|
|
|
|
$startRound = Round::where('id','=',$league->start_round_id)->first();
|
|
$start_round_name = $startRound->name;
|
|
$start_round_id = $startRound->id;
|
|
$round_count = $league->round_count;
|
|
if($league->is_qualification) { $league_mode="Qualifikation"; } else { $league_mode="Liga-Spiel"; }
|
|
}
|
|
|
|
// Fetch existing leagues
|
|
|
|
// No leagues: Create Qualification League or Standard League System (including matches)
|
|
// necessary input: start_round(_id), round_count
|
|
|
|
// Delete all leagues & matches
|
|
|
|
//
|
|
|
|
Log::info($a->getEndMessage());
|
|
|
|
return view('leagues.index', compact('season','rounds','start_round_id','start_round_name','league_mode','round_count'));
|
|
}
|
|
|
|
public function createLeagues($start_round_id, $round_count) {
|
|
Log::info("CREATE_LEAGUES");
|
|
$a=new TimeLogger("LeaguesController::createLeagues()");
|
|
Log::info($a->getStartMessage());
|
|
|
|
$users=User::getActives();
|
|
if (sizeof($users)==0){
|
|
Log::info($a->getEndMessage());
|
|
return view("leagues.no_users");
|
|
}
|
|
|
|
League::createLeagues($start_round_id, $round_count);
|
|
|
|
Log::info("LeaguesController::createLeagues completed.");
|
|
|
|
Match::createMatchups();
|
|
|
|
Log::info($a->getEndMessage());
|
|
return redirect("/seasons");
|
|
}
|
|
|
|
public function showLeagueRounds() {
|
|
if (Auth::guest()) { return redirect("/"); }
|
|
|
|
$a=new TimeLogger("LeaguesController::showLeagueRounds()");
|
|
Log::info($a->getStartMessage());
|
|
|
|
$season=Season::getCurrent();
|
|
|
|
$roundNames = Round::getNames();
|
|
$leagueNames = League::getNames();
|
|
$leagues = League::where('season_id','=',$season->id)->where('rank','<=', 4)->orderBy('id')->get();
|
|
$matchesTotal = array();
|
|
|
|
foreach ($leagues as $league) {
|
|
$matches = Match::getMatchResults($league->id, -1);
|
|
foreach ($matches as $match) {
|
|
if (!key_exists($match->round_id, $matchesTotal)) {
|
|
$matchesTotal[$match->round_id]=array();
|
|
}
|
|
if (!key_exists($league->id, $matchesTotal[$match->round_id] )) {
|
|
$matchesTotal[$match->round_id][$league->id]=array();
|
|
}
|
|
$lg = $matchesTotal[$match->round_id][$league->id];
|
|
array_push($lg, $match);
|
|
$matchesTotal[$match->round_id][$league->id] = $lg;
|
|
}
|
|
}
|
|
Log::info($a->getEndMessage());
|
|
|
|
return view ('leagues.matches', compact('season', 'matchesTotal','leagues','leagueNames','roundNames'));
|
|
}
|
|
|
|
|
|
|
|
public static function showLeagueRanking() {
|
|
|
|
$a=new TimeLogger("LeaguesController::showLeagueRanking()");
|
|
Log::info($a->getStartMessage());
|
|
|
|
$season = Season::getCurrent();
|
|
//$leagues = array_reverse(League::getRanking($rank));
|
|
$leagueNames = League::getNames();
|
|
$userNames = User::getNames();
|
|
|
|
$leagues = League::where('season_id','=',$season->id)->where('rank','<=', 4)->orderBy('id')->get();
|
|
if (!sizeof($leagues)) {
|
|
Log::info($a->getEndMessage());
|
|
return redirect("/");
|
|
}
|
|
|
|
$totalRanking = League::getTotalRankingOverall(); // Nur für Auf/Abstiegsinfo benötigt.
|
|
$rankInfo=array();
|
|
|
|
foreach($totalRanking as $index => $entry) {
|
|
$userId=$entry[0];
|
|
$rankInfo[$userId]=$totalRanking[$index][4];
|
|
}
|
|
|
|
$cols=array();
|
|
$cols[1]="greenyellow";
|
|
$cols[2]="orange";
|
|
$cols[3]="lightgrey";
|
|
$cols[4]="";
|
|
|
|
$leagueScores=array();
|
|
foreach([1,2,3,4] as $rank) {
|
|
$leagueScores[$rank] = League::getRanking($rank);
|
|
}
|
|
|
|
Log::info($a->getEndMessage());
|
|
//error_log($a->getEndMessage());
|
|
|
|
return view ('leagues.chart',compact('season', 'leagueNames', 'userNames','leagueScores','rankInfo','rank','cols'));
|
|
}
|
|
|
|
// Originall copied over from showLeagueRanking
|
|
public static function showLeagueSwapForm() {
|
|
|
|
$a=new TimeLogger("LeaguesController::showLeagueSwapForm()");
|
|
Log::info($a->getStartMessage());
|
|
|
|
$season = Season::getCurrent();
|
|
//$leagues = array_reverse(League::getRanking($rank));
|
|
$leagueNames = League::getNames();
|
|
$userNames = User::getNames();
|
|
|
|
$leagues = League::where('season_id','=',$season->id)->where('rank','<=', 4)->orderBy('id')->get();
|
|
if (!sizeof($leagues)) {
|
|
Log::info($a->getEndMessage());
|
|
return redirect("/");
|
|
}
|
|
|
|
$totalRanking = League::getTotalRankingOverall(); // Nur für Auf/Abstiegsinfo benötigt.
|
|
$rankInfo=array();
|
|
|
|
foreach($totalRanking as $index => $entry) {
|
|
$userId=$entry[0];
|
|
$rankInfo[$userId]=$totalRanking[$index][4];
|
|
}
|
|
|
|
$cols=array();
|
|
$cols[1]="greenyellow";
|
|
$cols[2]="orange";
|
|
$cols[3]="lightgrey";
|
|
$cols[4]="";
|
|
|
|
$leagueScores=array();
|
|
foreach([1,2,3,4] as $rank) {
|
|
$leagueScores[$rank] = League::getRanking($rank);
|
|
}
|
|
|
|
Log::info($a->getEndMessage());
|
|
//error_log($a->getEndMessage());
|
|
|
|
return view ('leagues.chart_swapform',compact('season', 'leagueNames', 'userNames','leagueScores','rankInfo','rank','cols'));
|
|
}
|
|
|
|
|
|
public static function showSingleUserMatches($userId) {
|
|
$season = Season::getCurrent();
|
|
$leagueNames = League::getNames();
|
|
$roundNames = Round::getNames();
|
|
$matches = Match::getMatchResultsForUser($userId);
|
|
|
|
$user = User::where('id','=', $userId)->first();
|
|
$userName = $user->name;
|
|
return view ('leagues.playermatches',compact('season','leagueNames','roundNames','matches','userName'));
|
|
}
|
|
|
|
} |