hasMany('App\Game'); } // true, wenn irgend ein Game locked ist. public static function hasLockedGame($round_id) { //Log::info("Check Round::HasLockedGame => ".$round_id); $games = Game::where('round_id', $round_id)->get(); foreach ($games as $game) { if (Game::locked($game->id)==true) { return true; } } return false; } public static function isCompleted($round_id) { $round = Round::where('id','=',$round_id)->first(); $games = Game::where('round_id','=',$round->id)->get(); $completed = true; foreach($games as $game) { if ($game->score1==-1 || $game->score2==-1) { $completed=false; } } return $completed; } public static function getLastCompleteRoundId() { $season = Season::getCurrent(); $rounds=Round::where('season_id','=',$season->id)->orderBy('id')->get(); $lastCompleteRound=-1; foreach ($rounds as $round) { if (Round::isCompleted($round->id) == true) { $lastCompleteRound = $round->id; } } return $lastCompleteRound; } public static function getFirstIncompleteRound() { $season_id = Season::getCurrent()->id; $rounds = Round::where('season_id','=',$season_id)->orderBy('id')->get(); foreach($rounds as $round) { if (!Round::isCompleted($round->id)) return $round->id; } return -1; } public static function getLastLockedRoundId() { $season = Season::getCurrent(); $rounds=Round::where('season_id','=',$season->id)->orderBy('id')->get(); $lastLockedRoundId=-1; foreach ($rounds as $round) { if (Round::hasLockedGame($round->id) == true) { $lastLockedRoundId = $round->id; } } return $lastLockedRoundId; } public static function getFirstTippableRound() { $season = Season::getCurrent(); $rounds=Round::where('season_id','=',$season->id)->orderBy('id')->get(); $locked = false; foreach ($rounds as $round) { if (!Round::hasLockedGame($round->id) ) { return $round; } } return null; } public static function getClosestRoundToNow() { $sql="select round_id,DATEDIFF(NOW(),kickoff) from games order by 2 desc limit 1;"; $result=DB::select($sql); if (count($result)==0) return 0; return $result[0]->round_id; } public static function getTippSpielLink() // Mit Verweis auf den aktuellen Tipp { $firstTippableRoundId=Round::getFirstTippableRound()->id; $tippSpielLink="http://hoschis-tippspiel.de/tipps#".$firstTippableRoundId; return $tippSpielLink; } // Ab sofort Verzicht auf statische Methoden, soweit möglich. public function getLockTime() { $games = Game::where('round_id','=',$this->id)->get(); $earliestKickoff = Carbon\Carbon::now(); $earliestKickoff->addWeeks(100); foreach($games as $game) { $kickoff = Carbon\Carbon::parse($game->kickoff); if ($kickoff < $earliestKickoff) { $earliestKickoff = $kickoff; } } $earliestKickoff->subHour(); return $earliestKickoff; } public function isInLockWarningTime($hours) { $hourDiffToLock=$this->getLockTime()->diffInHours(Carbon\Carbon::now()); if ($hourDiffToLock<=$hours) return true; return false; } public function getRemainingHoursBeforeLock() { $hourDiffToLock=$this->getLockTime()->diffInHours(Carbon\Carbon::now()); return $hourDiffToLock; } }