60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Test extends Model
|
|
{
|
|
// In order for testing seasons to work, we need a way to set all the users to 'paid'
|
|
public static function paySeason($seasonId)
|
|
{
|
|
$users = User::all();
|
|
$cnt=0;
|
|
foreach ($users as $user) {
|
|
Payment::set_payment_date($user->id, $seasonId, '01.01.2017');
|
|
$cnt+=1;
|
|
}
|
|
return $cnt." Users in season_id ".$seasonId." set to paid";
|
|
}
|
|
|
|
public static function fillSeason($seasonId) {
|
|
error_log("creating all tipps started");
|
|
Tipp::createAllTips();
|
|
error_log("creating all tipps completed");
|
|
$users = User::all();
|
|
|
|
error_log("setting payment started");
|
|
Test::paySeason($seasonId);
|
|
error_log("setting payment completed");
|
|
|
|
|
|
error_log("Users: ".sizeof($users));
|
|
|
|
// Spielergebnisse faken
|
|
$rounds=Round::where('season_id','=',$seasonId)->get();
|
|
error_log("Rounds: ".sizeof($rounds));
|
|
foreach ($rounds as $round) {
|
|
$games=Game::where('round_id','=',$round->id)->get();
|
|
$jokerSet=false;
|
|
error_log("Faking Tipps and game results for all users for: ".$round->name);
|
|
foreach ($games as $game) {
|
|
$game->score1=random_int(0,3);
|
|
$game->score2=random_int(0,3);
|
|
$game->save();
|
|
foreach ($users as $user) {
|
|
// Tipps faken
|
|
$tipp=Tipp::where('game_id','=',$game->id)->where('user_id','=',$user->id)->first();
|
|
$tipp->score1 = random_int(0,3);
|
|
$tipp->score2 = random_int(0,3);
|
|
if (!$jokerSet) {
|
|
$tipp->joker=true;
|
|
}
|
|
$tipp->save();
|
|
}
|
|
$jokerSet=true;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|