*/ class ChallengePeer { /** * @var array $challenges Les défis */ protected $challenges; public function __construct() { $this->challenges = $this->initChallenges(); } public function getChallenges() { return $this->challenges; } protected function initChallenges() { $data = []; for ($i = 18; $i < 25; $i++) { $data[] = (new Challenge()) ->setTitle('Mon titre '.$i) ->setDescription('Ma description '.$i) ->setDay(1) ->setHour($i); } for ($i = 1; $i < 19; $i++) { $data[] = (new Challenge()) ->setTitle('Mon titre '.$i) ->setDescription('Ma description '.$i) ->setDay(2) ->setHour($i); } return $data; } public function isPreviousChallenge(Challenge $challenge) { return !$this->isActiveChallenge($challenge) && !$this->isNextChallenge($challenge); } public function isActiveChallenge(Challenge $challenge) { $day = (int) date('d') === 12 ? 1 : 2; $hour = (int) date('H'); return $challenge->getDay() === $day && $hour === $challenge->getHour(); } public function isNextChallenge(Challenge $challenge) { $day = (int) date('d') === 12 ? 1 : 2; $hour = (int) date('H'); if ($day < $challenge->getDay()) { return true; } if ($day === $challenge->getDay() && $hour < $challenge->getHour()) { return true; } return false; } public function getChronoDate() { $now = new DateTime('now'); $next = $now->modify('+1 hour'); return $next->format('d F Y H:00:00'); } }