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

Inscription Formation (dasboard Participant)

parent 0de5aaf1
......@@ -64,8 +64,8 @@ $container[App\Action\DashboardInscriptionAction::class] = function ($c) {
return new App\Action\DashboardInscriptionAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardInscriptionFormationAction::class] = function ($c) {
return new App\Action\DashboardInscriptionFormationAction($c->get('view'), $c->get('logger'), $c->get('em'));
$container[App\Action\ParticipantInscriptionFormationAction::class] = function ($c) {
return new App\Action\ParticipantInscriptionFormationAction($c->get('view'), $c->get('logger'), $c->get('em'));
};
$container[App\Action\DashboardParcoursAction::class] = function ($c) {
......
......@@ -47,7 +47,7 @@ $app->get('/dashboard-inscription', App\Action\DashboardInscriptionAction::class
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_inscription');
$app->post('/dashboard-inscription-formation', App\Action\DashboardInscriptionFormationAction::class)
$app->map(['GET', 'POST'],'/dashboard-inscription-formation', App\Action\ParticipantInscriptionFormationAction::class)
->add(App\Middleware\TokenMiddleware::class)
->setName('dashboard_inscription_formation');
......
......@@ -41,16 +41,12 @@ final class DashboardInscriptionAction
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']);
$agendas = $this->getAgendas($params['jour'],$params['debut'],$params['fin'],$participant->getId());
$a['agendas'] = $agendas;
//var_dump($agendas);
//exit();
//foreach ($agendas as $agenda){
// $inscriptions = $this->getInscriptionAgenda($agenda->getId());
//}
//$a['inscriptions'] = $inscriptions;
}
// ajouter la possibilité de s'inscrire QUE si pas d'inscription su la demi-journée
}
$this->view->render($response, 'dashboard_inscription.twig', $a);
return $response;
......@@ -69,22 +65,29 @@ final class DashboardInscriptionAction
}
}
public function getAgendas($jour,$debut,$fin) {
//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,(select count(pa) from App\Entity\ParticipantAgenda pa where pa.agenda=a.id) as nb_inscrits FROM App\Entity\Agenda a ";
$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 .= "(select count(p3) from App\Entity\ParticipantAgenda p3 where p3.participant=$id) as inscrit ";
$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($id_agenda) {
public function getInscriptionAgenda($id_participant) {
//$dql = "SELECT a FROM App\Entity\ParticipantAgenda a LEFT JOIN a.participants p WHERE a.agenda = $id_agenda";
$dql = "SELECT count(pa) FROM App\Entity\ParticipantAgenda pa WHERE pa.agenda = $id_agenda";
$dql = "SELECT count(pa) FROM App\Entity\ParticipantAgenda pa WHERE pa.participant = $id_participant";
$query = $this->em->createQuery($dql);
return $query->getArrayResult();
return $query->getResult();
}
}
......@@ -12,46 +12,59 @@ final class ParticipantInscriptionFormationAction
private $view;
private $logger;
private $em;
private $mailer;
public function __construct(Twig $view, LoggerInterface $logger, EntityManagerInterface $em)
{
$this->view = $view;
$this->logger = $logger;
$this->em = $em;
$this->view = $view;
$this->logger = $logger;
$this->em = $em;
}
public function __invoke(Request $request, Response $response, $args)
{
$this->logger->info("inscription formation page action dispatched");
{
$this->logger->info("dashboard page action dispatched");
$params = $request->getQueryParams();
$token = $params['token'];
$email = $request->getAttribute('email');
$participant = $this->getParticipant($email);
$params = $request->getQueryParams();
$token = $params['token'];
$id_agenda = (int) $params['agenda'];
$valid = $params['valid'];
$email = $request->getAttribute('email');
$a = [
'page' => 'dashboard-inscription-formation',
'token' => $token,
'participant' => $participant
];
$participant = $this->getParticipant($email);
$id_participant=(int)$participant->getId();
// Suppression de l'inscription à la formation
if ($valid == 'false') {
$inscription = $this->getInscriptionAgenda($id_participant,$id_agenda);
$participant = $this->getParticipant($params['email']);
if (!$participant) {
return $response->withStatus(400);
}
$this->em->remove($inscription[0]);
$this->em->flush();
}
// Inscription à la formation
if ($valid == 'true') {
$agenda=$this->getAgenda($id_agenda);
$inscription = new \App\Entity\ParticipantAgenda();
$inscription->setParticipant($participant->getId());
$this->em->persist($inscription);
$this->em->flush();
$inscription->setParticipant($participant);
$inscription->setAgenda($agenda[0]);
$ladate=date_create_from_format('d/m/Y H:i', '04/07/17 14:00');
$inscription->setDateInscription($ladate);
//var_dump($agenda[0]);
//exit();
$this->em->persist($inscription);
$this->em->flush();
}
$response = $response->write('Inscription éffectuée')->withStatus(201);
$this->view->render($response, 'dashboard_inscription.twig', [
'page' => 'dashboard',
'token' => $token,
'participant' => $participant
]);
return $response;
}
private function getParticipant($email)
{
$participant = $this->em->getRepository('App\Entity\Participant')->findOneBy(array('email' => $email));
......@@ -62,4 +75,20 @@ final class ParticipantInscriptionFormationAction
}
}
public function getInscriptionAgenda($id_participant,$id_agenda) {
$dql = "SELECT pa FROM App\Entity\ParticipantAgenda pa WHERE pa.participant=$id_participant AND pa.agenda=$id_agenda";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
private function getAgenda($id_agenda)
{
$dql = "SELECT a FROM App\Entity\Agenda a WHERE a.id=$id_agenda";
$query = $this->em->createQuery($dql);
return $query->getResult();
}
}
......@@ -31,11 +31,12 @@ class ParticipantAgenda
**/
private $dateInscription;
public function __construct(Participant $participant, Agenda $agenda)
{
$this->participant = $participant;
$this->agenda = $agenda;
}
//public function __construct(Participant $participant, Agenda $agenda)
//{
// $this->participant = $participant;
// $this->agenda = $agenda;
//}
public function getId()
{
......
......@@ -19,7 +19,7 @@
<input type="hidden" id="token" name="token" value="{{ token }}">
<table width='100%'>
<tr>
<td><a href="dashboard-inscription?token={{ token }}&jour=2017-07-04&debut=08:00:00&fin=13:00:00" id="2017-07-04_am" class="btn btn-info btn-sm btn-block">04 Juillet 2017 - Matin</a></td>
<td><a href="dashboard-inscription?token={{ token }}&jour=2017-07-04&debut=08:00:00&fin=13:00:00" id="2017-07-04_am" class="btn btn-info btn-sm btn-block btn-jour">04 Juillet 2017 - Matin</a></td>
<td><button id="2017-07-05_am" class="btn btn-info btn-sm btn-block">05 Juillet 2017 - Matin</button></td>
<td><button id="2017-07-06_am" class="btn btn-info btn-sm btn-block">07 Juillet 2017 - Matin</button></td>
<td><button id="2017-07-07_am" class="btn btn-info btn-sm btn-block">08 Juillet 2017 - Matin</button></td>
......@@ -44,30 +44,52 @@
<div id="inscription">
{% if agendas %}
<table id="tab_agenda" class="table table-striped table-bordered">
<table id="tab_agenda" class="table table-striped table-bordered">
<thead>
<tr>
<th width="10%">Session</th>
<th width="10%">Intervenant</th>
<th width="10%">Salle</th>
<th width="5%">Début</th>
<th width="5%">Fin</th>
<th width="5%">Quota</th>
<th width="10%" colspan="3" class="text-center">Actions</th>
<th width="5%">Inscrits</th>
<th width="5%">Taux</th>
<th width="10%" class="text-center">Actions</th>
</tr>
</thead>
<tbody>
{% set quota = 0 %}
{% set id_agenda = 0 %}
{% for agenda in agendas %}
<tr>
<td>{{ agenda.getFormation().getNom() }}</td>
<td>{{ agenda.getSalle.getNom() }}</td>
<td>{{ agenda.agenda.getDateDebut() | date("H:i") }}</td>
<td>{{ agenda.dateFin | date("H:i") }}</td>
<td>{{ dump(agenda) }}</td>
{% for a in agenda | slice (0,1)%}
{% set quota=a.getFormation().getQuota() %}
{% set id_agenda=a.getId() %}
<td>{{ a.getFormation().getNom() }}</td>
<td>{{ a.getFormation().getIntervenant() }}</td>
<td>{{ a.getSalle.getNom() }}</td>
<td>{{ a.getDateDebut() | date("H:i") }}</td>
<td>{{ a.getDateFin() | date("H:i") }}</td>
{% endfor %}
<td>{{ agenda.nb_inscrits }}/{{ quota }}</td>
<td>{{ ((agenda.nb_inscrits / quota) * 100) | round }}</td>
<td class="text-center">
<a href="dashboard-inscription-formation?token={{token}}&formation={{agenda.getFormation().getId()}}"
class="btn fa fa-check-square-o btn-success btn-inscription-formation"
data-toggle="tooltip" title="S'inscrire">
{% if agenda.check == 0 %}
{% if agenda.inscrit == 1 %}
-
{% else %}
<a href="dashboard-inscription-formation?token={{token}}&agenda={{id_agenda}}&valid=true"
class="btn fa fa-check-square-o btn-treehouse btn-inscription-formation"
data-toggle="tooltip" title="M'inscrire à cette formation">
</a>
{% endif %}
{% else %}
<a href="dashboard-inscription-formation?token={{token}}&agenda={{id_agenda}}&valid=false"
class="btn fa fa-warning btn-danger btn-delete-inscription-formation"
data-toggle="tooltip" title="Me désinscrire de cette formation">
</a>
{% endif %}
</td>
</tr>
......
......@@ -10,32 +10,55 @@ $(document).ready(function(){
location.reload();
},
error: function() {
alert('PB');
alert('PB inscription');
}
});
}
});
$('#2017-07-05_am').on('click', function(e) {
$('.btn-delete-inscription-formation').on('click', function(e) {
e.preventDefault();
var letoken=$("#token").val();
$.ajax({
url: 'dashboard-inscription?token='+letoken+'&jour=2017-07-04&debut=09&fin=14',
type: 'GET',
datatype : 'json',
success: function(agenda) {
$.each(agenda, function (key, val) {
value=val['id'];
$('#inscription').append(value+'<br>');
});
if (confirm("Confirmez-vous la suppression de votre inscription à cette formation ?")) {
$.ajax({
url: $(this).attr('href'),
type: 'POST',
success: function(text) {
location.reload();
},
error: function() {
alert('PB suppression inscription');
}
});
}
});
$('#tab_agenda').DataTable({
"columnDefs":[
{
"targets" : 0,
"render": function (data) {
return "<b>" + data.toUpperCase() + "</b>";
}
},
error: function() {
alert('PB recupérartion de l\'agenda');
}
});
{
"targets" : 6,
"render": function (data) {
if (data < 50){
return "<span class=\"label label-success\">" + data + "%</span>";
}
if ((data => 50) && (data < 75)){
return "<span class=\"label label-warning\">" + data + "%</span>";
}
if (data => 75){
return "<span class=\"label label-danger\">" + data + "%</span>";
}
}
}
]
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment