Compare commits
No commits in common. "master" and "feature/Maxim" have entirely different histories.
master
...
feature/Ma
@ -4,8 +4,8 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\Intervention;
|
||||
use App\Form\InterventionType;
|
||||
use App\Form\RemarqueType;
|
||||
use App\Repository\InterventionRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@ -25,16 +25,12 @@ class InterventionController extends AbstractController
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
$intervention = new Intervention();
|
||||
$users = $userRepository->findAll();
|
||||
|
||||
$form = $this->createForm(InterventionType::class, $intervention, [
|
||||
'users' => $users,
|
||||
]);
|
||||
$form = $this->createForm(InterventionType::class, $intervention);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@ -79,16 +75,21 @@ class InterventionController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_intervention_show', methods: ['GET'])]
|
||||
public function show(Intervention $intervention): Response
|
||||
{
|
||||
$this->denyUnlessAdminOrSecretaire();
|
||||
return $this->render('intervention/show.html.twig', [
|
||||
'intervention' => $intervention,
|
||||
]);
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
$users = $userRepository->findAll();
|
||||
|
||||
$form = $this->createForm(InterventionType::class, $intervention, [
|
||||
'users' => $users,
|
||||
]);
|
||||
$form = $this->createForm(InterventionType::class, $intervention);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@ -120,7 +121,7 @@ class InterventionController extends AbstractController
|
||||
->andWhere('i.vehicle = :vehicule')
|
||||
->andWhere('i != :current')
|
||||
->setParameter('time', $timestamp)
|
||||
->setParameter('vehicule', $vehicule)
|
||||
->setParameter('user', $chauffagiste)
|
||||
->setParameter('current', $intervention)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
@ -144,35 +145,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'])]
|
||||
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\Utilisateur;
|
||||
use App\Entity\Vehicle;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
@ -18,18 +19,6 @@ class InterventionType extends AbstractType
|
||||
{
|
||||
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
|
||||
->add('Wording', TextType::class)
|
||||
->add('Timestamp', DateTimeType::class, [
|
||||
@ -40,11 +29,15 @@ class InterventionType extends AbstractType
|
||||
->add('Status', TextType::class)
|
||||
->add('user', EntityType::class, [
|
||||
'class' => Utilisateur::class,
|
||||
'choice_label' => fn(Utilisateur $user) => $user->getFirstName() . ' ' . $user->getLastName(),
|
||||
'choices' => $chauffagistes,
|
||||
'choice_label' => function (Utilisateur $user) {
|
||||
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é',
|
||||
'placeholder' => 'Sélectionnez un chauffagiste',
|
||||
'required' => true,
|
||||
])
|
||||
->add('fault', EntityType::class, [
|
||||
'class' => Fault::class,
|
||||
@ -67,7 +60,6 @@ class InterventionType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => Intervention::class,
|
||||
'users' => [],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -107,6 +107,7 @@
|
||||
{% if is_granted('ROLE_SECRETAIRE') %}
|
||||
<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_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_stock_index') }}">Gérer les stocks</a></li>
|
||||
<li><a href="{{ path('app_fault_index') }}">Gérer les pannes</a></li>
|
||||
@ -116,7 +117,8 @@
|
||||
|
||||
{% if is_granted('ROLE_CHAUFFAGISTE') %}
|
||||
<li><a href="{{ path('chauffagiste_dashboard') }}">Dashboard Chauffagiste</a></li>
|
||||
<li><a href="{{ path('app_intervention_mes') }}">Mes interventions</a></li>
|
||||
<li><a href="{{ path('app_intervention_index') }}">Mes interventions</a></li>
|
||||
<li><a href="{{ path('app_stock_index') }}">Pièces détachées</a></li>
|
||||
<li><a href="{{ path('app_calendrier_indexChauffagiste') }}">Mon planning</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
@ -1,38 +0,0 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Mes interventions{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>📋 Mes interventions</h1>
|
||||
|
||||
{% if interventions is not empty %}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Description</th>
|
||||
<th>Adresse</th>
|
||||
<th>Statut</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for intervention in interventions %}
|
||||
<tr>
|
||||
<td>{{ intervention.Timestamp ? intervention.Timestamp|date('d/m/Y H:i') : '' }}</td>
|
||||
<td>{{ intervention.Description }}</td>
|
||||
<td>{{ intervention.Address }}</td>
|
||||
<td>{{ intervention.Status }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_intervention_show', {'id': intervention.id}) }}" class="btn btn-primary btn-sm">
|
||||
Voir
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>Vous n’avez aucune intervention assignée.</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -63,13 +63,14 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% if is_granted('ROLE_CHAUFFAGISTE') and intervention.user == app.user %}
|
||||
<a href="{{ path('app_intervention_remarque', {'id': intervention.id}) }}" class="btn btn-outline-primary">
|
||||
📝 Ajouter une remarque
|
||||
</a>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% if is_granted('ROLE_CHAUFFAGISTE') and intervention.user == app.user %}
|
||||
<a href="{{ path('app_intervention_remarque', {'id': intervention.id}) }}" class="btn btn-outline-primary">
|
||||
📝 Ajouter une remarque
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ path('app_intervention_index') }}" class="btn btn-primary">Retour à la liste</a>
|
||||
<a href="{{ path('app_intervention_edit', {'id': intervention.id}) }}" class="btn btn-warning">Modifier</a>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user