defis48/src/Mmi/Bundle/ChallengeBundle/Resources/Model/ChallengePeer.php

85 lines
1.9 KiB
PHP
Raw Normal View History

2016-01-12 22:26:10 +01:00
<?php
namespace Mmi\Bundle\ChallengeBundle\Resources\Model;
2016-01-12 22:32:37 +01:00
use DateTime;
2016-01-12 22:26:10 +01:00
/**
* Class ChallengePeer
* @author Simon Vieille <simon@deblan.fr>
*/
class ChallengePeer
{
/**
2016-01-12 23:03:10 +01:00
* @var array $challenges Les défis
2016-01-12 22:26:10 +01:00
*/
protected $challenges;
public function __construct()
{
$this->challenges = $this->initChallenges();
}
public function getChallenges()
{
return $this->challenges;
}
protected function initChallenges()
{
$data = [];
2016-01-13 21:29:34 +01:00
$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);
2016-01-12 22:26:10 +01:00
return $data;
}
public function isPreviousChallenge(Challenge $challenge)
{
return !$this->isActiveChallenge($challenge) && !$this->isNextChallenge($challenge);
}
public function isActiveChallenge(Challenge $challenge)
{
2016-01-13 19:12:20 +01:00
$day = (int) date('d') === 15 ? 1 : 2;
2016-01-12 22:26:10 +01:00
$hour = (int) date('H');
return $challenge->getDay() === $day && $hour === $challenge->getHour();
}
public function isNextChallenge(Challenge $challenge)
{
2016-01-13 19:12:20 +01:00
$day = (int) date('d') === 15 ? 1 : 2;
2016-01-12 22:26:10 +01:00
$hour = (int) date('H');
if ($day < $challenge->getDay()) {
return true;
}
if ($day === $challenge->getDay() && $hour < $challenge->getHour()) {
return true;
}
return false;
}
2016-01-12 22:32:37 +01:00
public function getChronoDate()
{
$now = new DateTime('now');
$next = $now->modify('+1 hour');
return $next->format('d F Y H:00:00');
}
2016-01-12 22:26:10 +01:00
}