2017-06-20 08:43:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2017-06-21 17:12:07 +02:00
|
|
|
use App\Season;
|
|
|
|
|
use App\Payment;
|
2017-06-22 21:22:07 +02:00
|
|
|
use App\Round;
|
|
|
|
|
use App\Game;
|
|
|
|
|
use Log;
|
2017-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
|
|
|
|
use Notifiable;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name', 'email', 'password',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password', 'remember_token',
|
|
|
|
|
];
|
2017-06-21 17:12:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only the current season.
|
|
|
|
|
public static function is_season_paid($user_id) {
|
|
|
|
|
$retval="Ja";
|
|
|
|
|
if (User::payment_date($user_id, Season::getCurrent()->id)==null) { $retval="Nein"; }
|
|
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function payment_date($user_id,$season_id) {
|
|
|
|
|
$season = Season::getCurrent();
|
|
|
|
|
if ($season) {
|
|
|
|
|
$payment = Payment::where([
|
|
|
|
|
['user_id', '=', $user_id],
|
|
|
|
|
['season_id', '=', $season->id]
|
|
|
|
|
])->first();
|
|
|
|
|
if ($payment) {
|
|
|
|
|
if ($payment->paid_date) {
|
|
|
|
|
return $payment->paid_date;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$payment= Payment::create([
|
|
|
|
|
'user_id' => $user_id,
|
|
|
|
|
'season_id'=> $season->id,
|
|
|
|
|
'paid_date'=> null
|
|
|
|
|
]);
|
|
|
|
|
$payment->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 21:22:07 +02:00
|
|
|
public static function getScore($user_id) {
|
|
|
|
|
|
|
|
|
|
Log::info("User::getScore for userid=" . $user_id);
|
|
|
|
|
|
|
|
|
|
$season = Season::getCurrent();
|
|
|
|
|
|
|
|
|
|
$rounds = Round::where('season_id','=',$season->id)->get();
|
|
|
|
|
|
|
|
|
|
$totalScore=0;
|
|
|
|
|
foreach($rounds as $round) {
|
|
|
|
|
$games = Game::where('round_id','=',$round->id)->get();
|
|
|
|
|
Log::info(' round_id=' . $round->id);
|
|
|
|
|
foreach ($games as $game) {
|
|
|
|
|
|
|
|
|
|
Log::info(' game_id=' . $game->id);
|
|
|
|
|
|
|
|
|
|
$tipp = Tipp::getTipp($game->id,$user_id);
|
|
|
|
|
$score = Tipp::getScore($tipp->id);
|
|
|
|
|
|
|
|
|
|
Log::info(" Game id=" . $game->id. ", Tipp id=". $tipp->id.", score=" . $score);
|
|
|
|
|
|
|
|
|
|
$totalScore+=$score;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Log::info("Total score=" . $totalScore);
|
|
|
|
|
return $totalScore;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-20 08:43:36 +02:00
|
|
|
}
|