Show player matches for single userId
This commit is contained in:
parent
93d7670b48
commit
98ebdb6c93
7 changed files with 163 additions and 9 deletions
|
|
@ -198,11 +198,31 @@ class LeaguesController extends Controller
|
|||
$matchesTotal[$match->round_id][$league->id] = $lg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return view ('leagues.matches', compact('season', 'matchesTotal','leagues','leagueNames','roundNames'));
|
||||
}
|
||||
|
||||
public static function showLeagueRanking($rank, $maxRoundId=-1) {
|
||||
$season = Season::getCurrent();
|
||||
$leagues = array_reverse(League::getRanking($rank));
|
||||
$leagueNames = League::getNames();
|
||||
$userNames = User::getNames();
|
||||
|
||||
$leagueScores = League::getRanking($rank);
|
||||
return view ('leagues.chart',compact('season','leagues', 'leagueNames', 'userNames','leagueScores'));
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Leagues;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Season;
|
||||
use App\Round;
|
||||
|
||||
use DB;
|
||||
use Log;
|
||||
|
|
@ -59,4 +60,48 @@ class League extends Model
|
|||
return $league->start_round_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function cmpScore($score1, $score2) {
|
||||
return ($score1[1] < $score2[1]);
|
||||
}
|
||||
|
||||
public static function getRanking($rank) {
|
||||
$season = Season::getCurrent();
|
||||
$leagues = League::where('rank','=',$rank)->where('season_id','=', $season->id)->orderBy('id')->get();
|
||||
|
||||
error_log("LeagueCount:".sizeof($leagues));
|
||||
|
||||
$leagueScores=array();
|
||||
foreach($leagues as $league) {
|
||||
$memberIds = LeagueMember::getMembers($league->id);
|
||||
|
||||
$memberScores =array();
|
||||
foreach($memberIds as $memberId) {
|
||||
$tpl=array();
|
||||
$tpl[0]=$memberId;
|
||||
$tpl[1]=0;
|
||||
$tpl[2]=0; // goals
|
||||
$tpl[3]=0; // countergoals
|
||||
$memberScores[$memberId] = $tpl;
|
||||
}
|
||||
|
||||
$matches=Match::getMatchResults($league->id,-1);
|
||||
foreach ($matches as $match) {
|
||||
if (!Round::isCompleted($match->round_id)) { continue; }
|
||||
$memberScores[$match->user1_id][1] += $match->user1_league_score;
|
||||
$memberScores[$match->user1_id][2] += $match->user1_rankscore;
|
||||
$memberScores[$match->user1_id][3] += $match->user2_rankscore;
|
||||
$memberScores[$match->user2_id][1] += $match->user2_league_score;
|
||||
$memberScores[$match->user2_id][2] += $match->user2_rankscore;
|
||||
$memberScores[$match->user2_id][3] += $match->user1_rankscore;
|
||||
}
|
||||
usort($memberScores, array('App\Leagues\League','cmpScore'));
|
||||
|
||||
$leagueScores[$league->id]=$memberScores;
|
||||
|
||||
}
|
||||
return $leagueScores;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,13 +155,9 @@ class Match extends Model
|
|||
public static function getMatchResults($leagueId, $maxRoundId=-1) {
|
||||
$roundtipps = Tipp::getRoundTipps($maxRoundId);
|
||||
$roundtipps = $roundtipps["roundtipps"];
|
||||
$startRoundId = League::getStartRoundId($leagueId);
|
||||
$matches = Match::getLeagueMatches($leagueId, $maxRoundId);
|
||||
|
||||
if ($maxRoundId==-1) {$maxRoundId=Round::getLastLockedRoundId();}
|
||||
|
||||
$matchResults=array();
|
||||
$members = LeagueMember::getMembers($leagueId);
|
||||
if ($maxRoundId==-1) {$maxRoundId=Round::getLastCompleteRoundId();}
|
||||
|
||||
foreach($matches as $key => $match) {
|
||||
if (!Round::isCompleted($match->round_id)) continue;
|
||||
|
|
@ -175,9 +171,12 @@ class Match extends Model
|
|||
$matches[$key]->user1_rankscore = $user1_score;
|
||||
$matches[$key]->user2_rankscore = $user2_score;
|
||||
|
||||
//$matches[$key]->user1_hits = $roundtipps[$user1_key][]
|
||||
|
||||
if ($user1_score > $user2_score) {
|
||||
$matches[$key]->user1_league_score = 3;
|
||||
$matches[$key]->user2_league_score = 0;
|
||||
|
||||
}
|
||||
else if ($user1_score < $user2_score){
|
||||
$matches[$key]->user1_league_score = 0;
|
||||
|
|
@ -187,8 +186,31 @@ class Match extends Model
|
|||
$matches[$key]->user2_league_score = 1;
|
||||
}
|
||||
|
||||
// error_log($match->user1_id." vs ".$match->user2_id. " =>" . $user1_score.":".$user2_score);
|
||||
}
|
||||
return $matches;
|
||||
}
|
||||
|
||||
public static function getMatchResultsForUser($userId, $maxRoundId=-1) {
|
||||
$season = Season::getCurrent();
|
||||
$leagues = League::where('season_id','=',$season->id)->get();
|
||||
|
||||
$matchList=array();
|
||||
|
||||
foreach($leagues as $league) {
|
||||
$member=LeagueMember::where('league_id','=',$league->id)->where('user_id','=',$userId)->first();
|
||||
if ($member) {
|
||||
// $userId ist member dieser League
|
||||
$matchResults = Match::getMatchResults($league->id,$maxRoundId);
|
||||
foreach($matchResults as $result) {
|
||||
if ($result->user1_id == $userId || $result->user2_id==$userId) {
|
||||
array_push($matchList, $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $matchList;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
<a href="#" id="btn_league" onclick="toggleSelect('dropdown_league'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">Spieler-Liga</a>
|
||||
<div id="dropdown_league" class="dropdown-content">
|
||||
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league_show_rounds/league_rank=4/round_id=30">Spielplan</a>
|
||||
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="#">Tabellen</a>
|
||||
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league/show/rank=4/max_round_id=-1">Tabellen</a>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
|
|
|
|||
34
pfosten/resources/views/leagues/chart.blade.php
Executable file
34
pfosten/resources/views/leagues/chart.blade.php
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
@extends('layouts.layout')
|
||||
|
||||
@section('content')
|
||||
<section class="text-center">
|
||||
<div class="container">
|
||||
|
||||
<h2>{{ $season->name }}</h2>
|
||||
|
||||
@foreach($leagueScores as $leagueId => $playerTuples)
|
||||
<h2>{{ $leagueNames[$leagueId] }}</h2>
|
||||
|
||||
<table class="table-bordered col-lg-12">
|
||||
<tr class="table-bordered">
|
||||
<td class="table-bordered" style="width:50px;">Punkte</td>
|
||||
<td class="table-bordered" style="width:150px;">Spieler</td>
|
||||
<td class="table-bordered" style="width:150px;">Torverhältnis</td>
|
||||
</tr>
|
||||
|
||||
<!-- Start Matchgruppen-Loop-->
|
||||
@foreach($playerTuples as $player)
|
||||
<tr class="table-bordered">
|
||||
<td> {{$player[1]}} </td>
|
||||
<td> <a href="/league/showSingleUserMatches/user_id={{$player[0]}}"> {{$userNames[$player[0]]}} </a> </td>
|
||||
<td> {{$player[2]}}:{{$player[3]}} </td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
</table>
|
||||
<p> </p>
|
||||
|
||||
@endforeach
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
30
pfosten/resources/views/leagues/playermatches.blade.php
Executable file
30
pfosten/resources/views/leagues/playermatches.blade.php
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
@extends('layouts.layout')
|
||||
|
||||
@section('content')
|
||||
<section class="text-center">
|
||||
<div class="container">
|
||||
|
||||
<h2>{{ $userName }}</h2>
|
||||
|
||||
<table class="table-bordered col-lg-12">
|
||||
<tr class="table-bordered">
|
||||
<td class="table-bordered" style="width:50px;">Liga / Gruppe</td>
|
||||
<td class="table-bordered" style="width:150px;">Runde</td>
|
||||
<td class="table-bordered" style="width:150px;">Spieler 1</td>
|
||||
<td class="table-bordered" style="width:150px;">Spieler 2</td>
|
||||
</tr>
|
||||
|
||||
@foreach($matches as $match)
|
||||
|
||||
<tr class="table-bordered">
|
||||
<td class="table-bordered" style="width:50px;">{{$leagueNames[$match->league_id]}}</td>
|
||||
<td class="table-bordered" style="width:150px;">{{$roundNames[$match->round_id]}}</td>
|
||||
<td class="table-bordered" style="width:150px;">{{$match->user1_name}}</td>
|
||||
<td class="table-bordered" style="width:150px;">{{$match->user2_name}}</td>
|
||||
</tr>
|
||||
|
||||
@endforeach
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
@endsection
|
||||
|
|
@ -76,4 +76,7 @@ Route::get('/home', 'UsersController@main')->name('home');
|
|||
|
||||
Route::get('/league_settings/season={season_id}','Leagues\LeaguesController@index');
|
||||
Route::get('/league_settings/create_league/start_round_id={start_round_id}/round_count={round_count}/league_mode={league_mode}','Leagues\LeaguesController@createLeagues');
|
||||
Route::get('/league_show_rounds/league_rank={league_rank}/round_id={round_id}','Leagues\LeaguesController@showLeagueRounds');
|
||||
Route::get('/league_show_rounds/league_rank={league_rank}/round_id={round_id}','Leagues\LeaguesController@showLeagueRounds');
|
||||
Route::get('/league/show/rank={rank}/max_round_id={maxRoundId}','Leagues\LeaguesController@showLeagueRanking');
|
||||
|
||||
Route::get('/league/showSingleUserMatches/user_id={userId}','Leagues\LeaguesController@showSingleUserMatches');
|
||||
Loading…
Add table
Add a link
Reference in a new issue