59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Season;
|
|
use App\User;
|
|
use Log;
|
|
|
|
class ManualPayout extends Model
|
|
{
|
|
protected $fillable = [
|
|
'season_id','name','user_id'
|
|
];
|
|
|
|
public static function getManualQuotaNames() {
|
|
$manualQuotas=array('liga_platz1','liga_platz2','liga_platz3','liga_platz2_1','liga_platz3_1','pokal');
|
|
return $manualQuotas;
|
|
}
|
|
|
|
public static function getWinners() {
|
|
$winners=array();
|
|
$manualQuotas=ManualPayout::getManualQuotaNames();
|
|
foreach ($manualQuotas as $quota) {
|
|
$userId=0;
|
|
$winner=ManualPayout::getWinner($quota);
|
|
if ($winner) { $userId=$winner->id; }
|
|
$winners[$quota]=$userId;
|
|
}
|
|
return $winners;
|
|
}
|
|
|
|
public static function getWinner($quotaName) {
|
|
$season = Season::getCurrent();
|
|
|
|
$entry = ManualPayout::where('season_id','=', $season->id)->where('quota_name','=',$quotaName)->first();
|
|
if (!$entry) return null;
|
|
$user = User::where('id','=',$entry->user_id);
|
|
return $user->first();
|
|
}
|
|
|
|
public static function setWinner( $userId, $quotaName) {
|
|
|
|
$season = Season::getCurrent();
|
|
|
|
Log::info("setWinner, season_id=".$season->id.", quota_name='".$quotaName."'");
|
|
|
|
$entry = ManualPayout::where('season_id','=',$season->id)->where('quota_name','=',$quotaName)->first();
|
|
if (!$entry) {
|
|
$entry = new ManualPayout;
|
|
$entry->user_id = $userId;
|
|
$entry->season_id = $season->id;
|
|
$entry->quota_name = $quotaName;
|
|
}
|
|
|
|
$entry->user_id = $userId;
|
|
$entry->save();
|
|
}
|
|
}
|