Fuck yeah :')

This commit is contained in:
Simon Vieille 2016-01-12 22:26:10 +01:00
commit bbbf83ad1e
5 changed files with 212 additions and 64 deletions

View file

@ -5,6 +5,7 @@ namespace Mmi\Bundle\ChallengeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Mmi\Bundle\ChallengeBundle\Resources\Model\ChallengePeer;
class DefaultController extends Controller
{
@ -14,6 +15,12 @@ class DefaultController extends Controller
*/
public function indexAction()
{
return [];
$challengePeer = new ChallengePeer();
$challenges = $challengePeer->getChallenges();
return [
'challenge_peer' => $challengePeer,
'challenges' => $challenges,
];
}
}

View file

@ -0,0 +1,103 @@
<?php
namespace Mmi\Bundle\ChallengeBundle\Resources\Model;
/**
* Class Challenge
* @author Simon Vieille <simon@deblan.fr>
*/
class Challenge
{
/**
* @var int L'heure du défi
*/
protected $hour;
/**
* @var string Le titre du défi
*/
protected $title;
/**
* @var string La description du défi
*/
protected $description;
/**
* @return Challenge
* @param int $hour L'heure du défi
*/
public function setHour($hour)
{
$this->hour = (int) $hour;
return $this;
}
/**
* @return int L'heure du défi
*/
public function getHour()
{
return $this->hour;
}
/**
* @return Challenge
* @param int $day Le jour du défi
*/
public function setDay($day)
{
$this->day = (int) $day;
return $this;
}
/**
* @return int Le jour du défi
*/
public function getDay()
{
return $this->day;
}
/**
* @return Challenge
* @param string $title Le titre du défi
*/
public function setTitle($title)
{
$this->title = (string) $title;
return $this;
}
/**
* @return Le titre du défi
*/
public function getTitle()
{
return $this->title;
}
/**
* @return Challenge
* @param string $description La description du défi
*/
public function setDescription($description)
{
$this->description = (string) $description;
return $this;
}
/**
* @return La description du défi
*/
public function getDescription()
{
return $this->description;
}
}

View file

@ -0,0 +1,77 @@
<?php
namespace Mmi\Bundle\ChallengeBundle\Resources\Model;
/**
* Class ChallengePeer
* @author Simon Vieille <simon@deblan.fr>
*/
class ChallengePeer
{
/**
* @var Generator $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;
}
}

View file

@ -33,69 +33,9 @@
</header>
<main id="container">
<ul>
<li class="selector"></li>
<li><h1>13h | Défi 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati, quaerat.</p>
</li>
<li><h1>14h | Consigne surprise 1</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro, possimus!</p>
</li>
<li><h1>15h | Défi 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, nam!</p>
</li>
<li><h1>16h | Consigne surprise 2</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. At, consectetur!</p>
</li>
<li><h1>17h | Défi 3</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsum, nihil.</p>
</li>
<li><h1>18h | Consigne surprise 3</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur, explicabo.</p>
</li>
<li><h1>19h | Défi 4</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem, quas!</p>
</li>
<li class="active"><h1>20h | Consigne surprise 4</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate, quisquam.</p>
</li>
<li class="unavaliable"><h1>21h | Défi 5</h1>
<p>Instructions indisponibles pour le moment | Location : HALL</p>
</li>
<li class="unavaliable"><h1>22h | Consigne surprise 5</h1>
<p>Consigne indisponible pour le moment...</p>
</li>
<li class="unavaliable"><h1>23h | Défi 6</h1>
<p>Instructions indisponibles pour le moment | Location : HALL</p>
</li>
<li class="unavaliable"><h1>00h | Consigne surprise 6</h1>
<p>Consigne indisponible pour le moment...</p>
</li>
<li class="unavaliable"><h1>01h | Défi 7</h1>
<p>Instructions indisponibles pour le moment | Location : HALL</p>
</li>
<li class="unavaliable"><h1>02h | Consigne surprise 7</h1>
<p>Consigne indisponible pour le moment...</p>
</li>
<li class="unavaliable"><h1>03h | Défi 8</h1>
<p>Instructions indisponibles pour le moment | Location : HALL</p>
</li>
<li class="unavaliable"><h1>04h | Consigne surprise 8</h1>
<p>Consigne indisponible pour le moment...</p>
</li>
<li class="unavaliable"><h1>05h | Défi 9</h1>
<p>Instructions indisponibles pour le moment | Location : HALL</p>
</li>
<li class="unavaliable"><h1>06h | Consigne surprise 9</h1>
<p>Consigne indisponible pour le moment...</p>
</li>
<li class="unavaliable"><h1>07h | Défi 10</h1>
<p>Instructions indisponibles pour le moment | Location : HALL</p>
</li>
<li class="unavaliable"><h1>08h | Consigne surprise 10</h1>
<p>Consigne indisponible pour le moment...</p>
</li>
</ul>
{% block challenges %}
{% endblock %}
</main>
<footer>
<div id="pixel-grid" class="pixel-grid"></div>

View file

@ -1 +1,22 @@
{% extends "MmiChallengeBundle:Default:base.html.twig" %}
{% block challenges %}
<ul>
{% for challenge in challenges %}
{% set is_next = challenge_peer.isNextChallenge(challenge) %}
{% set is_current = challenge_peer.isActiveChallenge(challenge) %}
<li class="{% if is_current %}active{% endif %} {% if is_next %}unavaliable{% endif %}">
<h1>{{ challenge.hour }}h | {{ challenge.title }}</h1>
{% if not is_next %}
<p>
{{ challenge.description|nl2br }}
</p>
{% else %}
<p>Instructions indisponibles</p>
{% endif %}
</li>
{% endfor %}
</ul>
{% endblock %}