Incident commit

This commit is contained in:
colesm 2025-04-04 08:50:54 +02:00
parent fab5249ac5
commit 8eabb71db4
3 changed files with 54 additions and 12 deletions

12
composer.lock generated
View File

@ -6671,16 +6671,16 @@
}, },
{ {
"name": "symfony/twig-bundle", "name": "symfony/twig-bundle",
"version": "v7.1.1", "version": "v7.1.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/twig-bundle.git", "url": "https://github.com/symfony/twig-bundle.git",
"reference": "d48c2f08c2f315e749f0e18fc4945b7be8afe1e5" "reference": "af902314a71fb412ae412094f7e1d7e49594507b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/twig-bundle/zipball/d48c2f08c2f315e749f0e18fc4945b7be8afe1e5", "url": "https://api.github.com/repos/symfony/twig-bundle/zipball/af902314a71fb412ae412094f7e1d7e49594507b",
"reference": "d48c2f08c2f315e749f0e18fc4945b7be8afe1e5", "reference": "af902314a71fb412ae412094f7e1d7e49594507b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -6735,7 +6735,7 @@
"description": "Provides a tight integration of Twig into the Symfony full-stack framework", "description": "Provides a tight integration of Twig into the Symfony full-stack framework",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/twig-bundle/tree/v7.1.1" "source": "https://github.com/symfony/twig-bundle/tree/v7.1.6"
}, },
"funding": [ "funding": [
{ {
@ -6751,7 +6751,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-05-31T14:57:53+00:00" "time": "2024-09-25T14:20:29+00:00"
}, },
{ {
"name": "symfony/type-info", "name": "symfony/type-info",

View File

@ -2,17 +2,58 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Incident;
use App\Form\IncidentType;
use App\Repository\IncidentRepository;
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\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Annotation\Route;
#[Route('/incident', name: 'incident_')]
class IncidentController extends AbstractController class IncidentController extends AbstractController
{ {
#[Route('/incident', name: 'app_incident')] public function __construct(
public function index(): Response private readonly EntityManagerInterface $entityManager
) {
}
#[Route('', name: 'index', methods: ['GET'])]
public function index(IncidentRepository $incidentRepository): Response
{ {
return $this->render('incident/index.html.twig', [ return $this->render('incident/index.html.twig', [
'controller_name' => 'IncidentController', 'incidents' => $incidentRepository->findAll(),
]); ]);
} }
#[Route('/new', name: 'new', methods: ['GET', 'POST'])]
public function new(Request $request): Response
{
$incident = new Incident();
$form = $this->createForm(IncidentType::class, $incident);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($incident);
$this->entityManager->flush();
return $this->redirectToRoute('incident_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('incident/new.html.twig', [
'form' => $form->createView(),
]);
}
#[Route('/{id}', name: 'delete', methods: ['POST'])]
public function delete(Request $request, Incident $incident): Response
{
if ($this->isCsrfTokenValid('delete'.$incident->getId(), $request->request->get('_token'))) {
$this->entityManager->remove($incident);
$this->entityManager->flush();
}
return $this->redirectToRoute('incident_index', [], Response::HTTP_SEE_OTHER);
}
} }

View File

@ -2,11 +2,12 @@
namespace App\Entity; namespace App\Entity;
use AllowDynamicProperties;
use App\Repository\IncidentRepository; use App\Repository\IncidentRepository;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: IncidentRepository::class)] #[AllowDynamicProperties] #[ORM\Entity(repositoryClass: IncidentRepository::class)]
class Incident class Incident
{ {
#[ORM\Id] #[ORM\Id]
@ -15,7 +16,7 @@ class Incident
private ?int $id = null; private ?int $id = null;
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
private ?string $description = null; public ?string $description = null;
#[ORM\OneToMany(targetEntity: Employee::class, mappedBy: 'incident')] #[ORM\OneToMany(targetEntity: Employee::class, mappedBy: 'incident')]
private ?Employee $employee; private ?Employee $employee;