tippspiel/pfosten/app/Game.php

74 lines
1.4 KiB
PHP
Raw Normal View History

2017-06-20 08:43:36 +02:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
2017-06-26 17:21:30 +02:00
use Log;
use Carbon;
2017-06-20 08:43:36 +02:00
class Game extends Model
{
protected $fillable = [
'id','round_id','team1','team2','score1','score2','kickoff'
];
2017-06-26 17:21:30 +02:00
// true, wenn Anstoss - 1hr > now()
public static function locked($game_id)
{
$game = Game::find($game_id);
$now = Carbon\Carbon::now();
$tipp_input_end = $game->getLocktime($game);
2017-06-26 17:21:30 +02:00
return ($tipp_input_end <= $now);
}
2017-07-18 14:58:32 +02:00
public function hasResult() {
$game = $this;
2017-08-04 16:51:28 +02:00
return $game->score1 > -1;
2017-07-18 14:58:32 +02:00
}
2017-06-26 17:21:30 +02:00
public static function has_result($game_id) {
2017-07-18 14:58:32 +02:00
2017-06-26 17:21:30 +02:00
$game = Game::where('id',$game_id)->first();
$hasIt = $game->score1 > -1;
if ($hasIt==false) {
return false;
}
return true;
}
2017-07-18 14:58:32 +02:00
2017-06-26 17:21:30 +02:00
public static function resultString($game_id) {
$game = Game::where('id',$game_id)->first();
2017-06-27 08:22:25 +02:00
$now=Carbon\Carbon::now();
2017-06-26 17:21:30 +02:00
2017-07-18 14:58:32 +02:00
if (!$game->hasResult()) {
2017-08-03 20:47:51 +02:00
if ($game->kickoff > $now) return "-";
2017-06-27 08:22:25 +02:00
$start=Carbon\Carbon::parse($game->kickoff);
$end=$start->addHours(2);
if ($end<$now && $start>$now) return "Läuft";
return "(Eingeben)";
}
2017-06-26 17:21:30 +02:00
return $game->score1. " : " . $game->score2;
}
public function getLocktime() {
return Carbon\Carbon::parse($this->kickoff)->addHour(-1);
}
2017-06-20 08:43:36 +02:00
}