Working on LeagueMemberSwap Form

This commit is contained in:
Torsten 2022-06-03 11:58:26 +02:00
parent 2f26ee76d4
commit 3ec04c090d
4 changed files with 613 additions and 0 deletions

View file

@ -125,6 +125,8 @@ class LeaguesController extends Controller
return view ('leagues.matches', compact('season', 'matchesTotal','leagues','leagueNames','roundNames'));
}
public static function showLeagueRanking() {
$a=new TimeLogger("LeaguesController::showLeagueRanking()");
@ -166,6 +168,49 @@ class LeaguesController extends Controller
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();

View file

@ -0,0 +1,97 @@
@extends('layouts.layout')
@section('content')
<section class="text-center">
<div id="leagueContainer" class="container">
<h2>{{ $season->name }}</h2>
<h2>Spielerliga Platztausch</h2>
<table>
<tr>
<td style="width:50px;background-color:{{$cols[1]}}"></td>
<td style="width:250px;"> = Qualifikationsplatz Liga 1</td>
</tr>
<tr>
<td style="width:50px;background-color:{{$cols[2]}}"></td>
<td style="width:250px;"> = Qualifikationsplatz Liga 2</td>
</tr>
<tr>
<td style="width:50px;background-color:{{$cols[3]}}"></td>
<td style="width:250px;"> = Qualifikationsplatz Liga 3</td>
</tr>
</table>
@foreach($leagueScores as $rank => $_leagueScores)
@foreach($_leagueScores as $leagueId => $playerTuples)
<h2>{{ $leagueNames[$leagueId] }}</h2>
<table class="table-bordered col-lg-12">
<tr class="table-bordered">
<td>Tausch</td>
<td class="table-bordered" style="width:50px;">Pos</td>
<td class="table-bordered" style="width:150px;">Spieler</td>
<td class="table-bordered" style="width:50px;">Punkte</td>
<td class="table-bordered" style="width:150px;">Tordifferenz</td>
<td class="table-bordered" style="width:150px;">Torverhältnis</td>
</tr>
<!-- Start Matchgruppen-Loop-->
@foreach($playerTuples as $pos => $player)
<tr class="table-bordered">
<td><input id="{{$player[0]}}__{{$userNames[$player[0]]}}__{{$leagueNames[$leagueId]}}" type="checkbox"></td>
<td style="width:50px;background-color:{{ $cols[$rankInfo[$player[0]]] }}">&nbsp; {{$pos+1}}&nbsp;</td>
<td>&nbsp;<a name="playerid_{{$player[0]}}" class="{{ $player[0]==Auth::user()->id ? 'blink_text' : '' }}" href="/league/showSingleUserMatches/user_id={{$player[0]}}"> {{$userNames[$player[0]]}} </a>&nbsp;</td>
<td>&nbsp; {{$player[1]}} &nbsp;</td>
<td>&nbsp; {{$player[2]-$player[3]}} &nbsp;</td>
<td>&nbsp; {{$player[2]}}:{{$player[3]}} &nbsp;</td>
</tr>
@endforeach
</table>
<p>&nbsp;</p>
@endforeach
@endforeach
</div>
</section>
<script>
const checkbox = document.getElementById('leagueContainer')
checkbox.addEventListener('change', (event) => {
let delta =0
if (event.currentTarget.checked) {
// Is going to be unchecked
delta=-1
} else {
// Is going to be checked
delta=+1
}
// count checked boxes
let inputElems = document.getElementsByTagName("input"), count = 0;
for (let i=0; i<inputElems.length; i++) {
if (inputElems[i].type === "checkbox" && inputElems[i].checked === true) {
count++;
}
}
if (count==2) {
let selected_players=[];
for (let i=0; i<inputElems.length; i++) {
if (inputElems[i].type === "checkbox" && inputElems[i].checked === true) {
selected_players.push(inputElems[i].id)
inputElems[i].checked=false;
}
}
alert("Tauschen:\n"+selected_players.join("\n"));
}
})
</script>
@endsection

View file

@ -91,5 +91,7 @@ Route::get('/league_settings/season={season_id}','Leagues\LeaguesController@inde
Route::get('/league_settings/create_league/start_round_id={start_round_id}/round_count={round_count}','Leagues\LeaguesController@createLeagues');
Route::get('/league_show_rounds','Leagues\LeaguesController@showLeagueRounds');
Route::get('/league/show','Leagues\LeaguesController@showLeagueRanking');
Route::get('/league/swapform','Leagues\LeaguesController@showLeagueSwapForm');
Route::post('/league/swap','Leagues\LeaguesController@swapLeagueMembers');
Route::get('/league/showSingleUserMatches/user_id={userId}','Leagues\LeaguesController@showSingleUserMatches');