tippspiel/pfosten/app/Game.php
2017-06-27 08:22:25 +02:00

55 lines
1.2 KiB
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Log;
use Carbon;
class Game extends Model
{
protected $fillable = [
'id','round_id','team1','team2','score1','score2','kickoff'
];
// true, wenn Anstoss - 1hr > now()
public static function locked($game_id)
{
$game = Game::find($game_id);
$now = Carbon\Carbon::now();
$tipp_input_end = Carbon\Carbon::parse($game->kickoff)->addHour(-1);
return ($tipp_input_end <= $now);
}
public static function has_result($game_id) {
$game = Game::where('id',$game_id)->first();
$hasIt = $game->score1 > -1;
if ($hasIt==false) {
return false;
}
return true;
}
public static function resultString($game_id) {
$game = Game::where('id',$game_id)->first();
$now=Carbon\Carbon::now();
if (!Game::has_result($game_id)) {
if ($game->kickoff>$now) return "Anstoss: " . $game->kickoff;
$start=Carbon\Carbon::parse($game->kickoff);
$end=$start->addHours(2);
if ($end<$now && $start>$now) return "Läuft";
return "(Eingeben)";
}
return $game->score1. " : " . $game->score2;
}
}