Commit e2e81012 authored by Chrystel Moreau's avatar Chrystel Moreau
Browse files

Sondage (pre-agenda, participantSondage) & Parcours (agenda, participantParcours) => DONE

parent 8fefd210
......@@ -60,16 +60,21 @@ $container[App\Action\DashboardAction::class] = function ($c) {
return new App\Action\DashboardAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardPreInscriptionAction::class] = function ($c) {
return new App\Action\DashboardPreInscriptionAction($c->get('view'), $c->get('logger'), $c->get('em'));
$container[App\Action\DashboardParticipantSondageAction::class] = function ($c) {
return new App\Action\DashboardParticipantSondageAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\ParticipantPreInscriptionFormationAction::class] = function ($c) {
return new App\Action\ParticipantPreInscriptionFormationAction($c->get('view'), $c->get('logger'), $c->get('em'));
$container[App\Action\DashboardParticipantSondageFormationAction::class] = function ($c) {
return new App\Action\DashboardParticipantSondageFormationAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardParcoursAction::class] = function ($c) {
return new App\Action\DashboardParcoursAction($c->get('view'), $c->get('logger'), $c->get('em'));
$container[App\Action\DashboardParticipantParcoursAction::class] = function ($c) {
return new App\Action\DashboardParticipantParcoursAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardParticipantParcoursFormationAction::class] = function ($c) {
return new App\Action\DashboardParticipantParcoursFormationAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
......@@ -98,6 +103,14 @@ $container[App\Action\DashboardAdminFormationFormAction::class] = function ($c)
return new App\Action\DashboardAdminFormationFormAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardAdminPreAgendaAction::class] = function ($c) {
return new App\Action\DashboardAdminPreAgendaAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardAdminPreAgendaFormAction::class] = function ($c) {
return new App\Action\DashboardAdminPreAgendaFormAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardAdminAgendaAction::class] = function ($c) {
return new App\Action\DashboardAdminAgendaAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
......
......@@ -43,17 +43,21 @@ $app->get('/dashboard-home', App\Action\DashboardAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_home');
$app->get('/dashboard-preinscription', App\Action\DashboardPreInscriptionAction::class)
$app->get('/dashboard-participant-sondage', App\Action\DashboardParticipantSondageAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_preinscription');
->setName('dashboard_participant_sondage');
$app->map(['GET', 'POST'],'/dashboard-preinscription-formation', App\Action\ParticipantPreInscriptionFormationAction::class)
$app->map(['GET', 'POST'],'/dashboard-participant-sondage-formation', App\Action\DashboardParticipantSondageFormationAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_preinscription_formation');
->setName('dashboard_participant_sondage_formation');
$app->get('/dashboard-parcours', App\Action\DashboardParcoursAction::class)
$app->get('/dashboard-participant-parcours', App\Action\DashboardParticipantParcoursAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_parcours');
->setName('dashboard_participant_sondage');
$app->map(['GET', 'POST'],'/dashboard-participant-parcours-formation', App\Action\DashboardParticipantParcoursFormationAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_participant_parcours_formation');
// =============================================================
......@@ -81,6 +85,14 @@ $app->map(['GET', 'POST', 'PUT', 'DELETE'], '/dashboard-admin-formation-form', A
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_admin_formation_form');
$app->get('/dashboard-admin-preagenda', App\Action\DashboardAdminPreAgendaAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_admin_preagenda');
$app->map(['GET', 'POST', 'PUT', 'DELETE'], '/dashboard-admin-preagenda-form', App\Action\DashboardAdminPreAgendaFormAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_admin_preagenda_form');
$app->get('/dashboard-admin-agenda', App\Action\DashboardAdminAgendaAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_admin_agenda');
......
......@@ -115,8 +115,7 @@ final class DashboardAdminAgendaFormAction
private function getFormations()
{
//$dql = "SELECT f FROM App\Entity\Formation f LEFT JOIN f.agendas a where f.confirme='t' AND a.dateDebut IS NULL ORDER BY f.nom ASC";
$dql = "SELECT f FROM App\Entity\Formation f LEFT JOIN f.agendas a where a.dateDebut IS NULL ORDER BY f.nom ASC";
$dql = "SELECT f FROM App\Entity\Formation f LEFT JOIN f.agendas a where f.confirme='t' AND a.dateDebut IS NULL ORDER BY f.nom ASC";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
......
<?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 DashboardAdminPreAgendaAction
{
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("dashboard formation page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$roleSI = $request->getAttribute('roleSI');
if ($roleSI != 'admin') {
return $response->withStatus(401);
}
$preagendas = $this->getPreAgendas();
$this->view->render($response, 'dashboard_admin_preagenda.twig', [
'page' => 'dashboard-admin-preagenda',
'token' => $token,
'preagendas' => $preagendas
]);
return $response;
}
public function getPreAgendas() {
$dql = "SELECT a FROM App\Entity\PreAgenda a ORDER BY a.dateDebut ASC";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
}
<?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 DashboardAdminPreAgendaFormAction
{
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("dashboard page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$roleSI = $request->getAttribute('roleSI');
if ($roleSI != 'admin') {
return $response->withStatus(401);
}
if($request->isGet()) {
$formations = $this->getFormations();
$a = [
'page' => 'dashboard',
'token' => $token,
'formations' => $formations
];
if (array_key_exists('preagenda_id', $params)) {
$preagenda = $this->em->find('App\Entity\PreAgenda', $params['preagenda_id']);
$formations = $this->getOneFormation($params['preagenda_id']);
$a['preagenda'] = $preagenda;
}
if (array_key_exists('quota', $params)) {
$parsedBody = $request->getParsedBody();
$debut = date_create_from_format('d/m/Y H:i', $params['jour'] . ' ' . $params['debut']);
$fin = date_create_from_format('d/m/Y H:i', $params['jour'] . ' ' . $params['fin']);
$quota = $params['quota'];
$salles = $this->getSalles($debut->format('Y-m-d H:i:s'),$fin->format('Y-m-d H:i:s'),$quota);
$response = $response->write(json_encode($salles))->withHeader('Content-type', 'application/json');
return $response;
}
else {
$this->view->render($response, 'dashboard_admin_preagenda_form.twig', $a);
}
}
if($request->isPost()) {
$parsedBody = $request->getParsedBody();
$formation = $this->em->find('App\Entity\Formation', $parsedBody['formation']);
$debut = date_create_from_format('d/m/Y H:i', $parsedBody['jour'] . ' ' . $parsedBody['debut']);
$fin = date_create_from_format('d/m/Y H:i', $parsedBody['jour'] . ' ' . $parsedBody['fin']);
$salle = $this->em->find('App\Entity\Salle', $parsedBody['salle']);
$preagenda = new \App\Entity\PreAgenda();
$preagenda->setFormation($formation);
$preagenda->setSalle($salle);
$preagenda->setDateDebut($debut);
$preagenda->setDateFin($fin);
$this->em->persist($preagenda);
$this->em->flush();
$response = $response->write('Nouvel preagenda enregistré')->withStatus(201);
}
if($request->isPut()) {
$parsedBody = $request->getParsedBody();
$formation = $this->em->find('App\Entity\Formation', $parsedBody['formation']);
$salle = $this->em->find('App\Entity\Salle', $parsedBody['salle']);
$debut = date_create_from_format('d/m/Y H:i', $parsedBody['jour'] . ' ' . $parsedBody['debut']);
$fin = date_create_from_format('d/m/Y H:i', $parsedBody['jour'] . ' ' . $parsedBody['fin']);
$preagenda = $this->em->find('App\Entity\PreAgenda', $parsedBody['preagenda_id']);
$preagenda->setFormation($formation);
$preagenda->setSalle($salle);
$preagenda->setDateDebut($debut);
$preagenda->setDateFin($fin);
$this->em->flush();
$response = $response->write('PreAgenda n°' . $preagenda->getId() . ' modifié')->withStatus(201);
}
if ($request->isDelete()) {
$preagenda = $this->em->find('App\Entity\PreAgenda', $params['preagenda_id']);
$this->em->remove($preagenda);
$this->em->flush();
$response = $response->write('PreAgenda id: ' . $params['preagenda_id'] . ' supprimé')->withStatus(200);
}
return $response;
}
private function getFormations()
{
//$dql = "SELECT f FROM App\Entity\Formation f LEFT JOIN f.preagendas a where f.confirme='t' AND a.dateDebut IS NULL ORDER BY f.nom ASC";
$dql = "SELECT f FROM App\Entity\Formation f LEFT JOIN f.preagendas a where a.dateDebut IS NULL ORDER BY f.nom ASC";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
private function getOneFormation($id_formation)
{
$dql = "SELECT f FROM App\Entity\Formation f where f.id=$id_formation";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
// select distinct salle.id,salle.nom,salle.quota_physique,preagenda.date_debut,preagenda.date_fin from salle
// left join preagenda on salle.id=preagenda.id_salle
// where salle.quota_physique >= 30 and
// salle.id not in
// (select salle.id from salle left join preagenda on salle.id=preagenda.id_salle
// where (preagenda.date_debut,preagenda.date_fin) overlaps ('2017-07-04 14:00:00','2017-07-04 17:00:00'))
// order by salle.quota_physique;
private function getSalles($debut,$fin,$quota)
{
$dql = "SELECT distinct s FROM App\Entity\Salle s LEFT JOIN s.preagendas a ";
$dql .= "WHERE s.quotaPhysique >= $quota AND s.id NOT IN ";
$dql .= " ( select s1.id FROM App\Entity\Salle s1 LEFT JOIN s1.preagendas a1 ";
$dql .= " where a1.dateDebut between '$debut' and '$fin' and a1.dateFin between '$debut' and '$fin' )";
$dql .= " ORDER BY s.quotaPhysique";
$query = $this->em->createQuery($dql);
return $query->getArrayResult();
}
}
<?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 DashboardParcoursAction
{
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("dashboard-parcours page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$email = $request->getAttribute('email');
$participant = $this->getParticipant($email);
$this->view->render($response, 'dashboard_parcours.twig', [
'page' => 'dashboard-parcours',
'token' => $token,
'participant' => $participant
]);
return $response;
}
private function getParticipant($email)
{
$participant = $this->em->getRepository('App\Entity\Participant')->findOneBy(array('email' => $email));
if(isset($participant)) {
return $participant;
} else {
return false;
}
}
}
<?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 DashboardParticipantParcoursAction
{
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("dashboard-participant-parcours page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$email = $request->getAttribute('email');
$participant = $this->getParticipant($email);
$a = [
'page' => 'dashboard-participant-parcours',
'token' => $token,
'participant' => $participant
];
if (array_key_exists('jour', $params)) {
$j=explode("-",$params['jour']);
if ($params['debut'] == '08:00:00'){ $a['jour'] = $j[2].' Juillet 2017 - Matin';}
if ($params['debut'] == '13:00:00'){ $a['jour'] = $j[2].' Juillet 2017 - Après-midi';}
$agendas = $this->getAgendas($params['jour'],$params['debut'],$params['fin'],$participant->getId());
$a['agendas'] = $agendas;
$inscription = $this->getInscriptionAgenda($params['jour'],$params['debut'],$params['fin'],$participant->getId());
$a['inscription'] = $inscription;
}
$this->view->render($response, 'dashboard_participant_parcours.twig', $a);
return $response;
}
private function getParticipant($email)
{
$participant = $this->em->getRepository('App\Entity\Participant')->findOneBy(array('email' => $email));
if(isset($participant)) {
return $participant;
} else {
return false;
}
}
//select *,
// (select count(*) from participant_x_agenda pa where pa.id_agenda=a.id) as nb_inscrits,
// (select count(*) from participant_x_agenda p2 where p2.id_agenda=a.id and p2.id_participant=100) as check from agenda a;
public function getAgendas($jour,$debut,$fin,$id) {
$date_debut=$jour." ".$debut;
$date_fin=$jour." ".$fin;
$dql = "SELECT a,";
//$dql .= "(select count(pa) from App\Entity\ParticipantAgenda pa where pa.agenda=a.id) as nb_inscrits, ";
$dql .= "(select count(p2) from App\Entity\ParticipantAgenda p2 where p2.agenda=a.id and p2.participant=$id) as check ";
$dql .= "FROM App\Entity\Agenda a ";
$dql .= "WHERE a.dateDebut between '$date_debut' and '$date_fin' and a.dateFin between '$date_debut' and '$date_fin'";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
public function getInscriptionAgenda($jour,$debut,$fin,$id) {
$date_debut=$jour." ".$debut;
$date_fin=$jour." ".$fin;
$dql = "SELECT pa from App\Entity\ParticipantAgenda pa LEFT JOIN pa.agenda a ";
$dql .= "WHERE pa.participant=$id ";
$dql .= "AND a.dateDebut between '$date_debut' and '$date_fin' and a.dateFin between '$date_debut' and '$date_fin'";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
}
......@@ -7,7 +7,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
final class ParticipantInscriptionFormationAction
final class DashboardParticipantParcoursFormationAction
{
private $view;
private $logger;
......@@ -54,7 +54,7 @@ final class ParticipantInscriptionFormationAction
}
$this->view->render($response, 'dashboard_inscription.twig', [
$this->view->render($response, 'dashboard_participant_parcours.twig', [
'page' => 'dashboard',
'token' => $token,
'participant' => $participant
......
<?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 DashboardParticipantSondageAction
{
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("dashboard-participant-sondage page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$email = $request->getAttribute('email');
$participant = $this->getParticipant($email);
$a = [
'page' => 'dashboard-participant-sondage',
'token' => $token,
'participant' => $participant
];
if (array_key_exists('jour', $params)) {
$j=explode("-",$params['jour']);
if ($params['debut'] == '08:00:00'){ $a['jour'] = $j[2].' Juillet 2017 - Matin';}
if ($params['debut'] == '13:00:00'){ $a['jour'] = $j[2].' Juillet 2017 - Après-midi';}
$preagendas = $this->getPreAgendas($params['jour'],$params['debut'],$params['fin'],$participant->getId());
$a['preagendas'] = $preagendas;
$inscription = $this->getInscriptionPreAgenda($params['jour'],$params['debut'],$params['fin'],$participant->getId());
$a['inscription'] = $inscription;
}
$this->view->render($response, 'dashboard_participant_sondage.twig', $a);
return $response;
}
private function getParticipant($email)
{
$participant = $this->em->getRepository('App\Entity\Participant')->findOneBy(array('email' => $email));
if(isset($participant)) {
return $participant;
} else {
return false;
}
}
//select *,
// (select count(*) from participant_x_agenda pa where pa.id_agenda=a.id) as nb_inscrits,
// (select count(*) from participant_x_agenda p2 where p2.id_agenda=a.id and p2.id_participant=100) as check from agenda a;
public function getPreAgendas($jour,$debut,$fin,$id) {
$date_debut=$jour." ".$debut;
$date_fin=$jour." ".$fin;
$dql = "SELECT a,";
//$dql .= "(select count(pa) from App\Entity\ParticipantAgenda pa where pa.agenda=a.id) as nb_inscrits, ";
$dql .= "(select count(p2) from App\Entity\ParticipantPreAgenda p2 where p2.preagenda=a.id and p2.participant=$id) as check ";
$dql .= "FROM App\Entity\PreAgenda a ";
$dql .= "WHERE a.dateDebut between '$date_debut' and '$date_fin' and a.dateFin between '$date_debut' and '$date_fin'";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
public function getInscriptionPreAgenda($jour,$debut,$fin,$id) {
$date_debut=$jour." ".$debut;
$date_fin=$jour." ".$fin;
$dql = "SELECT pa from App\Entity\ParticipantPreAgenda pa LEFT JOIN pa.preagenda a ";
$dql .= "WHERE pa.participant=$id ";
$dql .= "AND a.dateDebut between '$date_debut' and '$date_fin' and a.dateFin between '$date_debut' and '$date_fin'";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
}
<?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 DashboardParticipantSondageFormationAction
{
private $view;
private $logger;
private $em;
public function __construct(Twig $view, LoggerInterface $logger, EntityManagerInterface $em)
{
$this->view = $view;
$this->logger = $logger;
$this->em = $em;