Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
@ -4,8 +4,8 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use App\Entity\Intervention;
|
use App\Entity\Intervention;
|
||||||
use App\Form\InterventionType;
|
use App\Form\InterventionType;
|
||||||
|
use App\Form\RemarqueType;
|
||||||
use App\Repository\InterventionRepository;
|
use App\Repository\InterventionRepository;
|
||||||
use App\Repository\UserRepository;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -25,16 +25,12 @@ class InterventionController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/new', name: 'app_intervention_new', methods: ['GET', 'POST'])]
|
#[Route('/new', name: 'app_intervention_new', methods: ['GET', 'POST'])]
|
||||||
public function new(Request $request, EntityManagerInterface $entityManager, InterventionRepository $interventionRepository, UserRepository $userRepository): Response
|
public function new(Request $request, EntityManagerInterface $entityManager, InterventionRepository $interventionRepository): Response
|
||||||
{
|
{
|
||||||
$this->denyUnlessAdminOrSecretaire();
|
$this->denyUnlessAdminOrSecretaire();
|
||||||
|
|
||||||
$intervention = new Intervention();
|
$intervention = new Intervention();
|
||||||
$users = $userRepository->findAll();
|
$form = $this->createForm(InterventionType::class, $intervention);
|
||||||
|
|
||||||
$form = $this->createForm(InterventionType::class, $intervention, [
|
|
||||||
'users' => $users,
|
|
||||||
]);
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
@ -79,16 +75,43 @@ class InterventionController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/mes-interventions', name: 'app_intervention_mes', methods: ['GET'])]
|
||||||
|
public function mesInterventions(InterventionRepository $interventionRepository): Response
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('ROLE_CHAUFFAGISTE');
|
||||||
|
|
||||||
|
$user = $this->getUser();
|
||||||
|
$interventions = $interventionRepository->findBy(['user' => $user]);
|
||||||
|
|
||||||
|
return $this->render('intervention/indexChauffagiste.html.twig', [
|
||||||
|
'interventions' => $interventions,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/{id}', name: 'app_intervention_show', methods: ['GET'])]
|
||||||
|
public function show(Intervention $intervention): Response
|
||||||
|
{
|
||||||
|
// ✅ Si l'utilisateur est un chauffagiste, il ne peut voir que ses interventions
|
||||||
|
if ($this->isGranted('ROLE_CHAUFFAGISTE')) {
|
||||||
|
if ($intervention->getUser() !== $this->getUser()) {
|
||||||
|
throw $this->createAccessDeniedException('Accès refusé à cette intervention.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// ✅ Sinon, seuls admin/secrétaire peuvent accéder à tout
|
||||||
|
$this->denyUnlessAdminOrSecretaire();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('intervention/show.html.twig', [
|
||||||
|
'intervention' => $intervention,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
#[Route('/{id}/edit', name: 'app_intervention_edit', methods: ['GET', 'POST'])]
|
#[Route('/{id}/edit', name: 'app_intervention_edit', methods: ['GET', 'POST'])]
|
||||||
public function edit(Request $request, Intervention $intervention, EntityManagerInterface $entityManager, InterventionRepository $interventionRepository, UserRepository $userRepository): Response
|
public function edit(Request $request, Intervention $intervention, EntityManagerInterface $entityManager, InterventionRepository $interventionRepository): Response
|
||||||
{
|
{
|
||||||
$this->denyUnlessAdminOrSecretaire();
|
$this->denyUnlessAdminOrSecretaire();
|
||||||
|
|
||||||
$users = $userRepository->findAll();
|
$form = $this->createForm(InterventionType::class, $intervention);
|
||||||
|
|
||||||
$form = $this->createForm(InterventionType::class, $intervention, [
|
|
||||||
'users' => $users,
|
|
||||||
]);
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
@ -120,7 +143,7 @@ class InterventionController extends AbstractController
|
|||||||
->andWhere('i.vehicle = :vehicule')
|
->andWhere('i.vehicle = :vehicule')
|
||||||
->andWhere('i != :current')
|
->andWhere('i != :current')
|
||||||
->setParameter('time', $timestamp)
|
->setParameter('time', $timestamp)
|
||||||
->setParameter('vehicule', $vehicule)
|
->setParameter('user', $chauffagiste)
|
||||||
->setParameter('current', $intervention)
|
->setParameter('current', $intervention)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();
|
||||||
@ -144,35 +167,6 @@ class InterventionController extends AbstractController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/mes-interventions', name: 'app_intervention_mes', methods: ['GET'])]
|
|
||||||
public function mesInterventions(InterventionRepository $interventionRepository): Response
|
|
||||||
{
|
|
||||||
$this->denyAccessUnlessGranted('ROLE_CHAUFFAGISTE');
|
|
||||||
|
|
||||||
$user = $this->getUser();
|
|
||||||
$interventions = $interventionRepository->findBy(['user' => $user]);
|
|
||||||
|
|
||||||
return $this->render('intervention/indexChauffagiste.html.twig', [
|
|
||||||
'interventions' => $interventions,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/{id}', name: 'app_intervention_show', methods: ['GET'])]
|
|
||||||
public function show(Intervention $intervention): Response
|
|
||||||
{
|
|
||||||
if ($this->isGranted('ROLE_CHAUFFAGISTE')) {
|
|
||||||
if ($intervention->getUser() !== $this->getUser()) {
|
|
||||||
throw $this->createAccessDeniedException('Accès refusé à cette intervention.');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->denyUnlessAdminOrSecretaire();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('intervention/show.html.twig', [
|
|
||||||
'intervention' => $intervention,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/{id}', name: 'app_intervention_delete', methods: ['POST'])]
|
#[Route('/{id}', name: 'app_intervention_delete', methods: ['POST'])]
|
||||||
public function delete(Request $request, Intervention $intervention, EntityManagerInterface $entityManager): Response
|
public function delete(Request $request, Intervention $intervention, EntityManagerInterface $entityManager): Response
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,7 @@ use App\Entity\Intervention;
|
|||||||
use App\Entity\Stock;
|
use App\Entity\Stock;
|
||||||
use App\Entity\Utilisateur;
|
use App\Entity\Utilisateur;
|
||||||
use App\Entity\Vehicle;
|
use App\Entity\Vehicle;
|
||||||
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||||
@ -18,18 +19,6 @@ class InterventionType extends AbstractType
|
|||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
{
|
{
|
||||||
$intervention = $builder->getData();
|
|
||||||
$allUsers = $options['users'] ?? [];
|
|
||||||
|
|
||||||
$chauffagistes = array_filter($allUsers, fn(Utilisateur $user) =>
|
|
||||||
in_array('ROLE_CHAUFFAGISTE', $user->getRoles(), true)
|
|
||||||
);
|
|
||||||
|
|
||||||
$currentUser = $intervention->getUser();
|
|
||||||
if ($currentUser && !in_array($currentUser, $chauffagistes, true)) {
|
|
||||||
$chauffagistes[] = $currentUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
$builder
|
$builder
|
||||||
->add('Wording', TextType::class)
|
->add('Wording', TextType::class)
|
||||||
->add('Timestamp', DateTimeType::class, [
|
->add('Timestamp', DateTimeType::class, [
|
||||||
@ -40,11 +29,15 @@ class InterventionType extends AbstractType
|
|||||||
->add('Status', TextType::class)
|
->add('Status', TextType::class)
|
||||||
->add('user', EntityType::class, [
|
->add('user', EntityType::class, [
|
||||||
'class' => Utilisateur::class,
|
'class' => Utilisateur::class,
|
||||||
'choice_label' => fn(Utilisateur $user) => $user->getFirstName() . ' ' . $user->getLastName(),
|
'choice_label' => function (Utilisateur $user) {
|
||||||
'choices' => $chauffagistes,
|
return $user->getFirstName() . ' ' . $user->getLastName();
|
||||||
|
},
|
||||||
|
'query_builder' => function (EntityRepository $er) {
|
||||||
|
return $er->createQueryBuilder('u')
|
||||||
|
->where('JSON_CONTAINS(u.roles, :role) = 1')
|
||||||
|
->setParameter('role', '"ROLE_CHAUFFAGISTE"');
|
||||||
|
},
|
||||||
'label' => 'Chauffagiste assigné',
|
'label' => 'Chauffagiste assigné',
|
||||||
'placeholder' => 'Sélectionnez un chauffagiste',
|
|
||||||
'required' => true,
|
|
||||||
])
|
])
|
||||||
->add('fault', EntityType::class, [
|
->add('fault', EntityType::class, [
|
||||||
'class' => Fault::class,
|
'class' => Fault::class,
|
||||||
@ -67,7 +60,6 @@ class InterventionType extends AbstractType
|
|||||||
{
|
{
|
||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'data_class' => Intervention::class,
|
'data_class' => Intervention::class,
|
||||||
'users' => [],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,7 @@
|
|||||||
{% if is_granted('ROLE_SECRETAIRE') %}
|
{% if is_granted('ROLE_SECRETAIRE') %}
|
||||||
<li><a href="{{ path('secretaire_dashboard') }}">Dashboard Secrétaire</a></li>
|
<li><a href="{{ path('secretaire_dashboard') }}">Dashboard Secrétaire</a></li>
|
||||||
<li><a href="{{ path('app_intervention_index') }}">Gérer les interventions</a></li>
|
<li><a href="{{ path('app_intervention_index') }}">Gérer les interventions</a></li>
|
||||||
|
<li><a href="{{ path('app_user_index') }}">Créer un chauffagiste</a></li>
|
||||||
<li><a href="{{ path('app_vehicle_index') }}">Gérer les véhicules</a></li>
|
<li><a href="{{ path('app_vehicle_index') }}">Gérer les véhicules</a></li>
|
||||||
<li><a href="{{ path('app_stock_index') }}">Gérer les stocks</a></li>
|
<li><a href="{{ path('app_stock_index') }}">Gérer les stocks</a></li>
|
||||||
<li><a href="{{ path('app_fault_index') }}">Gérer les pannes</a></li>
|
<li><a href="{{ path('app_fault_index') }}">Gérer les pannes</a></li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user