Ongoing - RepresentationController.php

Ongoing - AffectationController.php
This commit is contained in:
ASTIER Yann 2024-12-06 07:57:39 +01:00
parent fab5249ac5
commit ebc0a27382
18 changed files with 479 additions and 8 deletions

View File

@ -37,6 +37,9 @@ security:
# https://symfony.com/doc/current/security/impersonating_user.html
# switch_user: true
role_hierarchy:
ROLE_ADMIN: ['ROLE_USER']
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:

View File

@ -2,17 +2,95 @@
namespace App\Controller;
use App\Entity\Employee;
use App\Entity\Representation;
use App\Entity\Ride;
use App\Form\RepresentationType;
use App\Repository\RepresentationRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class RepresentationController extends AbstractController
#[Route('/representation', name: 'representation')]
final class RepresentationController extends AbstractController
{
#[Route('/representation', name: 'app_representation')]
public function index(): Response
public function __toString(): string
{
// TODO: Implement __toString() method.
return "";
}
#[Route(name: '_index', methods: ['GET'])]
public function index(RepresentationRepository $representationRepository): Response
{
return $this->render('representation/index.html.twig', [
'controller_name' => 'RepresentationController',
'representations' => $representationRepository->findAll(),
]);
}
#[Route('/new', name: '_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$representation = new Representation();
$form = $this->createForm(RepresentationType::class, $representation);
$form->handleRequest($request);
// $employee = $entityManager->getRepository(Employee::class)->findOneBy(['email' => $this->getUser()->getEmail()]);
// $ride = $entityManager->getRepository(Ride::class)->findOneBy(['id' => $form->get('ride')->getData()]);
if ($form->isSubmitted() && $form->isValid()) {
// $representation->setEmployee($employee);
// $representation->setRide($ride);
dd($representation);
$entityManager->persist($representation);
// $entityManager->flush();
//
// return $this->redirectToRoute('representation_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('representation/new.html.twig', [
'representation' => $representation,
'form' => $form,
]);
}
#[Route('/{employee}', name: '_show', methods: ['GET'])]
public function show(Representation $representation): Response
{
return $this->render('representation/show.html.twig', [
'representation' => $representation,
]);
}
#[Route('/{employee}/edit', name: '_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Representation $representation, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(RepresentationType::class, $representation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('representation_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('representation/edit.html.twig', [
'representation' => $representation,
'form' => $form,
]);
}
#[Route('/{employee}', name: '_delete', methods: ['POST'])]
public function delete(Request $request, Representation $representation, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$representation->getEmployee(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($representation);
$entityManager->flush();
}
return $this->redirectToRoute('representation_index', [], Response::HTTP_SEE_OTHER);
}
}

View File

@ -0,0 +1,100 @@
<?php
namespace App\Controller;
use App\Entity\Ride;
use App\Form\RideType;
use App\Repository\RideRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/ride', name: 'ride')]
final class RideController extends AbstractController
{
#[Route(name: '_index', methods: ['GET'])]
public function index(RideRepository $rideRepository): Response
{
return $this->render('ride/index.html.twig', [
'rides' => $rideRepository->findAll(),
]);
}
#[Route('/new', name: '_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$ride = new Ride();
$form = $this->createForm(RideType::class, $ride);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($ride);
$entityManager->flush();
return $this->redirectToRoute('ride_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('ride/new.html.twig', [
'ride' => $ride,
'form' => $form,
]);
}
#[Route('/{id}', name: '_show', methods: ['GET'])]
public function show(Ride $ride): Response
{
return $this->render('ride/show.html.twig', [
'ride' => $ride,
]);
}
#[Route('/{id}/edit', name: '_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Ride $ride, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(RideType::class, $ride);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('ride_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('ride/edit.html.twig', [
'ride' => $ride,
'form' => $form,
]);
}
#[Route('/{id}/increment', name: '_increment', methods: ['GET', 'POST'])]
public function incrementCount(Request $request, Ride $ride, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(RideType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$ride->setCount($ride->getCount() + 15);
$entityManager->persist($ride);
$entityManager->flush();
}
return $this->redirectToRoute('ride_show', ['id' => $ride->getId()], Response::HTTP_SEE_OTHER);
}
#[Route('/{id}', name: '_delete', methods: ['POST'])]
public function delete(Request $request, Ride $ride, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$ride->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($ride);
$entityManager->flush();
}
return $this->redirectToRoute('ride_index', [], Response::HTTP_SEE_OTHER);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace App\Form;
use App\Entity\Employee;
use App\Entity\Representation;
use App\Entity\Ride;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RepresentationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('employee', EntityType::class, [
'class' => Employee::class,
'choice_label' => 'email',
])
->add('ride', EntityType::class, [
'class' => Ride::class,
'choice_label' => 'label',
])
->add('count')
->add('date', null, [
'widget' => 'single_text',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Representation::class,
]);
}
}

37
src/Form/RideType.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace App\Form;
use App\Entity\IncidentType;
use App\Entity\Mission;
use App\Entity\Ride;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RideType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('label')
->add('count')
->add('incidentTypes', EntityType::class, [
'class' => IncidentType::class,
'choice_label' => 'id',
])
->add('missions', EntityType::class, [
'class' => Mission::class,
'choice_label' => 'id',
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Ride::class,
]);
}
}

View File

@ -24,7 +24,7 @@
<nav class="navbar navbar-expand-lg navbar-dark p-3 m-2 rounded hegre-navbar">
<a class="navbar-brand " href="#">
<img src="https://getbootstrap.com/docs/4.4/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top" alt="">
HergeLand
HegreLand
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
@ -34,14 +34,18 @@
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Dashboard<span class="sr-only"></span></a>
<a class="nav-link" href="{{ path('dashboard') }}">Dashboard<span class="sr-only"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Attractions</a>
<a class="nav-link" href="{{ path('ride_index') }}">Attractions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Employées</a>
<a class="nav-link" href="{{ path('representation_index') }}">Représentation</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('employee_index') }}">Employées</a>
</li>
</ul>
</div>

View File

@ -0,0 +1,4 @@
<form method="post" action="{{ path('app_representation_delete', {'employee': representation.employee}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ representation.employee) }}">
<button class="btn">Delete</button>
</form>

View File

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View File

@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit Representation{% endblock %}
{% block body %}
<h1>Edit Representation</h1>
{{ include('representation/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('representation_index') }}">back to list</a>
{{ include('representation/_delete_form.html.twig') }}
{% endblock %}

View File

@ -0,0 +1,39 @@
{% extends 'base.html.twig' %}
{% block title %}Representation index{% endblock %}
{% block body %}
<h1>Representation index</h1>
<table class="table">
<thead>
<tr>
<th>Employee</th>
<th>Ride</th>
<th>Count</th>
<th>Date</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for representation in representations %}
<tr>
<td>{{ representation.employee }}</td>
<td>{{ representation.ride }}</td>
<td>{{ representation.count }}</td>
<td>{{ representation.date ? representation.date|date('Y-m-d H:i:s') : '' }}</td>
<td>
<a href="{{ path('representation_show', {'employee': representation.employee}) }}">show</a>
<a href="{{ path('representation_edit', {'employee': representation.employee}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="5">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('representation_new') }}">Create new</a>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New Representation{% endblock %}
{% block body %}
<h1>Create new Representation</h1>
{{ include('representation/_form.html.twig') }}
<a href="{{ path('representation_index') }}">back to list</a>
{% endblock %}

View File

@ -0,0 +1,34 @@
{% extends 'base.html.twig' %}
{% block title %}Representation{% endblock %}
{% block body %}
<h1>Representation</h1>
<table class="table">
<tbody>
<tr>
<th>Employee</th>
<td>{{ representation.employee }}</td>
</tr>
<tr>
<th>Ride</th>
<td>{{ representation.ride }}</td>
</tr>
<tr>
<th>Count</th>
<td>{{ representation.count }}</td>
</tr>
<tr>
<th>Date</th>
<td>{{ representation.date ? representation.date|date('Y-m-d H:i:s') : '' }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('representation_index') }}">back to list</a>
<a href="{{ path('representation_edit', {'employee': representation.employee}) }}">edit</a>
{{ include('representation/_delete_form.html.twig') }}
{% endblock %}

View File

@ -0,0 +1,4 @@
<form method="post" action="{{ path('ride_delete', {'id': ride.id}) }}" onsubmit="return confirm('Are you sure you want to delete this item?');">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ ride.id) }}">
<button class="btn">Delete</button>
</form>

View File

@ -0,0 +1,4 @@
{{ form_start(form) }}
{{ form_widget(form) }}
<button class="btn">{{ button_label|default('Save') }}</button>
{{ form_end(form) }}

View File

@ -0,0 +1,13 @@
{% extends 'base.html.twig' %}
{% block title %}Edit Ride{% endblock %}
{% block body %}
<h1>Edit Ride</h1>
{{ include('ride/_form.html.twig', {'button_label': 'Update'}) }}
<a href="{{ path('ride_index') }}">back to list</a>
{{ include('ride/_delete_form.html.twig') }}
{% endblock %}

View File

@ -0,0 +1,37 @@
{% extends 'base.html.twig' %}
{% block title %}Ride index{% endblock %}
{% block body %}
<h1>Ride index</h1>
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Label</th>
<th>Count</th>
<th>actions</th>
</tr>
</thead>
<tbody>
{% for ride in rides %}
<tr>
<td>{{ ride.id }}</td>
<td>{{ ride.label }}</td>
<td>{{ ride.count }}</td>
<td>
<a href="{{ path('ride_show', {'id': ride.id}) }}">show</a>
<a href="{{ path('ride_edit', {'id': ride.id}) }}">edit</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="4">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
<a href="{{ path('ride_new') }}">Create new</a>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html.twig' %}
{% block title %}New Ride{% endblock %}
{% block body %}
<h1>Create new Ride</h1>
{{ include('ride/_form.html.twig') }}
<a href="{{ path('ride_index') }}">back to list</a>
{% endblock %}

View File

@ -0,0 +1,36 @@
{% extends 'base.html.twig' %}
{% block title %}Ride{% endblock %}
{% block body %}
<h1>Ride</h1>
<table class="table">
<tbody>
<tr>
<th>Id</th>
<td>{{ ride.id }}</td>
</tr>
<tr>
<th>Label</th>
<td>{{ ride.label }}</td>
</tr>
<tr>
<th>Count</th>
<td>{{ ride.count }}</td>
</tr>
</tbody>
</table>
<a href="{{ path('ride_index') }}">back to list</a>
<a href="{{ path('ride_edit', {'id': ride.id}) }}">edit</a>
<form method="post" action="{{ path('ride_increment', {'id': ride.id}) }}" onsubmit="return confirm('Attraction complète ?');">
{{ include('ride/_delete_form.html.twig') }}
{% endblock %}