tippspiel/pfosten/app/Game.php
2017-08-04 16:51:28 +02:00

64 lines
1.3 KiB
PHP
Executable file

<?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 function hasResult() {
$game = $this;
return $game->score1 > -1;
}
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->hasResult()) {
if ($game->kickoff > $now) return "-";
$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;
}
}