96 lines
2.4 KiB
PHP
96 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Lib\Helpers;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class GamePeriodHelper
|
|
{
|
|
public static function voteStartAt(): Carbon
|
|
{
|
|
return Carbon::parse(config('goldencrush.vote_start_at'))->startOfDay();
|
|
}
|
|
|
|
public static function voteEndAt(): Carbon
|
|
{
|
|
return Carbon::parse(config('goldencrush.vote_end_at'))->endOfDay();
|
|
}
|
|
|
|
public static function endParticipationStartAt(): Carbon
|
|
{
|
|
return self::voteEndAt()->copy()->addDay()->startOfDay();
|
|
}
|
|
|
|
public static function endParticipationEndAt(): Carbon
|
|
{
|
|
return Carbon::parse(config('goldencrush.end_participation_end_at'))->endOfDay();
|
|
}
|
|
|
|
public static function endGameStartAt(): Carbon
|
|
{
|
|
return self::endParticipationEndAt()->copy()->addDay()->startOfDay();
|
|
}
|
|
|
|
public static function endGameEndAt(): Carbon
|
|
{
|
|
return Carbon::parse(config('goldencrush.end_game_end_at'))->endOfDay();
|
|
}
|
|
|
|
public static function hasValidPeriods(): bool
|
|
{
|
|
return self::voteStartAt()->lte(self::voteEndAt())
|
|
&& self::voteStartAt()->lte(self::endGameEndAt());
|
|
}
|
|
|
|
public static function state(): string
|
|
{
|
|
|
|
if (! self::hasValidPeriods()) {
|
|
\Log::error('Config des dates invalide ! ');
|
|
return 'closed';
|
|
}
|
|
|
|
$today = now();
|
|
|
|
if ($today->betweenIncluded(self::voteStartAt(), self::voteEndAt())) {
|
|
return 'vote';
|
|
}
|
|
|
|
if ($today->betweenIncluded(self::endParticipationStartAt(), self::endParticipationEndAt())) {
|
|
return 'end_participation';
|
|
}
|
|
|
|
if ($today->betweenIncluded(self::endGameStartAt(), self::endGameEndAt())) {
|
|
return 'end_game';
|
|
}
|
|
|
|
return 'closed';
|
|
}
|
|
|
|
public static function routeName(): string
|
|
{
|
|
return match (self::state()) {
|
|
'vote' => 'club.golden-crush',
|
|
'end_participation' => 'club.golden-crush.end-of-participation',
|
|
'end_game' => 'club.golden-crush.end-of-game',
|
|
default => 'club.home.show',
|
|
};
|
|
}
|
|
|
|
public static function isGamePeriod(): bool
|
|
{
|
|
return now()->between(
|
|
self::voteStartAt(),
|
|
self::endGameEndAt()
|
|
);
|
|
}
|
|
// visibility
|
|
public static function isGameVisible(): bool
|
|
{
|
|
return in_array(self::state(), [
|
|
'vote',
|
|
'end_participation',
|
|
'end_game',
|
|
]);
|
|
}
|
|
}
|