Start of Test Class, fixing ranking visibiliy of open rounds issue

This commit is contained in:
Torsten 2017-10-06 12:17:49 +02:00
parent 7545760aa2
commit 29e493e22d
11 changed files with 11891 additions and 43 deletions

11779
d0274241_2017-10-06_1111.sql Normal file

File diff suppressed because it is too large Load diff

View file

@ -171,32 +171,28 @@ class LeaguesController extends Controller
return redirect("/seasons");
}
public function showLeagueRounds($league_rank, $maxRoundId) {
public function showLeagueRounds($league_rank) {
if (Auth::guest()) { return redirect("/"); }
$season=Season::getCurrent();
$maxRoundId = min(Round::getLastRoundId($season->id),$maxRoundId);
$roundNames = Round::getNames();
$leagueNames = League::getNames();
$leagues = League::where('season_id','=',$season->id)->where('rank','=', $league_rank)->orderBy('id')->get();
$matchesTotal = array();
foreach ($leagues as $league) {
$matches = Match::getMatchResults($league->id, $maxRoundId);
$matches = Match::getMatchResults($league->id, -1);
foreach ($matches as $match) {
if ($match->round_id <= $maxRoundId) {
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;
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;
}
}

View file

@ -4,8 +4,12 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Season;
use App\Round;
use App\Quota;
use App\User;
use App\Game;
use App\Tipp;
use Carbon;
use DB;
use Auth;
use Log;
@ -49,25 +53,81 @@ class SeasonsController extends Controller
// Validate form
$this->validate(request(), [
'name' => 'required'
'name' => 'required',
'roundcount' => 'required'
]);
// Create and save the season
$season = Season::create([
'name' => request('name')
'name' => request('name'),
'rounds' => request('roundcount')
]);
if (Season::all()->count()==1) {
Season::setCurrent($season->id);
Log::info('Setting season id=' .$season->id);
}
$season->save();
Season::setCurrent($season->id);
Log::info('Setting season id=' .$season->id);
Quota::createDefaultQuota($season->id);
$nr=1;
$roundcount=request('roundcount');
$seasonId = Season::getCurrent()->id;
$endOfYear = Carbon\Carbon::createFromDate(Carbon\Carbon::now()->year,12,31);
while($nr<=$roundcount) {
$roundname="Runde ".$nr;
Log::info("Creating: ".$roundname);
$round = Round::create([
'name' => $roundname,
'season_id' => $seasonId
]);
$round->save();
$round_id = $round->id;
$game1 = Game::create([
'round_id' => $round_id,
'team1' => "Mannschaft 1",
'team2' => "Mannschaft 2",
//'kickoff' => User::toDBDate(request('game1_kickoff'))
'kickoff' => $endOfYear
]);
$game1->save();
$game2 = Game::create([
'round_id' => $round_id,
'team1' => "Mannschaft 3",
'team2' => "Mannschaft 4",
'kickoff' => $endOfYear
]);
$game2->save();
$game3 = Game::create([
'round_id' => $round_id,
'team1' => "Mannschaft 5",
'team2' => "Mannschaft 6",
'kickoff' => $endOfYear
]);
$game3->save();
$game4 = Game::create([
'round_id' => $round_id,
'team1' => "Mannschaft 7",
'team2' => "Mannschaft 8",
'kickoff' => $endOfYear
]);
$game4->save();
// Sign them in
$nr+=1;
}
Log::info("Round creation completed, now setting Tipps");
Tipp::createAllTips();
// Redirect to the home page
return redirect('/seasons');
}
public function store_quota() {
if (Auth::guest()) { return redirect("/"); }
if (!Auth::user()->admin) { return redirect("/"); }

View file

@ -193,6 +193,7 @@ class UsersController extends Controller
$currentSeason = Season::getCurrent();
// Check ob mindestens eine Runde der Saison gelockt ist angezeigt werden kann
if($max_round_id==-1) {
$max_round_id = Round::getLastLockedRoundId();
if ($max_round_id==-1) {
@ -209,6 +210,10 @@ class UsersController extends Controller
}
}
$max_round_id=min($max_round_id, Round::getLastLockedRoundId());
// Payment made ?
if (! User::payment_date(Auth::user()->id, $currentSeason->id) && Auth::user()->name!="Torsten Schneider") {
return view('users.no_payment');
@ -428,7 +433,6 @@ class UsersController extends Controller
]);
$user=Auth::user();
$user->email=request('email');
@ -455,6 +459,7 @@ class UsersController extends Controller
public function money_ranking() {
if (Auth::guest()) { return redirect("/"); }
$currentSeason = Season::getCurrent();
// Payment made ?
@ -474,15 +479,6 @@ 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

@ -109,6 +109,7 @@ class Quota extends Model
return $arr;
}
public static function setQuotas($quotas,$season_id) {
foreach ($quotas as $key => $quota) {
setQuota($key, $quota, $season_id);
@ -116,21 +117,19 @@ class Quota extends Model
}
public static function createDefaultQuota($season_id)
{
Log::info('Creating default quotas');
DB::table('quotas')->where('season_id', '=', $season_id)->delete();
$roundCount=Season::getCurrent()->rounds;
Log::info("Creating new Quota");
$quota = new Quota;
$quota->season_id = $season_id;
$quota->name = "Runden";
$quota->prc = 36;
$quota->prc = $roundCount;
$quota->save();

View file

@ -9,7 +9,7 @@ use Log;
class Season extends Model
{
protected $fillable = [
'name'
'name','rounds'
];
/*
public function isActive() {
@ -21,6 +21,7 @@ class Season extends Model
$setting = Setting::all()->first();
if (!$setting) {
//Log::info('Season.getCurrent(): No current season set');
error_log('Season.getCurrent(): No current season set');
return null;
}

View file

@ -207,6 +207,7 @@ class Tipp extends Model
public static function createAllTips() {
$users = DB::table('users')->where('deleted',null)->get();
foreach($users as $user) {
Log::info("Creating tipps for userid ".$user->id);
Tipp::createTipps($user->id);
}
}

View file

@ -9,7 +9,7 @@
<!-- Start Runden-Loop-->
@foreach($matchesTotal as $round_id => $roundGroup)
<h2>{{$roundNames[$round_id]}}</h2>
<h2><a href="http://hoschis-tippspiel.de/users/ranking/roundid_{{$round_id}}#playerid_0">{{$roundNames[$round_id]}}</a></h2>
<!-- Start Liga-Loop-->
@foreach($matchesTotal[$round_id] as $league_id => $matchGroup)
@ -25,8 +25,9 @@
<!-- Start Matchgruppen-Loop-->
@foreach($matchesTotal[$round_id][$league_id] as $match)
<tr class="table-bordered">
<td>&nbsp;{{$match->user1_name}}&nbsp;</td>
<td>&nbsp;{{$match->user2_name}}&nbsp;</td>
<td>&nbsp;<a href="/league/showSingleUserMatches/user_id={{$match->user1_id}}"> {{$match->user1_name}} </a>&nbsp;</td>
<td>&nbsp;<a href="/league/showSingleUserMatches/user_id={{$match->user2_id}}"> {{$match->user2_name}} </a>&nbsp;</td>
@if($match->user1_rankscore==-1)
<td> ausstehend </td>
@else

View file

@ -4,7 +4,7 @@
<section class="text-center">
<div class="container">
<h2>{{ $userName }}</h2>
<h2>Spielplan für: {{ $userName }}</h2>
<table class="table-bordered col-lg-12">
<tr class="table-bordered">
@ -12,6 +12,7 @@
<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>
<td class="table-bordered" style="width:150px;">Ergebnis</td>
</tr>
@foreach($matches as $match)
@ -19,8 +20,15 @@
<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>
<td>&nbsp;<a href="/league/showSingleUserMatches/user_id={{$match->user1_id}}"> {{$match->user1_name}} </a>&nbsp;</td>
<td>&nbsp;<a href="/league/showSingleUserMatches/user_id={{$match->user2_id}}"> {{$match->user2_name}} </a>&nbsp;</td>
@if ($match->user1_rankscore>-1)
<td class="table-bordered" style="width:150px;">{{$match->user1_rankscore}}:{{$match->user2_rankscore}}</td>
@else
<td class="table-bordered" style="width:150px;">ausstehend</td>
@endif
</tr>
@endforeach

View file

@ -10,11 +10,14 @@
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" name="name" required>
<label for="roundcount">Anzahl Runden:</label>
<input style="width:100px" type="text" class="form-control" id="roundcount" name="roundcount" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Erstellen</button>
</div>
</form>

View file

@ -14,9 +14,13 @@
<form>
<p>&nbsp;</p>
<div class="form-group" >
<h4>
<label style="float:left; width:200px;">Aktive Spieler:</label>
<label style="float:left;">&nbsp;{{$active_user_count}}</label>
</h4>
<h4>
<label style="float:left; width:200px;">Einsatz pro Spieler:</label>
<label style="float:left;">&nbsp;{{$quotas['Einsatz']}} €</label>