Working on Qualification Pairings

This commit is contained in:
Torsten 2017-09-22 17:40:48 +02:00
parent 9c0f94758d
commit a66189ca00
19 changed files with 9005 additions and 237 deletions

8497
d0274241_2017-09-20_1000.sql Normal file

File diff suppressed because it is too large Load diff

View file

@ -13,24 +13,27 @@ use App\Season;
use App\Round;
use App\User;
use App\leagues\League;
use App\leagues\LeagueMember;
use App\Leagues\League;
use App\Leagues\LeagueMember;
use App\Leagues\Match;
use Log;
use DB;
class LeagueController extends Controller
class LeaguesController extends Controller
{
public function index($season_id) {
public function index() {
$season=Season::getCurrent();
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }
$season = Season::where('id','=',$season_id)->first();
$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();
$rounds = Round::where('season_id','=',$season->id)->orderBy('id')->get();
if (!$rounds) return redirect("/seasons");
$round_count = 18;
@ -38,9 +41,9 @@ class LeagueController extends Controller
$start_round_id=$rounds[0]->id;
$league_mode="Einstellen";
$league = League::where('season_id','=',$season_id)->first();
$league = League::where('season_id','=',$season->id)->first();
if ($league) {
$startround = Round::where('season_id', '=', $season_id)->orderBy('id')->first();
$startround = Round::where('season_id', '=', $season->id)->orderBy('id')->first();
$start_round_id = $startround->id;
$startRound = Round::where('id','=',$league->start_round_id)->first();
@ -75,13 +78,13 @@ class LeagueController extends Controller
}
}
$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([
@ -101,6 +104,7 @@ class LeagueController extends Controller
$users = User::getActives();
shuffle($users);
$league_index=0;
Log::info("Distributing Members between groups");
while(sizeof($users)>0) {
$user = array_pop($users);
@ -115,7 +119,6 @@ class LeagueController extends Controller
}
} else {
// ToDo: Achtel-, Viertel-, Halb-, Finale require additional leagues; Same with Pokal, so createMissingLeagues method will be needed in the future
$league_size1= min(22,$active_member_count);
@ -134,8 +137,8 @@ class LeagueController extends Controller
if ($league_size2>0) {
$league2 = League::create([
'is_qualification' => false,
'name' => 'Spielerliga 1',
'rank' => '1',
'name' => 'Spielerliga 2',
'rank' => '2',
'subrank' => '1',
'round_count' => $round_count,
'season_id' => $currentSeason->id,
@ -163,6 +166,37 @@ class LeagueController extends Controller
}
}
Match::createMissingMatchups();
return redirect("/seasons");
}
public function showLeagueRounds($league_rank, $round_id) { // $round_id = $max_round_id
if (Auth::guest()) { return redirect("/"); }
$season=Season::getCurrent();
$roundNames = Round::getNames();
$leagueNames = League::getNames();
$leagues = League::where('season_id','=',$season->id)->where('rank','=', $league_rank)->get();
$matchesTotal = array();
foreach ($leagues as $league) {
$matches = Match::getLeagueMatches($league->id);
foreach ($matches as $match) {
if ($match->round_id <= $round_id) {
if (!key_exists($match->round_id, $matchesTotal)) {
$matchesTotal[$match->round_id]=array();
}
$lg = $matchesTotal[$match->round_id];
array_push($lg, $match);
$matchesTotal[$match->round_id] = $lg;
}
}
}
return view ('leagues.matches', compact('season', 'matchesTotal','leagues','leagueNames','roundNames'));
}
}

View file

@ -119,7 +119,7 @@ class TippsController extends Controller
// Joker gesetzt ? Dann Jokerflag für alle Tipps der selben Runde entfernen
if ($tipp->joker){
Log::info("Checking for joker strip");
//Log::info("Checking for joker strip");
$game=Game::where('id','=',$tipp->game_id)->first();
$round_id=$game->round_id;
@ -127,12 +127,13 @@ class TippsController extends Controller
foreach ($games as $game) {
$tipp = Tipp::where('user_id', $user->id)->where('game_id', $game->id)->first();
Log::info("Testing game_id " . $game->id);
//Log::info("Testing game_id " . $game->id);
if ($tipp->id != request('id')) {
Log::info("Resetting game_id " . $game->id);
//Log::info("Resetting game_id " . $game->id);
$tipp->joker = false;
$tipp->save();
}
}
}

View file

@ -221,8 +221,6 @@ class UsersController extends Controller
$user_ids = $response['user_ids'];
$round_ids = $response['round_ids'];
///////////////////////////// DISPLAY AUFBAU /////////////////////////////
///
@ -233,6 +231,8 @@ class UsersController extends Controller
$isFinalRound=false;
Log::info("Starting Display Loop");
foreach ($user_ids as $user_id) {
$rankscore_total= 0;
$payout_sum = 0;
@ -251,10 +251,12 @@ class UsersController extends Controller
$rankingDisplay[$user_id]["user_name"] = $roundtipps[$key]["user_name"];
$rankingDisplay[$user_id]["is_dayscorewinner"] = $roundtipps[$key]["is_dayscorewinner"];
if ($round_id==4 && $roundtipps[$key]["is_dayscorewinner"]) {
//Log::info("Dayscorewinner: ".$roundtipps[$key]["user_name"]);
}
if ($round_id=="13") {
Log::info('userid '.$user_id." [".$key."]");
Log::info($roundtipps[$key]["is_dayscorewinner"]);
Log::info($roundtipps[$key]["payout"]);
}
$rankingDisplay[$user_id]["ranking_payout"] = $roundtipps[$key]["ranking_payout"];
if ($roundtipps[$key]["ranking_payout"]>0) {
@ -309,8 +311,6 @@ class UsersController extends Controller
$rankingDisplay[$user_id]["trendCol4"] = Tipp::trendCol($roundtipps[$key]["results"][6],$roundtipps[$key]["results"][7],
$roundtipps[$key]["tipps"][6],$roundtipps[$key]["tipps"][7],
$roundtipps[$key]["joker"][3]);
}
$userids = array_keys($rankingDisplay);
@ -334,7 +334,6 @@ class UsersController extends Controller
$game_results=array(); // 4 Spielergebnisse der angezeigten Runde
array_push($game_results,$rankingDisplay[0]["result_score1"],$rankingDisplay[0]["result_score2"],$rankingDisplay[0]["result_score3"],$rankingDisplay[0]["result_score4"],$rankingDisplay[0]["result_score5"],$rankingDisplay[0]["result_score6"],$rankingDisplay[0]["result_score7"],$rankingDisplay[0]["result_score8"]);
Log::info("UserController::ranking: ExecutionTime: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n");
return view('users.ranking', compact('all_rounds','rankingDisplay','userids','round','games','game_results','isFinalRound'));
}
@ -475,6 +474,15 @@ class UsersController extends Controller
foreach($user_ids as $user_id) {
$key=$round_id."_".$user_id;
if ($key=='13_44') {
Log::info("Debat(44) Debug");
Log::info("is_dayscorewinner:");
Log::info($roundtipps[$key]['is_dayscorewinner']);
Log::info("payout:");
Log::info($roundtipps[$key]['payout']);
}
$payout = str_replace(",",".",$roundtipps[$key]['payout']);
if (strlen($payout)==0) { $payout=0; }

View file

@ -4,6 +4,8 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Game;
use App\Season;
use Log;
use DB;
use Carbon;
@ -65,7 +67,15 @@ class Round extends Model
return -1;
}
public static function getNextRoundId($roundId) {
$currentSeason = Season::getCurrent();
$rounds = Round::where('season_id','=',$currentSeason->id)->where('id','>=',$roundId)->get();
foreach($rounds as $round) {
if ($round->id == $roundId) { continue; }
return $round->id;
}
return -1;
}
public static function getLastLockedRoundId() {
$season = Season::getCurrent();
@ -132,5 +142,15 @@ class Round extends Model
return $hourDiffToLock;
}
public static function getNames() {
$season= Season::getCurrent();
$rounds = Round::where('season_id','=',$season->id)->get();
Log::info("START");
$roundnames = array();
foreach($rounds as $round) {
$roundnames[$round->id] = $round->name;
}
return $roundnames;
}
}

View file

@ -328,10 +328,7 @@ class Tipp extends Model
foreach($user_ids as $user_id) {
$totalRankScore=0;
foreach($round_ids as $round_id) {
$key=$round_id."_".$user_id;
// Compute Dayscore values
$dayScore1WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][0],$roundtipps[$key]['results'][1],$roundtipps[$key]['tipps'][0],$roundtipps[$key]['tipps'][1],$roundtipps[$key]['joker'][0],$roundtipps[$key]['rankscore']);
$dayScore2WithRankScore = Tipp::getDayScoreLocal($roundtipps[$key]['results'][2],$roundtipps[$key]['results'][3],$roundtipps[$key]['tipps'][2],$roundtipps[$key]['tipps'][3],$roundtipps[$key]['joker'][1],$roundtipps[$key]['rankscore']);
@ -392,54 +389,53 @@ class Tipp extends Model
$round_count=0;
foreach ($round_ids as $round_id) {
$round_count +=1;
$round_count += 1;
$totalDayWinPayout += $payouts["tagessieg"];
$highestDayScore = $highestDayscores[$round_id];
$usersWithHighestDayScore = array();
$round_completed=false;
$round_completed = false;
foreach ($user_ids as $user_id) {
$round_completed = $roundtipps[$key]['round_completed']; // TODO: Separaten info array roundData erzeugen, der Rundenspezifische, SPielerübergreifende Infos enthält, so wie round_completed.
$key = $round_id . "_" . $user_id;
if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed'] && $highestDayScore>0 ) {
if ($roundtipps[$key]['dayscore'] == $highestDayScore && $roundtipps[$key]['round_completed'] && $highestDayScore > 0) {
array_push($usersWithHighestDayScore, [$user_id, $roundtipps[$key]['dayScoreWithRankScore']]);
}
}
if (sizeof($usersWithHighestDayScore) > 6) {
//usort($usersWithHighestDayScore, 'cmpDayWin');
usort($usersWithHighestDayScore, array('App\Tipp','cmpDayWin'));
}
$count = 0;
$cutOffScore = 0;
$dayScoreWinnersIds = array();
foreach ($usersWithHighestDayScore as $user) { // Feld0: user_id, dayScoreWithRankScore
//ALT
/*
$count += 1;
if ($count > 6) {
if ($user[1] < $cutOffScore) {
$dayScoreWinnersIds = array();
// Bei >6 Tagessiegern über rankscore reduzieren
if (sizeof($usersWithHighestDayScore) > 6) {
usort($usersWithHighestDayScore, array('App\Tipp', 'cmpDayWin'));
$count = 0;
$cutOffScore = 0;
foreach ($usersWithHighestDayScore as $user) { // Feld0: user_id, dayScoreWithRankScore
$key = $max_round_id . "_" . $user[0]; // Hier: $user[0] = user_id, $user[1] = dayScore WithRankScore
$rankscore = $user[1];
$count += 1;
if ($count == 1) {
$cutOffScore = $rankscore;
}
if ($rankscore < $cutOffScore) {
break;
}
array_push($dayScoreWinnersIds, $user[0]);
$key = $round_id . "_" . $user[0];
$roundtipps[$key]['is_dayscorewinner'] = true;
}
array_push($dayScoreWinnersIds, $user[0]);
$key = $round_id . "_" . $user[0];
$roundtipps[$key]['is_dayscorewinner'] = true;
$cutOffScore = $user[1];
*/
// NEU
$key = $max_round_id . "_" . $user[0]; // Hier: $user[0] = user_id, $user[1] = dayScore WithRankScore
$rankscore = $roundtipps[$key]['rankscore'];
$count += 1;
if ($count==1) {$cutOffScore=$rankscore;}
if ($rankscore < $cutOffScore) { break; }
array_push($dayScoreWinnersIds, $user[0]);
$key = $round_id . "_" . $user[0];
$roundtipps[$key]['is_dayscorewinner'] = true;
}
// Bei bis zu 6 Gewinnern normal als Sieger klassifizieren
else {
foreach ($usersWithHighestDayScore as $user) {
array_push($dayScoreWinnersIds, $user[0]);
$key = $round_id . "_" . $user[0];
$roundtipps[$key]['is_dayscorewinner'] = true;
}
}
// Compute Dayscorewin payout (Tagessieg)

View file

@ -8,8 +8,10 @@ use App\Season;
use App\Payment;
use App\Round;
use App\Game;
use Carbon;
use Log;
use DB;
class User extends Authenticatable
{
@ -207,18 +209,14 @@ class User extends Authenticatable
$user->save();
}
// Selektiert nur die "Heimspiele"
public static function getMatches($user_id, $league_id) {
$matches = DB::table('leagues_matches')->where('league_id', '=', $league_id)->where('user1_id','=',$user_id)->get();
return $matches;
}
public static function hasMatched($user1_id, $user2_id, $league_id) {
$matches = User::getMatches($user1_id, $league_id);
foreach($matches as $match) {
if ($match->user1_id == $user1_id && $match->user2_id == $user2_id) return true;
public static function getNames() {
$users=User::getActives();
$usernames = array();
foreach($users as $user) {
$usernames[$user->id] = $user->name;
}
return false;
return $usernames;
}

View file

@ -1,12 +1,22 @@
<?php
namespace App\leagues;
namespace App\Leagues;
use Illuminate\Database\Eloquent\Model;
use App\Season;
use DB;
use Log;
class League extends Model
{
const RANK_LEAGUE1 = 1;
const RANK_LEAGUE2 = 2;
const RANK_LEAGUE3 = 3;
const RANK_QUALIFICATION = 4;
protected $table ='leagues';
protected $fillable = [
'id','season_id','is_qualification','rank','subrank','start_round_id','round_count','name'
@ -26,7 +36,21 @@ class League extends Model
}
public static function getMemberCount($league_id) {
$members = DB::table('leagues_matches')->where('league_id','=',$league_id)->get();
$members = DB::table('leagues_members')->where('league_id','=',$league_id)->get();
return sizeof($members);
}
public static function getNames() {
$season = Season::getCurrent();
$leagues = League::where('season_id','=',$season->id)->orderBy('rank')->orderBy('name')->get();
$leagueNames = array();
foreach($leagues as $league) {
$leagueNames[$league->id] = $league->name;
}
return $leagueNames;
}
}

View file

@ -4,6 +4,8 @@ namespace App\Leagues;
use Illuminate\Database\Eloquent\Model;
use App\User;
class LeagueMember extends Model
{
protected $table ='leagues_members';
@ -11,4 +13,19 @@ class LeagueMember extends Model
'id','user_id','league_id'
];
//
public static function getMembers($league_id) {
$members =LeagueMember::where('league_id','=',$league_id)->orderBy('id')->get();
return $members;
}
public static function playsInRound($userId, $roundId, $leagueId) {
$matches1 = Match::where('user1_id','=',$userId)->where('round_id','=',$roundId)->where('league_id','=',$leagueId)->get();
if (sizeof($matches1)>0) return true;
$matches2 = Match::where('user2_id','=',$userId)->where('round_id','=',$roundId)->where('league_id','=',$leagueId)->get();
return sizeof($matches2)>0;
}
}

View file

@ -1,10 +1,17 @@
<?php
namespace App\leagues;
namespace App\Leagues;
use Illuminate\Database\Eloquent\Model;
use App\leagues\League;
use App\Leagues\League;
use App\Leagues\LeagueMember;
use App\User;
use App\Round;
use App\Season;
use Log;
use DB;
class Match extends Model
{
@ -13,106 +20,246 @@ class Match extends Model
'id','league_id','round_id','user1_id','user2_id'
];
public static function createMissingMatchups() {
// https://en.wikipedia.org/wiki/Round-robin_tournament
public static function createMissingMatchups()
{ Log::info("Match::Creating missing matchups()");
$currentSeason = Season::getCurrent();
$leagues = League::where('season_id','=',$currentSeason->id);
$leagues = League::where('season_id', '=', $currentSeason->id)->get();
// TODO: Differentiate Matchup selection by League Type
$roundNames=Round::getNames();
$leagueNames=League::getNames();
// Liga 1
// Liga 2
// Ligen 3 1,2,3,...n
foreach ($leagues as $league) {
// Liga 4 (Qualifikation)
// Liga 5: Champions League
// Liga 7: Achtelfinale
// Liga 8: Viertelfinale
// Liga 9: Halbfinale
// Liga 10: Finale
foreach($leagues as $league) {
// Qualifikation
if ($league->rank == 4) {
if ($league->rank == League::RANK_QUALIFICATION) {
$matches = array();
// Bereits bestehende Matches laden
DB::table('leagues_matches')->where('league_id','=',$league->id)->get();
$users = User::getActives();
foreach($users as $user1) {
$counter_users=getActives();
foreach($counter_users as $user2) {
if ($user1->id == $user2->id) continue;
if (!User::hasMatched($user1->id, $user2->id, $league->id)) {
$members = LeagueMember::getMembers($league->id);
foreach ($members as $member) {
$counterMembers = LeagueMember::getMembers($league->id);
foreach ($counterMembers as $counterMember) {
if ($member->user_id == $counterMember->user_id) continue;
// Die Paarung darf nicht schon in der DB existieren, egal welche Runde
// hasMatched bezieht sich auf bereits eingetragene matches
// Spieler darf gegen den Gegner in der Saison nicht schon gespielt haben
$exists = false;
// Prüfung ob Paarung bereits in matches abgespeichert ist
if (array_key_exists($league->id, $matches)) {
foreach ($matches[$league->id] as $match) {
if ($match[0] == $member->user_id && $match[1] == $counterMember->user_id) {
$exists = true;
}
if ($match[1] == $member->user_id && $match[0] == $counterMember->user_id) {
$exists = true;
}
}
}
// hasMatched prüft abgespeicherte Matches in DB (leagues_matches)
if (!Match::hasMatched($member->user_id, $counterMember->user_id, $league->id) && !$exists ) {
if (!array_key_exists($league->id, $matches)) {
$matches[$league->id] = array();
}
// add Match
array_push($matches, [$user1, $user2]);
array_push($matches[$league->id], [$member->user_id, $counterMember->user_id,0]); // 0 = unplatziert
Log::info("ADD MATCH PAIRING: Liga " . $league->id . " => " . $member->user_id . " vs " . $counterMember->user_id);
}
}
}
Log::info("Open Matches:");
foreach ($matches as $match) {
// Oh je, jetzt noch die Runde festlegen
// Wir haben jetzt in $matches die nach Liga unterteilten noch zu platzierenden Matches
//Log::info("Starting placement");
// Auffüllen der noch freien Runden mit den verfügbaren matches.
$rounds = Round::where('id','>=',$league->start_round_id)->get();
/*
*
* Bestimmen, in welcher Runde das Spiel stattfinden soll.
* Es darf kein Heim & Rückspiel in der gleichen Runde sein,
* d.h. ein Spieler kommt in einer Runde nur einmal zu einem Match
*
* Stehen keine Runden mehr zur Verfügung (der Standardfall)
* muss die Vergabe beendet werden. Neue Runden kommen dann
* später im Verlauf der Halbsaison ins System.
*
*/
// In der Runde darf es nicht schon ein bestehendes Match mit dem User geben
// $round = Match::getFreeRound($user_id, $league_id)
foreach ($rounds as $round) {
if ($leagueNames[$league->id]=="Qualifikationsgruppe 4" && $roundNames[$round->id]=="Runde 2") { Log::info("Analyzing Round 2");}
//Log::info("LeagueID=".$league->id.", Trying to fill roundid ".$round->id);
$count=0;
if ($leagueNames[$league->id]=="Qualifikationsgruppe 4" && $roundNames[$round->id]=="Runde 2") {
Log::info("Available Matchups:");
}
shuffle($matches[$league->id]);
foreach($matches[$league->id] as $key => $m) {
if ($m[2]==0) { $count += 1;
if ($leagueNames[$league->id]=="Qualifikationsgruppe 4" && $roundNames[$round->id]=="Runde 2") {
Log::info($m[0]." vs ".$m[1]);
}
}
}
//Log::info("Unplaced matches:".$count);
$existingRoundMatches = Match::where('league_id','=',$league->id)->where('round_id','=',$round->id)->get();
//Log::info("round ".$round->id." Existing matchCount:".sizeof($existingRoundMatches));
$membercount = League::getMemberCount($league->id);
$maxMatchCount = intdiv($membercount,2); //TODO: Ungerade Anzahl = +1
// Gibt es noch Einträge in $matches[$league->id] ?
$hasUnplacedMatches=false;
foreach($matches[$league->id] as $m) {
if ($m[2]==0) { $hasUnplacedMatches=true; break;}
}
if ( !$hasUnplacedMatches ) {
if ($leagueNames[$league->id]=="Qualifikationsgruppe 4" && $roundNames[$round->id]=="Runde 2") {
Log::info("Ending Placement for Round 2 because roster is full");
}
break;
}
foreach ($matches[$league->id] as $index => $match) {
if ($match[2]==1) continue;
// Anzahl an Matches pro Runde schon erreicht ?
$existingRoundMatches = Match::where('league_id','=',$league->id)->where('round_id','=',$round->id)->get();
//Log::info("Existing matches in roundid ".$round->id.": ".sizeof($existingRoundMatches));
if (sizeof($existingRoundMatches) > $maxMatchCount) {
//Log::info("Skipping to next round, because Placement roster is full");
continue;
}
$conflict=false;
foreach ($existingRoundMatches as $exMatch) {
$mName=$matches[$league->id][$index][0]." vs ".$matches[$league->id][$index][1];
if ($exMatch->user1_id == $match[0] ) { $conflict=true; }
else if ($exMatch->user2_id == $match[0]) { $conflict=true; }
else if ($exMatch->user1_id == $match[1]) { $conflict=true; }
else if ($exMatch->user2_id == $match[1]) { $conflict=true; }
}
if (!$conflict) {
$matches[$league->id][$index][2]=1;
Log::info("Saving match. ".$matches[$league->id][$index][0]." vs ".$matches[$league->id][$index][1]);
$newMatch = Match::create([
'league_id' => $league->id,
'round_id' => $round->id,
'user1_id' => $matches[$league->id][$index][0],
'user2_id' => $matches[$league->id][$index][1]
]);
$newMatch->save();
}
}
}
$count=0;
foreach($matches[$league->id] as $key => $m) {
if ($m[2]==0) { $count += 1; }
}
Log::info("Exiting LeagueId ".$league->id. " with ".$count." unplaced matches");
}
}
}
public static function hasMatched($user1_id, $user2_id, $league_id)
{
// Wieviele Spiele finden pro Runde statt ? => Jeder Spieler spielt, also GruppenGröße/2, bei ungerader Gruppengröße gibt es spielfreie Tage.
$matches = DB::table('leagues_matches')
->where('league_id', '=', $league_id)
->where('user1_id', '=', $user1_id)
->where('user2_id', '=', $user2_id)
->get();
if (sizeof($matches)) {
return true;
}
public static function getFreeRound($user_id, $league_id) {
$round_matches = Match::where('league_id','=',$league_id)->orderBy('round_id')->get();
$membercount = League::getMemberCount($league_id);
$max_size = divint($membercount,2);
$matches = DB::table('leagues_matches')
->where('league_id', '=', $league_id)
->where('user1_id', '=', $user2_id)
->where('user2_id', '=', $user1_id)
->get();
if (sizeof($matches)) {
return true;
}
$current_round_id=-1;
$current_member_count=0;
$is_round_usable=true;
return false;
}
foreach($round_matches as $round_match) {
$current_member_count+=1;
// 1.) Runde darf nicht schon Gruppengröße/2 Matches enthalten (siehe $max_size)
// 2.) Spieler darf in der Runde nicht schon spielen (als user1_id enthalten sein)
if ($current_member_count>$max_size) { $is_round_usable=false; continue; }
if ($round_match->user1_id == $user_id) { $is_round_usable=false; continue; }
if ($round_match->round_id != $current_round_id) {
if ($is_round_usable && $current_round_id!=-1) { return $round_match->round_id; }
$current_round_id=$round_match->match_id;
$current_member_count=0;
$is_round_usable = true;
}
// Selektiert nur die "Heimspiele"
public static function getMatches($user_id, $league_id) {
$matches = DB::table('leagues_matches')->where('league_id', '=', $league_id)->where('user1_id','=',$user_id)->get();
return $matches;
}
public static function getLeagueMatches($league_id) {
//$matches = Match::where('league_id','=',$league_id)->orderBy('round_id')->get();
$matches = DB::table('leagues_matches')->where('league_id','=',$league_id)->orderBy('round_id')->get();
$season = Season::getCurrent();
$roundnames = Round::getNames();
$usernames = User::getNames();
foreach($matches as $match) {
$match->round_name = $roundnames[$match->round_id];
$match->user1_name = $usernames[$match->user1_id];
$match->user2_name = $usernames[$match->user2_id];
// Hier könnte man die Punkte auswerten.
}
return -1; // No suitable/free round found for Player Match.
return $matches;
}
public static function getPairings($leagueId, $roundNr) {
$members = LeagueMember::getMembers($leagueId);
$pairingCount = intdiv(sizeof($members),2);
$roundRobin=array();
foreach($members as $member) {
array_push($roundRobin, $member->id);
}
while ($roundNr>1) {
// Round-Robin shift: First element stays, rest rotates
$first = array_shift($roundRobin); // Erstes Element sichern & entfernen
$last = array_pop($roundRobin); // Letztes Element sichern & entfernen
array_unshift($roundRobin, $last); // Vorne einfügen
array_unshift($roundRobin, $first); // Vorne einfügen
$roundNr--;
}
error_log("Members: ".sizeof($roundRobin));
foreach ($roundRobin as $index => $userId) {
error_log($index." => ".$userId);
}
$idx=0;
$slot=0;
$pairings=array();
foreach ($roundRobin as $index => $userId) {
$idx=$index;
if ($index >= $pairingCount){ $idx -= $pairingCount; $slot=1;}
$pairings[$idx][$slot]=$userId;
error_log("pairings[".$idx."][".$slot."]=".$userId);
}
return $pairings; // Array, der User1/User2 Tupel enthält
}
}

View file

@ -16,6 +16,6 @@
"jquery": "^3.1.1",
"laravel-mix": "0.*",
"lodash": "^4.17.4",
"vue": "^2.1.10"
"vue": "^2.4.4"
}
}

View file

@ -20,6 +20,9 @@
<script type="text/javascript" src="/bower/moment/min/moment.min.js"></script>
<script type="text/javascript" src="/bower/moment/locale/de.js"></script>
<script type="text/javascript" src="/bower/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="/bower/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" />
<script type="text/javascript">

View file

@ -2,29 +2,58 @@
<div class="navbar">
<div class="container text-center">
@if (Auth::check())
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/">Start</a>
&nbsp;
@if (Auth::user()->admin)
<div>
<label class="lead" style="font-color: black; font-weight: bold; font-size: 14px; ">Admin:</label>
<a class="lead" href="/seasons">Saison</a> &nbsp;
<a class="lead" href="/rounds#{{\App\Round::getFirstIncompleteRound()}}">Runden</a> &nbsp;
<a class="lead" href="/users">Spieler</a> &nbsp;
<a class="lead" href="/roundmails">Rundmail</a> &nbsp;
</div>
<label class="dropdown" id="dropdown1">
<a href="#" id="btn_admin" onclick="toggleSelect('dropdown_admin'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">Administration</a>
<div id="dropdown_admin" class="dropdown-content">
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/seasons">Saison</a>
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/rounds#{{\App\Round::getFirstIncompleteRound()}}">Runden</a>
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/users">Spieler</a>
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/roundmails">Rundmail</a>
</div>
</label>
@endif
<a class="lead" href="/">Start</a> &nbsp;
<a class="lead" href="/users/show_payouts">Quoten</a> &nbsp;
<a class="lead" href="/tipps#{{\App\Round::getFirstTippableRound()->id}}">Tipps</a> &nbsp;
<a class="lead" href="/users/ranking/roundid_-1#playerid_{{Auth::user()->id}}" >Rangliste</a> &nbsp;
<a class="lead" href="/users/payout#playerid_{{Auth::user()->id}}">Geldrangliste</a> &nbsp;
<label class="lead text ml-auto" >Spieler: <a href="/users/useredit/{{ Auth::user()->id }}">{{ Auth::user()->name }}</a></label><a class="lead" href="/logout">(abmelden)</a>
&nbsp;
<a style="font-color: blue; font-size: 22px;" href="/tipps#{{\App\Round::getFirstTippableRound()->id}}">Tipps</a> &nbsp;
&nbsp;
<a style="font-color: blue; font-size: 22px;" href="/users/ranking/roundid_-1#playerid_{{Auth::user()->id}}" >Rangliste</a> &nbsp;
&nbsp;
<label class="dropdown" id="dropdown2">
<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="#">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>
<div id="dropdown_info" class="dropdown-content">
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/users/show_payouts">Quoten</a> &nbsp;
<a style="font-weight:normal; font-color: blue; font-size: 22px;" href="/users/payout#playerid_{{Auth::user()->id}}">Geldrangliste</a> &nbsp;
</div>
</label>
&nbsp;
<label class="dropdown" id="dropdown4">
<a href="#" id="btn_player" onclick="toggleSelect('dropdown_player'); return false;" style="font-weight:normal; font-color: blue; font-size: 22px;">&nbsp;( {{Auth::user()->name}} )</a>
<div id="dropdown_player" class="dropdown-content">
<a style="font-weight: normal; font-color: blue; font-size: 22px;" href="/users/useredit/{{ Auth::user()->id }}">Einstellungen</a>
<a style="font-weight: normal; font-color: blue; font-size: 22px;" href="/logout">Abmelden</a>
</div>
</label>
@endif
</div>
</div>
<script>
// When the user clicks on the button,toggle between hiding and showing the dropdown content
function toggleSelect($elementName) {
document.getElementById($elementName).classList.toggle("show");
}
</script>
</div>

View file

@ -0,0 +1,36 @@
@extends('layouts.layout')
@section('content')
<section class="text-center">
<div class="container">
<label>{{ $season->name }}</label>
<h2>Spielplan</h2>
<!-- Start Runden-Loop-->
@foreach($matchesTotal as $round_id => $roundGroup)
<h3>{{$roundNames[$round_id]}}</h3>
<table class="table-bordered col-lg-12">
<tr class="table-bordered">
<td class="table-bordered" style="width:150px;">Gruppe</td>
<td class="table-bordered" style="width:150px;">Spieler 1</td>
<td class="table-bordered" style="width:150px;">Spieler 2</td>
<td class="table-bordered" style="width:150px;">Ergebnis</td>
</tr>
<p>&nbsp;</p>
@foreach($matchesTotal[$round_id] as $match)
@if ($leagueNames[$match->league_id]=="Qualifikationsgruppe 4") <!-- Debug -->
<tr class="table-bordered">
<td>&nbsp;{{$leagueNames[$match->league_id]}}&nbsp;</td>
<td>&nbsp;{{$match->user1_id}}-{{$match->user1_name}}&nbsp;</td>
<td>&nbsp;{{$match->user2_id}}-{{$match->user2_name}}&nbsp;</td>
<td>0:0</td>
</tr>
@endif
@endforeach
</table>
@endforeach
</div>
</section>
@endsection

View file

@ -1,43 +0,0 @@
@extends('layouts.layout')
@section('content')
<div class="container">
<h2>Liga-Spiel Einstellungen</h2>
<div class="lead">{{ $season->name }}</div>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</div>
<script>
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
@endsection

View file

@ -1,21 +1,23 @@
@extends('layouts.layout')
@section('content')
<section class="jumbotron text-center">
@if(Auth::check())
@if($hourDiffToLock<49)
@if (strlen($message_text_tipps)>0)
<div><p class="blink_text">{{ $message_text_tipps }}</p></div>
@endif
@if (strlen($message_text_joker)>0)
<div><p class="blink_text">{{ $message_text_joker }}</p></div>
@endif
@if (strlen($nextRoundLockTime)>0)
<div><p class="blink_text">{{ $nextRoundName }} sperrt sich: {{ $nextRoundLockTime }} ( noch {{ $hourDiffToLock }} )</p></div>
<!-- <section class="jumbotron text-center"> -->
<section class="container-fluid col-md-12">
<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>
@endif
@if (strlen($message_text_joker)>0)
<div><p class="blink_text" style="font-size:21px;">{{ $message_text_joker }}</p></div>
@endif
@if (strlen($nextRoundLockTime)>0)
<div><p class="blink_text" style="font-size:21px;">{{ $nextRoundName }} sperrt sich: {{ $nextRoundLockTime }} ( noch {{ $hourDiffToLock }} Stunden )</p></div>
@endif
@endif
@endif
@endif
<div class="container">
<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>
@ -24,12 +26,13 @@
<div>
<a href="/login" class="btn btn-primary">Anmelden</a>
</div>
<div><p></p><p></p><p></p></div>
</div>
<a href="/register" class="btn btn-primary">Registrieren</a>
@endif
<p>&nbsp;</p>
<div>
<a href="/register" class="btn btn-primary">Registrieren</a>
</div>
@endif
</span>
</section>
@if (Auth::check())
@foreach($display_rounds as $round)

View file

@ -1,5 +1,4 @@
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
@ -11,8 +10,6 @@
|
*/
Route::get('/','UsersController@main')->name('home');
Route::get('/register','RegistrationController@create')->name('register');
@ -39,7 +36,6 @@ Route::post('/rounds/storename', 'RoundsController@storename');
Route::get('/games/edit/{game_id}', 'GamesController@edit');
Route::post('/games/store', 'GamesController@store');
Route::get('/users','UsersController@index');
Route::get('/users/edit/{user_id}','UsersController@edit');
Route::post('/users/store','UsersController@store');
@ -78,6 +74,6 @@ 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\LeagueController@index');
Route::get('/league_settings/create_league/start_round_id={start_round_id}/round_count={round_count}/league_mode={league_mode}','Leagues\LeagueController@createLeagues');
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');

View file

@ -17,7 +17,7 @@ return array(
'App\\Http\\Controllers\\Controller' => $baseDir . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\GamesController' => $baseDir . '/app/Http/Controllers/GamesController.php',
'App\\Http\\Controllers\\HomeController' => $baseDir . '/app/Http/Controllers/HomeController.php',
'App\\Http\\Controllers\\Leagues\\LeagueController' => $baseDir . '/app/Http/Controllers/Leagues/LeagueController.php',
'App\\Http\\Controllers\\Leagues\\LeaguesController' => $baseDir . '/app/Http/Controllers/Leagues/LeaguesController.php',
'App\\Http\\Controllers\\Leagues\\MatchController' => $baseDir . '/app/Http/Controllers/Leagues/MatchController.php',
'App\\Http\\Controllers\\PaymentController' => $baseDir . '/app/Http/Controllers/PaymentController.php',
'App\\Http\\Controllers\\RegistrationController' => $baseDir . '/app/Http/Controllers/RegistrationController.php',
@ -33,6 +33,9 @@ return array(
'App\\Http\\Middleware\\RedirectIfAuthenticated' => $baseDir . '/app/Http/Middleware/RedirectIfAuthenticated.php',
'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php',
'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php',
'App\\Leagues\\League' => $baseDir . '/app/Leagues/League.php',
'App\\Leagues\\LeagueMember' => $baseDir . '/app/Leagues/LeagueMember.php',
'App\\Leagues\\Match' => $baseDir . '/app/Leagues/Match.php',
'App\\Mail\\RoundmailMailer' => $baseDir . '/app/Mail/RoundmailMailer.php',
'App\\Payment' => $baseDir . '/app/Payment.php',
'App\\Providers\\AppServiceProvider' => $baseDir . '/app/Providers/AppServiceProvider.php',
@ -47,8 +50,6 @@ return array(
'App\\Setting' => $baseDir . '/app/Setting.php',
'App\\Tipp' => $baseDir . '/app/Tipp.php',
'App\\User' => $baseDir . '/app/User.php',
'App\\leagues\\League' => $baseDir . '/app/leagues/League.php',
'App\\leagues\\Match' => $baseDir . '/app/leagues/Match.php',
'Carbon\\Carbon' => $vendorDir . '/nesbot/carbon/src/Carbon/Carbon.php',
'Carbon\\CarbonInterval' => $vendorDir . '/nesbot/carbon/src/Carbon/CarbonInterval.php',
'Carbon\\Exceptions\\InvalidDateException' => $vendorDir . '/nesbot/carbon/src/Carbon/Exceptions/InvalidDateException.php',

View file

@ -289,7 +289,7 @@ class ComposerStaticInita19fb0695e1b61b4feeb3cc3fbdd2feb
'App\\Http\\Controllers\\Controller' => __DIR__ . '/../..' . '/app/Http/Controllers/Controller.php',
'App\\Http\\Controllers\\GamesController' => __DIR__ . '/../..' . '/app/Http/Controllers/GamesController.php',
'App\\Http\\Controllers\\HomeController' => __DIR__ . '/../..' . '/app/Http/Controllers/HomeController.php',
'App\\Http\\Controllers\\Leagues\\LeagueController' => __DIR__ . '/../..' . '/app/Http/Controllers/Leagues/LeagueController.php',
'App\\Http\\Controllers\\Leagues\\LeaguesController' => __DIR__ . '/../..' . '/app/Http/Controllers/Leagues/LeaguesController.php',
'App\\Http\\Controllers\\Leagues\\MatchController' => __DIR__ . '/../..' . '/app/Http/Controllers/Leagues/MatchController.php',
'App\\Http\\Controllers\\PaymentController' => __DIR__ . '/../..' . '/app/Http/Controllers/PaymentController.php',
'App\\Http\\Controllers\\RegistrationController' => __DIR__ . '/../..' . '/app/Http/Controllers/RegistrationController.php',
@ -305,6 +305,9 @@ class ComposerStaticInita19fb0695e1b61b4feeb3cc3fbdd2feb
'App\\Http\\Middleware\\RedirectIfAuthenticated' => __DIR__ . '/../..' . '/app/Http/Middleware/RedirectIfAuthenticated.php',
'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php',
'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php',
'App\\Leagues\\League' => __DIR__ . '/../..' . '/app/Leagues/League.php',
'App\\Leagues\\LeagueMember' => __DIR__ . '/../..' . '/app/Leagues/LeagueMember.php',
'App\\Leagues\\Match' => __DIR__ . '/../..' . '/app/Leagues/Match.php',
'App\\Mail\\RoundmailMailer' => __DIR__ . '/../..' . '/app/Mail/RoundmailMailer.php',
'App\\Payment' => __DIR__ . '/../..' . '/app/Payment.php',
'App\\Providers\\AppServiceProvider' => __DIR__ . '/../..' . '/app/Providers/AppServiceProvider.php',
@ -319,8 +322,6 @@ class ComposerStaticInita19fb0695e1b61b4feeb3cc3fbdd2feb
'App\\Setting' => __DIR__ . '/../..' . '/app/Setting.php',
'App\\Tipp' => __DIR__ . '/../..' . '/app/Tipp.php',
'App\\User' => __DIR__ . '/../..' . '/app/User.php',
'App\\leagues\\League' => __DIR__ . '/../..' . '/app/leagues/League.php',
'App\\leagues\\Match' => __DIR__ . '/../..' . '/app/leagues/Match.php',
'Carbon\\Carbon' => __DIR__ . '/..' . '/nesbot/carbon/src/Carbon/Carbon.php',
'Carbon\\CarbonInterval' => __DIR__ . '/..' . '/nesbot/carbon/src/Carbon/CarbonInterval.php',
'Carbon\\Exceptions\\InvalidDateException' => __DIR__ . '/..' . '/nesbot/carbon/src/Carbon/Exceptions/InvalidDateException.php',