This commit is contained in:
Torsten 2017-10-25 10:42:05 +02:00
parent ed0c445bfa
commit 30f6157606
15 changed files with 248 additions and 169 deletions

View file

@ -65,114 +65,9 @@ class LeaguesController extends Controller
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, $league_mode) {
$currentSeason=Season::getCurrent();
// Eventuell vorhandene Ligen loeschen
$leagues=League::where('season_id','=',$currentSeason->id)->get();
if ($leagues) {
foreach ($leagues as $league) {
DB::table('leagues_matches')->where('league_id', '=', $league->id)->delete();
DB::table('leagues_members')->where('league_id', '=', $league->id)->delete();
DB::table('leagues')->where('id', '=', $league->id)->delete();
}
}
$active_member_count=sizeof(User::getActives());
Log::info("Aktive Spieler: ".$active_member_count);
$neededLeagues = League::neededLeagues($active_member_count, $round_count);
Log::info("Benötigte Quali-Gruppen: ".$neededLeagues);
$league_ids=array();
Log::info("League Mode:".$league_mode);
if ($league_mode=="Qualifikation") {
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
$league = League::create([
'is_qualification' => true,
'name' => 'Qualifikationsgruppe '.$league_nr,
'rank' => '4',
'subrank' => $league_nr,
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league->save();
$league_ids[$league_nr-1] = $league->id;
}
// Distribute members
$users = User::getActives();
shuffle($users);
$league_index=0;
Log::info("Distributing Members between groups");
while(sizeof($users)>0) {
$user = array_pop($users);
$leagueMember = LeagueMember::create([
'user_id' => $user->id,
'league_id' => $league_ids[$league_index]
]);
$leagueMember->save();
$league_index+=1;
if (sizeof($league_ids)==$league_index) { $league_index=0; }
}
} else {
// ToDo: Branch Qualifikation/Liga entfällt in Zukunft, da Quali der Fallback für den Fall ist, dass keine vorherige Saison existiert.
// Pokal und Play-Off findet hier nicht statt, da diese Wettbewerbe die Matches abgängig von existierenden Vorrunden-Ergebnissen erzeugen,
// und daher zwangsläufig inkrementell sein müssen.
$league_size1= min(22,$active_member_count);
$league1 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 1',
'rank' => '1',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league_size2=min(22,$active_member_count - $league_size1);
if ($league_size2>0) {
$league2 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 2',
'rank' => '2',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league_size3 = $active_member_count - $league_size1 - $league_size2;
if ($league_size3>0) {
$neededLeagues = League::neededLeagues($league_size3, $round_count);
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
$league = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 3, Gruppe '.$league_nr,
'rank' => '3',
'subrank' => $league_nr,
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league->save();
}
}
// TODO: LeagueMembers zu den Leagues hinzufügen, abhängig vom zuzuordnenden Platz
}
}
public function createLeagues($start_round_id, $round_count) {
League::createLeagues($start_round_id, $round_count);
Match::createMatchups();
return redirect("/seasons");

View file

@ -18,24 +18,17 @@ class SeasonsController extends Controller
{
public function index() {
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$seasons = DB::table('seasons')->get();
$currentSeason=Season::getCurrent();
$quotas = Quota::getQuotas($currentSeason->id);
if (!$quotas) {
Quota::createDefaultQuota($currentSeason->id);
$quotas = Quota::getQuotas($currentSeason->id);
}
$active_user_count = sizeof( User::getActives() );
$quotas = Quota::getQuotas($currentSeason->id);
$payouts = Quota::getPayouts($currentSeason->id);
$currentSeasonId=-1;
if ($currentSeason) {
$quotas = Quota::getQuotas($currentSeason->id);
$payouts = Quota::getPayouts($currentSeason->id);
}
return view('seasons.index', compact('seasons','currentSeason','active_user_count','quotas','payouts'));
}

View file

@ -52,8 +52,10 @@ class UsersController extends Controller
$nextRoundName="";
$nextRound = Round::getFirstTippableRound();
$nextRoundName = "";
$nextRoundLockTime = "";
$diffToLock ="";
$hourDiffToLock = 999;
if ($nextRound) {
$nextRoundName = $nextRound->name;
$nextRoundLockTime = $nextRound->getLockTime();
@ -98,6 +100,7 @@ class UsersController extends Controller
$activeUsers = User::getActives();
$currentSeason=Season::getCurrent();
if (!$currentSeason) { return redirect('/'); }
$active_user_count = sizeof( $activeUsers );
$total_user_count = sizeof( DB::table('payments')->where('season_id',$currentSeason->id)->get() );
@ -121,8 +124,6 @@ class UsersController extends Controller
}
}
return view('users.index', compact('users','active_user_count','total_user_count'));
}
/*
@ -201,8 +202,7 @@ class UsersController extends Controller
if($max_round_id==-1) {
$max_round_id = Round::getLastLockedRoundId();
if ($max_round_id==-1) {
$sql="select DATE_FORMAT(date_sub(min(games.kickoff), interval 1 hour),'%d.%m.%Y %H:%i') as start_date from rounds,games where rounds.season_id=".$season->id." and games.round_id=rounds.id;";
dd($sql);
$sql="select DATE_FORMAT(date_sub(min(games.kickoff), interval 1 hour),'%d.%m.%Y %H:%i') as start_date from rounds,games where rounds.season_id=".$seasonId." and games.round_id=rounds.id;";
$date = DB::select($sql);
if (count($date)>0) {

View file

@ -59,8 +59,10 @@ class Round extends Model
}
public static function getFirstIncompleteRound() {
$season_id = Season::getCurrent()->id;
$rounds = Round::where('season_id','=',$season_id)->orderBy('id')->get();
$season = Season::getCurrent();
if (!$season) return -1;
$rounds = Round::where('season_id','=',$season->id)->orderBy('id')->get();
foreach($rounds as $round) {
if (!Round::isCompleted($round->id)) return $round->id;
}
@ -69,6 +71,8 @@ class Round extends Model
public static function getNextRoundId($roundId) {
$currentSeason = Season::getCurrent();
if (!$currentSeason) return -1;
$rounds = Round::where('season_id','=',$currentSeason->id)->where('id','>=',$roundId)->get();
foreach($rounds as $round) {
if ($round->id == $roundId) { continue; }
@ -79,6 +83,7 @@ class Round extends Model
public static function getLastLockedRoundId() {
$season = Season::getCurrent();
if (!$season) return -1;
$rounds=Round::where('season_id','=',$season->id)->orderBy('id')->get();
$lastLockedRoundId=-1;
foreach ($rounds as $round) {
@ -89,8 +94,15 @@ class Round extends Model
return $lastLockedRoundId;
}
public static function getFirstTippableRoundId() {
$round = Round::getFirstTippableRound();
if (!$round) return -1;
return $round->id;
}
public static function getFirstTippableRound() {
$season = Season::getCurrent();
if (!$season) return null;
$rounds=Round::where('season_id','=',$season->id)->orderBy('id')->get();
$locked = false;
foreach ($rounds as $round) {

View file

@ -272,7 +272,7 @@ class Tipp extends Model
$round_ids=array();
// Write sql result to roundtipps (score per round & user)
if ($max_round_id==-1) { $max_round_id=Round::getLastLockedRoundId(); }
if ($max_round_id==-1) { $max_round_id=Round::getLastCompleteRoundId(); }
foreach ($result as $entry) {
$round_id = $entry->round_id;
if ($max_round_id >-1 && $round_id>$max_round_id) break;

View file

@ -180,9 +180,10 @@ class User extends Authenticatable
// aktiv = hat die Saison bezahlt.
public static function getActives($seasonId=-1) {
$currentSeason=Season::getCurrent();
if ($seasonId != -1) { $currentSeason = Season::where('id','=',$seasonId); }
if (!$currentSeason) return array();
$users = User::all();
$payments = Payment::where('season_id','=',$currentSeason->id)->get();

View file

@ -62,11 +62,33 @@ class League extends Model
}
public static function cmpScore($score1, $score2) {
return ($score1[1] < $score2[1]);
// [0] = user-id
$_score1 = $score1[1];
$goals1 = $score1[2];
$cGoals1 = $score1[3];
$_score2 = $score2[1];
$goals2 = $score2[2];
$cGoals2 = $score2[3];
$diff1 = $goals1-$cGoals1;
$diff2 = $goals2-$cGoals2;
if ($_score1 == $_score2) {
if ($diff1==$diff2) {
if ($goals1 == $goals2) {
return $cGoals1 > $cGoals2;
}
return ( $goals1 < $goals2 );
}
return ($diff1<$diff2);
}
return ($_score1 < $_score2);
}
public static function getRanking($rank, $seasonId=-1) {
$season = Season::getCurrent();
if ($seasonId > -1) { $season=Season::where('id','=',$seasonId)->first(); };
@ -122,21 +144,155 @@ class League extends Model
return $unifiedScores;
}
// ausfaktoriert aus LeaguesController::createLeagues()
// TODO: $round_count ist nur im Quali-Modus relevant und steuert, wieviele Quali-Gruppen benötigt werden.
// TODO: Sobald es Liga1 und Liga2 gibt, wird der round_count immer 21 sein, da Liga1 und Liga2 auf
// TODO: 22 Mitspieler festgelegt sind.
public static function createLeagues($start_round_id, $round_count) {
$currentSeason=Season::getCurrent();
// Eventuell vorhandene Ligen loeschen
$leagues=League::where('season_id','=',$currentSeason->id)->get();
if ($leagues) {
foreach ($leagues as $league) {
DB::table('leagues_matches')->where('league_id', '=', $league->id)->delete();
DB::table('leagues_members')->where('league_id', '=', $league->id)->delete();
DB::table('leagues')->where('id', '=', $league->id)->delete();
}
}
$active_member_count=sizeof(User::getActives());
Log::info("Aktive Spieler: ".$active_member_count);
$neededLeagues = League::neededLeagues($active_member_count, $round_count);
Log::info("Benötigte Quali-Gruppen: ".$neededLeagues);
$league_ids=array();
//TODO: Den Leaguemode kann die Methode selbst rausfinden.
//TODO: Wenn es keine Vorsaison gibt -> Qualifikation
//TODO: Ansonsten: Ligen erzeugen.
$league_mode="Qualifikation";
if ($league_mode=="Qualifikation") {
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
$league = League::create([
'is_qualification' => true,
'name' => 'Qualifikationsgruppe '.$league_nr,
'rank' => '4',
'subrank' => $league_nr,
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league->save();
$league_ids[$league_nr-1] = $league->id;
}
// Distribute members
$users = User::getActives();
shuffle($users);
$league_index=0;
Log::info("Distributing Members between groups");
while(sizeof($users)>0) {
$user = array_pop($users);
$leagueMember = LeagueMember::create([
'user_id' => $user->id,
'league_id' => $league_ids[$league_index]
]);
$leagueMember->save();
$league_index+=1;
if (sizeof($league_ids)==$league_index) { $league_index=0; }
}
} else {
// ToDo: Branch Qualifikation/Liga entfällt in Zukunft, da Quali der Fallback für den Fall ist, dass keine vorherige Saison existiert.
// Pokal und Play-Off findet hier nicht statt, da diese Wettbewerbe die Matches abgängig von existierenden Vorrunden-Ergebnissen erzeugen,
// und daher zwangsläufig inkrementell sein müssen.
$league_size1= min(22,$active_member_count);
$league1 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 1',
'rank' => '1',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league_size2=min(22,$active_member_count - $league_size1);
if ($league_size2>0) {
$league2 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 2',
'rank' => '2',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league_size3 = $active_member_count - $league_size1 - $league_size2;
if ($league_size3>0) {
$neededLeagues = League::neededLeagues($league_size3, $round_count);
for ($league_nr=1; $league_nr<=$neededLeagues; $league_nr+=1) {
$league = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 3, Gruppe '.$league_nr,
'rank' => '3',
'subrank' => $league_nr,
'round_count' => $round_count,
'season_id' => $currentSeason->id,
'start_round_id' => $start_round_id
]);
$league->save();
}
}
// TODO: LeagueMembers zu den Leagues hinzufügen, abhängig vom zuzuordnenden Platz
}
}
}
// Aktuelle Liga-Zuordnung auf Basis des Rangs in der letzten Liga
// Oder des Rangs in der Qualifikation
// oder erstellung des Quali Rangs wenn es keine previous Season gibt.
// Liga-Zugehörigkeit festlegen. Setzt voraus, dass die Ligen bereits erzeugt wurden.
public static function setLeagueForPlayers()
/*
* setLeagueForPlayers__NEW_QUALIFICATION case1
* setLeagueForPlayers__FROM_QUALIFICATION case2
* setLeagueForPlayers__FROM_LEAGUES case3
*/
{
$previousSeason = Season::getPrevious();
$currentSeason = Season::getCurrent();
$users = User::getActives();
if (!$previousSeason) {
dd("No last season handling implemented. Please fix/implement.");
//TODO: Implement a qualification round
return;
// case 1: first season ever, no previous season exists, qualification (league-rank=4)
} elseif (Season::hasQualification($previousSeason->id)){
// case 2: previous season was qualification season (rank 4)
} else { /*case 3 - default: determine league-ranks 1,2,3 from previous Season rank verwenden*/
}
$users = User::getActives();
// 2 Möglichkeiten:
// 1.) previousSeason hat rank=4 => Qualification Round
// 2.) sonst aus .
$usersLastSeason = User::getActives($previousSeason->id);
$league1 = League::getUnifiedRanking(1, $previousSeason->id);
@ -144,7 +300,14 @@ class League extends Model
$league3 = League::getUnifiedRanking( 3, $previousSeason->id);
//$lastLeagues = League::where('season_id','=',$previousSeason->id)->get();
foreach ($users as $key => $user) {
/*
foreach ($users as $index => $user) {
$found = false;
foreach ($usersLastSeason as $userLastSeason) {
@ -152,7 +315,12 @@ class League extends Model
}
if (!$found) {
$users[$key]['rank']=League::RANK_LEAGUE3; // In der letzten Season unter den Actives nicht gefunden
$users[$index]['rank']=League::RANK_LEAGUE3; // In der letzten Season unter den Actives nicht gefunden
$leagueMember = LeagueMember::create([
'user_id' => $user->id,
'league_id' => $league3->id
]);
$leagueMember->save();
} else {
// League1, 1-16: RANK_LEAGUE1
@ -163,6 +331,8 @@ class League extends Model
// League3, best6: RANK_LEAGUE2
// League3, 7-end: RANK_LEAGUE3
//
//alte Ligen durchsuchen und entsprechend einordnen
foreach($league1 as $index => $entry) {
$userId = $entry[0];
$score = $entry[1];
@ -238,5 +408,7 @@ class League extends Model
}
}
*/
}
}

View file

@ -23,7 +23,11 @@ class Match extends Model
// https://en.wikipedia.org/wiki/Round-robin_tournament
public static function createMatchups()
{ Log::info("Match::Creating matchups()");
{ // should be restricted to league ranks 1,2,3 and 4. All other leagues will have to use some
// incremental matchmaking system.
Log::info("Match::Creating matchups()");
$currentSeason = Season::getCurrent();
$leagues = League::where('season_id', '=', $currentSeason->id)->get();
foreach ($leagues as $league) {

View file

@ -17,7 +17,7 @@
</label>
@endif
&nbsp;
<a style="font-color: blue; font-size: 22px;" href="/tipps#{{\App\Round::getFirstTippableRound()->id}}">Tipps</a> &nbsp;
<a style="font-color: blue; font-size: 22px;" href="/tipps#{{\App\Round::getFirstTippableRoundId()}}">Tipps</a> &nbsp;
&nbsp;
<a style="font-color: blue; font-size: 22px;" href="/users/ranking/roundid_-1#playerid_{{Auth::user()->id}}" >Rangliste</a> &nbsp;
@ -25,10 +25,9 @@
<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> &nbsp;
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league/show/rank=4/max_round_id=-1">Tabellen</a> &nbsp;
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/league/show/rank=4/max_round_id=-1#user_{{Auth::user()->id}}">Tabellen</a> &nbsp;
</div>
</label>
&nbsp;
<label class="dropdown" id="dropdown3">
<a href="#" id="btn_info" onclick="toggleSelect('dropdown_info'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">Info</a>

View file

@ -11,16 +11,20 @@
<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: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 $player)
@foreach($playerTuples as $pos => $player)
<tr class="table-bordered">
<td>&nbsp; {{$pos+1}}&nbsp;</td>
<td>&nbsp;<a name="user_{{$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;<a href="/league/showSingleUserMatches/user_id={{$player[0]}}"> {{$userNames[$player[0]]}} </a>&nbsp;</td>
<td>&nbsp; {{$player[2]-$player[3]}} &nbsp;</td>
<td>&nbsp; {{$player[2]}}:{{$player[3]}} &nbsp;</td>
</tr>
@endforeach

View file

@ -60,7 +60,7 @@
//alert($global_selected_round_id);
var round_count=document.getElementById("input_round_count").value;
var link = '/league_settings/create_league/start_round_id='+global_start_round_id+"/round_count="+round_count+"/league_mode="+global_league_mode;
var link = '/league_settings/create_league/start_round_id='+global_start_round_id+"/round_count="+round_count;
//alert(link);
window.location=link;
}

View file

@ -6,6 +6,7 @@
<span class="col-md-2"></span>
<span class="text-center col-md-8">
@if(Auth::check())
@if($hourDiffToLock<49)
@if (strlen($message_text_tipps)>0)
<div><p class="blink_text" style="font-size:21px;">{{ $message_text_tipps }}</p></div>
@ -17,17 +18,18 @@
<div><p class="blink_text" style="font-size:21px;">{{ $nextRoundName }} sperrt sich: {{ $nextRoundLockTime }} ( noch {{ $hourDiffToLock }} )</p></div>
@endif
@endif
@endif
<h1 class="jumbotron-heading">Hoschis Tippspiel</h1>
<p class="lead text-muted">Eine Tippgemeinschaft unter Freunden.</p>
<div><p></p><p></p><p></p></div>
@if (!Auth::check())
<div>
<div>
<a href="/login" class="btn btn-primary">Anmelden</a>
</div>
<p>&nbsp;</p>
<div>
<p>&nbsp;</p>
<div>
<a href="/register" class="btn btn-primary">Registrieren</a>
</div>
@ -35,14 +37,16 @@
</span>
</section>
@if (Auth::check())
@foreach($display_rounds as $round)
<div class="container-fluid col-md-12">
<span class="col-md-2"></span>
<span class="text-center col-md-8">
<h2>&nbsp;{{ $round['name'] }}</h2>
<div style="font-size: 18px;">&nbsp;{!! $round['report'] !!}</div>
</span>
</div>
@endforeach
@if ($display_rounds)
@foreach($display_rounds as $round)
<div class="container-fluid col-md-12">
<span class="col-md-2"></span>
<span class="text-center col-md-8">
<h2>&nbsp;{{ $round['name'] }}</h2>
<div style="font-size: 18px;">&nbsp;{!! $round['report'] !!}</div>
</span>
</div>
@endforeach
@endif
@endif
@endsection

View file

@ -5,11 +5,12 @@
<div class="container">
<label>{{ $activeSeason->name }}</label>
@if (sizeof($rounds)<$round_count)
<!--
if (sizeof($rounds)<$round_count)
<div><a href="/rounds/create" class="btn btn-primary" >Runde hinzufügen</a></div>
<p>&nbsp;</p>
@endif
endif
-->
</div>
<div class="container">
@ -40,10 +41,8 @@
<div class="container-fluid" style="width:800px;">
<p>&nbsp;</p>
<p>Berichterstattung</p>
<form method="POST" action="/rounds/store_report" class="text-center">
{{ csrf_field() }}

View file

@ -17,15 +17,11 @@
@endforeach
</ul>
</div>
@endif
@if ($currentSeason)
<div>
<form method="POST" action="/seasons/store_quota">
{{ csrf_field() }}
<h3>Anzahl Runden</h3>

View file

@ -75,7 +75,7 @@ Route::get('/users/send_reset_links_from_settings','UsersController@send_reset_l
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_settings/create_league/start_round_id={start_round_id}/round_count={round_count}','Leagues\LeaguesController@createLeagues');
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');