Commit febd64dc authored by François Agneray's avatar François Agneray
Browse files

Premier import

parents
Pipeline #275 skipped
{
"directory": "public/bower_components/",
"timeout": 120000
}
nbproject/
vendor/*
public/bower_components
data/*
build/*
log/*
cache/*
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
composer.lock
1.0.0
\ No newline at end of file
<?php
// DIC configuration
$container = $app->getContainer();
// -----------------------------------------------------------------------------
// Service providers
// -----------------------------------------------------------------------------
// Twig
$container['view'] = function ($c) {
$settings = $c->get('settings');
$view = new Slim\Views\Twig($settings['view']['template_path'], $settings['view']['twig']);
// Add extensions
$view->addExtension(new Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri()));
$view->addExtension(new Twig_Extension_Debug());
return $view;
};
// Doctrine 2 Entity Manager
$container['em'] = function ($c) {
$settings = $c->get('settings');
$metadata = $settings['database'];
$c = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(
$metadata['entity_path'],
$metadata['dev_mode']
);
$c->setProxyDir(getcwd() . '/' . $metadata['path_proxy']);
if ($metadata['dev_mode']) {
$c->setAutoGenerateProxyClasses(true);
} else {
$c->setAutoGenerateProxyClasses(false);
}
$em = \Doctrine\ORM\EntityManager::create($metadata['connection_options'], $c);
return $em;
};
// Flash messages
//$container['flash'] = function ($c) {
// return new Slim\Flash\Messages;
//};
// -----------------------------------------------------------------------------
// Service factories
// -----------------------------------------------------------------------------
// monolog
$container['logger'] = function ($c) {
$settings = $c->get('settings');
$logger = new Monolog\Logger($settings['logger']['name']);
$logger->pushProcessor(new Monolog\Processor\UidProcessor());
$logger->pushHandler(new Monolog\Handler\StreamHandler($settings['logger']['path'], Monolog\Logger::DEBUG));
return $logger;
};
// -----------------------------------------------------------------------------
// Action factories
// -----------------------------------------------------------------------------
$container[App\Action\HomeAction::class] = function ($c) {
return new App\Action\HomeAction($c->get('view'), $c->get('logger'));
};
$container[App\Action\InscriptionAction::class] = function ($c) {
return new App\Action\InscriptionAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
<?php
// Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard);
<?php
// Routes
$app->get('/', App\Action\HomeAction::class)
->setName('homepage');
$app->map(['GET', 'POST'], '/inscription', App\Action\InscriptionAction::class)
->setName('inscription');
<?php
return [
'settings' => [
// Slim Settings
'determineRouteBeforeAppMiddleware' => false,
'displayErrorDetails' => false,
// View settings
'view' => [
'template_path' => __DIR__ . '/templates',
'twig' => [
'cache' => __DIR__ . '/../cache/twig',
'debug' => true,
'auto_reload' => true,
],
],
// monolog settings
'logger' => [
'name' => 'app',
'path' => __DIR__ . '/../log/app.log',
],
// database settings (doctrine 2)
'database' => [
'entity_path' => ['app/src/Entity'],
'path_proxy' => 'cache/doctrine_proxy',
'dev_mode' => true,
'connection_options' => [
'driver' => 'pdo_sqlite',
'path' => 'data/db.sqlite'
]
],
],
];
<?php
namespace App\Action;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
final class HomeAction
{
private $view;
private $logger;
public function __construct(Twig $view, LoggerInterface $logger)
{
$this->view = $view;
$this->logger = $logger;
}
public function __invoke(Request $request, Response $response, $args)
{
$this->logger->info("Home page action dispatched");
$this->view->render($response, 'home.twig', [
'page' => 'home'
]);
return $response;
}
}
<?php
namespace App\Action;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
final class InscriptionAction
{
private $view;
private $logger;
private $em;
public function __construct(Twig $view, LoggerInterface $logger, EntityManagerInterface $em)
{
$this->view = $view;
$this->logger = $logger;
$this->em = $em;
}
public function __invoke(Request $request, Response $response, $args)
{
$this->logger->info("Inscription action dispatched");
if($request->isGet()) {
$this->view->render($response, 'inscription.twig', [
'page' => 'inscription'
]);
}
if($request->isPost()) {
// TODO: Vérification des champs vides
// TODO: Vérificiation de la force du mot de passe
// TODO: Vérification de l'éxistance du participant dans la base
// DONE: Ajouter le participant en tant que stagiaire
// TODO: Envoyer un email pour confirmation
// TODO: Confirmer l'inscription au participant
$roleStagiaire = $this->em->find('App\Entity\Role', 3);
var_dump($roleStagiaire);
$parsedBody = $request->getParsedBody();
var_dump($parsedBody);
$participant = new \App\Entity\Participant();
$participant->setNom($parsedBody['nom']);
$participant->setPrenom($parsedBody['prenom']);
$participant->setEmail($parsedBody['email']);
$participant->setPassword($parsedBody['password']);
$participant->addRole($roleStagiaire);
$this->em->persist($participant);
$this->em->flush();
var_dump($participant);
}
return $response;
}
}
<?php
namespace App\Entity;
/**
* @Entity
* @Table(name="atelier")
*/
class Atelier
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string")
**/
private $nom;
/**
* @Column(type="datetime", name="date_debut")
**/
private $dateDebut;
/**
* @Column(type="datetime", name="date_fin")
**/
private $dateFin;
/**
* @ManyToOne(targetEntity="Thematique")
* @JoinColumn(name="thematique_id", referencedColumnName="id")
*/
private $thematique;
/**
* @ManyToOne(targetEntity="Salle")
* @JoinColumn(name="salle_id", referencedColumnName="id")
*/
private $salle;
public function getId()
{
return $this->id;
}
public function getNom()
{
return $this->nom;
}
public function setNom($nom)
{
$this->nom = $nom;
}
public function getDateDebut()
{
return $this->dateDebut;
}
public function setDateDebut($dateDebut)
{
$this->dateDebut = $dateDebut;
}
public function getDateFin()
{
return $this->dateFin;
}
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
}
public function getThematique()
{
return $this->thematique;
}
public function setThematique(Thematique $thematique)
{
$this->thematique = $thematique;
}
public function getSalle()
{
return $this->salle;
}
public function setSalle(Salle $salle)
{
return $this->salle = $salle;
}
}
<?php
namespace App\Entity;
/**
* @Entity
* @Table(name="inscription")
*/
class Inscription
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @ManyToOne(targetEntity="Participant")
* @JoinColumn(name="participant_id", referencedColumnName="id")
*/
private $participant;
/**
* @ManyToOne(targetEntity="Atelier")
* @JoinColumn(name="atelier_id", referencedColumnName="id")
*/
private $atelier;
/**
* @Column(type="datetime", name="date_inscription")
**/
private $dateInscription;
public function __construct(Participant $participant, Atelier $atelier)
{
$this->participant = $participant;
$this->atelier = $atelier;
}
public function getId()
{
return $this->id;
}
public function getParticipant()
{
return $this->participant;
}
public function getAtelier()
{
return $this->atelier;
}
public function getDateInscription()
{
return $this->dateInscription;
}
}
<?php
namespace App\Entity;
/**
* @Entity
* @Table(name="participant")
*/
class Participant
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string")
**/
private $prenom;
/**
* @Column(type="string")
**/
private $nom;
/**
* @Column(type="string")
**/
private $email;
/**
* @Column(type="string")
**/
private $password;
/**
* @ManyToMany(targetEntity="Role")
* @JoinTable(
* name="participant_x_role",
* joinColumns={@JoinColumn(name="participant_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
private $roles;
public function getId()
{
return $this->id;
}
public function getPrenom()
{
return $this->prenom;
}
public function setPrenom($prenom)
{
$this->prenom = $prenom;
}
public function getNom()
{
return $this->nom;
}
public function setNom($nom)
{
$this->nom = $nom;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getRoles()
{
return $this->roles;
}
public function addRole(Role $role)
{
$this->roles[] = $role;
}
}
<?php
namespace App\Entity;
/**
* @Entity
* @Table(name="role")
**/
class Role
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
**/
private $id;
/**
* @Column(type="string")
**/
private $nom;
public function getId()
{
return $this->id;
}
public function getNom()
{
return $this->nom();
}
public function setNom($nom)
{
$this->nom = $nom;
}
}
<?php
namespace App\Entity;
/**
* @Entity
* @Table(name="salle")
*/
class Salle
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string")
**/
private $nom;
/**
* @Column(type="integer")
**/
private $etage;
/**
* @Column(type="string")
**/
private $aile;
/**
* @Column(type="string")
**/
private $description;
/**
* @Column(type="integer", name="quota_officiel")
**/
private $quotaOfficiel;
/**
* @Column(type="integer", name="quota_physique")
**/
private $quotaPhysique;
public function getId()
{
return $this->id;
}
public function getNom()
{
return $this->nom;
}
public function setNom($nom)
{
$this->nom = $nom;
}
public function getEtage()
{
return $this->etage;
}
public function setEtage($etage)
{
$this->etage = $etage;
}
public function getAile()
{
return $this->aile;
}
public function setAile($aile)
{
$this->aile = $aile;
}
public function getDescription()
{
return $this->description;
}
public function setDescription($description)
{
$this->description = $description;
}
public function getQuotaOfficiel()
{
return $this->quotaOfficiel;
}
public function setQuotaOfficiel($quotaOfficiel)
{
$this->quotaOfficiel = $quotaOfficiel;
}
public function getQuotaPhysique()
{
return $this->quotaPhysique;