85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Mmi\Bundle\ChallengeBundle\Resources\Model;
|
|
|
|
use DateTime;
|
|
|
|
/**
|
|
* Class ChallengePeer
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
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 = [];
|
|
|
|
$data[] = (new Challenge())
|
|
->setTitle('Défi Facebook')
|
|
->setDescription('Le BDE offre les pizzas à L\'équipe qui a un maximum de j\'aimes sur Facebook d\'ici le prochain défi, tous les cousp sont permis.')
|
|
->setDay(1)
|
|
->setHour(18);
|
|
|
|
$data[] = (new Challenge())
|
|
->setTitle('')
|
|
->setDescription('')
|
|
->setDay(1)
|
|
->setHour(18);
|
|
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function isPreviousChallenge(Challenge $challenge)
|
|
{
|
|
return !$this->isActiveChallenge($challenge) && !$this->isNextChallenge($challenge);
|
|
}
|
|
|
|
public function isActiveChallenge(Challenge $challenge)
|
|
{
|
|
$day = (int) date('d') === 15 ? 1 : 2;
|
|
$hour = (int) date('H');
|
|
|
|
return $challenge->getDay() === $day && $hour === $challenge->getHour();
|
|
}
|
|
|
|
public function isNextChallenge(Challenge $challenge)
|
|
{
|
|
$day = (int) date('d') === 15 ? 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');
|
|
}
|
|
}
|