Commit 6e345ef0 authored by Patrick Etcheverry's avatar Patrick Etcheverry

- Implémentation de la possibilité de gérer les différents scénarios pédagogiques

parent 4fd918d8
......@@ -6,6 +6,9 @@ use ScenarioBundle\Entity\Formation;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use ScenarioBundle\Entity\PedagogicalScenario;
use ScenarioBundle\Entity\PedagogicalScenarioFormation;
/**
* Formation controller.
*
......@@ -133,4 +136,104 @@ class FormationController extends Controller
->getForm()
;
}
/**
* Permit to manage the pedagogical scenarios of a Formation
*
* @param Formation $formation The formation entity
*
*/
public function pedagogicalScenarioManagementAction(Formation $formation)
{
$em = $this->getDoctrine()->getManager();
/*$queryBuilder = $em->getRepository('ScenarioBundle:PedagogicalScenario')->createQueryBuilder('pedagogicalScenarios');
$query = $queryBuilder->getQuery();
$paginator = $this->get('knp_paginator');
$pedagogicalScenarios = $paginator->paginate(
$query,
$request->query->getInt('page', 1), // page number
5 // limit per page
);*/
// On récupère la liste des scénarios pédagogiques de la formation courante
$scenariosPedagogiquesAlreadyLinked = $em->createQuery ('
select ps, psf, f
FROM ScenarioBundle:PedagogicalScenario ps
JOIN ps.pedagogicalScenarioFormation psf
JOIN psf.formation f
WHERE psf.formation = :formation');
$scenariosPedagogiquesAlreadyLinked->setParameter('formation', $formation);
// On récupère la liste des scénario pédagogiques qui ne sont pas dans la formation courante
$scenariosPedagogiquesAvailable = $em->createQuery ('
select pss
FROM ScenarioBundle:PedagogicalScenario pss
WHERE pss NOT IN (select ps
FROM ScenarioBundle:PedagogicalScenario ps
JOIN ps.pedagogicalScenarioFormation psf
JOIN psf.formation f
WHERE psf.formation = :formation)');
$scenariosPedagogiquesAvailable->setParameter('formation', $formation);
$pedagogicalScenariosAvailable = $scenariosPedagogiquesAvailable->getResult();
$pedagogicalScenariosAlreadyLinked = $scenariosPedagogiquesAlreadyLinked->getResult();
return $this->render('ScenarioBundle:formation:pedagogicalscenariomanagement.html.twig', array(
'pedagogicalScenariosAvailable' => $pedagogicalScenariosAvailable,
'pedagogicalScenariosAlreadyLinked' => $pedagogicalScenariosAlreadyLinked,
'formation' => $formation
));
}
/**
* Add a PedagogicalScenario in a Formation
*
* @param Formation $formation The formation entity
* @param Formation $formation The pedagogical scenario entity
*/
public function addPedagogicalScenarioAction(Formation $formation, PedagogicalScenario $pedagogicalScenario)
{
$em = $this->getDoctrine()->getManager();
$pedagogicalScenarioFormation = new PedagogicalScenarioFormation();
$formation->addPedagogicalScenarioFormation($pedagogicalScenarioFormation);
$pedagogicalScenario->addPedagogicalScenarioFormation($pedagogicalScenarioFormation);
$em->persist($pedagogicalScenarioFormation);
$em->flush();
return $this->redirectToRoute('formation_pedagogical_scenario_management', array('userRole' => 'pedagogical-engineer', 'id' => $formation->getId()));
}
/**
* Delete a PedagogicalScenario from a Formation
*
* @param Formation $formation The formation entity
* @param Formation $formation The pedagogical scenario entity
*/
public function deletePedagogicalScenarioAction(Formation $formation, PedagogicalScenario $pedagogicalScenario)
{
$em = $this->getDoctrine()->getManager();
$dql_pedagogicalScenarioFormation = $em->createQuery('SELECT psf
FROM ScenarioBundle:PedagogicalScenarioFormation psf
WHERE psf.formation = :formationId AND psf.pedagogicalScenario = :pedagogicalScenarioId');
$dql_pedagogicalScenarioFormation->setParameter('formationId',$formation->getId());
$dql_pedagogicalScenarioFormation->setParameter('pedagogicalScenarioId',$pedagogicalScenario->getId());
$pedagogicalScenarioFormation = $dql_pedagogicalScenarioFormation->getOneOrNullResult();
$formation->removePedagogicalScenarioFormation($pedagogicalScenarioFormation);
$pedagogicalScenario->removePedagogicalScenarioFormation($pedagogicalScenarioFormation);
$em->remove($pedagogicalScenarioFormation);
$em->flush();
return $this->redirectToRoute('formation_pedagogical_scenario_management', array('userRole' => 'pedagogical-engineer', 'id' => $formation->getId()));
}
}
......@@ -337,7 +337,7 @@ class PedagogicalScenario
}
/**
* Remove pedagogicalScenarioFormation
* Delete pedagogicalScenarioFormation
*
* @param \ScenarioBundle\Entity\PedagogicalScenarioFormation PedagogicalScenarioFormation
*/
......
......@@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
/**
* PedagogicalScenarioFormation
*
* @ORM\Table(name="pedagogical_Scenario_formation")
* @ORM\Table(name="pedagogical_scenario_formation", uniqueConstraints={@ORM\UniqueConstraint(name="pedagogical_scenario_already_include", columns={"formation_id", "pedagogical_scenario_id"})})
* @ORM\Entity(repositoryClass="ScenarioBundle\Repository\PedagogicalScenarioFormationRepository")
*/
class PedagogicalScenarioFormation
......
......@@ -22,3 +22,18 @@ formation_delete:
path: /{id}/delete
defaults: { _controller: "ScenarioBundle:Formation:delete" }
methods: DELETE
formation_pedagogical_scenario_management:
path: /{id}/pedagogical-scenario/
defaults: { _controller: "ScenarioBundle:Formation:pedagogicalScenarioManagement" }
methods: GET
formation_pedagogical_scenario_delete:
path: /{id}/pedagogical-scenario/{pedagogicalScenario}/delete
defaults: { _controller: "ScenarioBundle:Formation:deletePedagogicalScenario" }
methods: GET
formation_pedagogical_scenario_add:
path: /{id}/pedagogical-scenario/{pedagogicalScenario}/add
defaults: { _controller: "ScenarioBundle:Formation:addPedagogicalScenario" }
methods: GET
......@@ -18,7 +18,6 @@
<td>{{ formation.fullname }}</td>
<td>
<ul>
{% dump(currentRole) %}
<li>
<a href="{{ path('formation_show', { 'id': formation.id, 'userRole': currentRole }) }}">{{ 'show'|trans }}</a>
</li>
......@@ -26,6 +25,9 @@
<li>
<a href="{{ path('formation_edit', { 'id': formation.id, 'userRole': currentRole }) }}">{{ 'edit'|trans }}</a>
</li>
<li>
<a href="{{ path('formation_pedagogical_scenario_management', { 'id': formation.id, 'userRole': currentRole } ) }}">AJOUTER UN SCENARIO PEDAGOGIQUE</a>
</li>
{% endif %}
</ul>
</td>
......
{% extends 'base.html.twig' %}
{% block body %}
<h1>Gestion des scénarios pédagoiques d'une formation</h1>
Formation courante : {{ formation.shortname }}
<hr/>
{% if pedagogicalScenariosAlreadyLinked is not empty %}
<p> Liste des scénarios pédagogiques déjà liés </p>
<table class="table">
<thead>
<tr>
<th>{{ 'shortname'|trans }}</th>
<th>{{ 'fullname'|trans }}</th>
<th>{{ 'actions'|trans }}</th>
</tr>
</thead>
<tbody>
{% for pedagogicalScenario in pedagogicalScenariosAlreadyLinked %}
<tr>
<td>{{ pedagogicalScenario.shortname }}</td>
<td>{{ pedagogicalScenario.fullname }}</td>
<td><a href="{{ path('formation_pedagogical_scenario_delete', {'userRole': currentRole, 'id' : formation.id, 'pedagogicalScenario' : pedagogicalScenario.id}) }}">{{ 'Delete'|trans}}</a></td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p> La formation courante ne possède aucun scénario pédagogique </p>
{% endif %}
{% if pedagogicalScenariosAvailable is not empty %}
<p> Liste des scénarios pédagogiques disponibles </p>
<table class="table">
<thead>
<tr>
<th>{{ 'shortname'|trans }}</th>
<th>{{ 'fullname'|trans }}</th>
<th>{{ 'actions'|trans }}</th>
</tr>
</thead>
<tbody>
{% for pedagogicalScenario in pedagogicalScenariosAvailable %}
<tr>
<td>{{ pedagogicalScenario.shortname }}</td>
<td>{{ pedagogicalScenario.fullname }}</td>
<td><a href="{{ path('formation_pedagogical_scenario_add', {'userRole': currentRole, 'id' : formation.id, 'pedagogicalScenario' : pedagogicalScenario.id}) }}">{{ 'Add'|trans}}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p> Aucun scénario pédagogique de disponible </p>
{% endif %}
{% endblock %}
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