From 0246adcc03c81ade7454fc87a71a2668fbcabc75 Mon Sep 17 00:00:00 2001 From: Allavena Romain Date: Fri, 4 Apr 2025 13:02:53 +0200 Subject: [PATCH] ajout candidatures --- src/Controller/InternController.php | 37 +++++++++++++++++++++++++++ templates/announcement/show.html.twig | 9 +++++++ templates/degree/index.html.twig | 12 ++++++--- templates/profile/intern.html.twig | 12 +++------ 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/Controller/InternController.php b/src/Controller/InternController.php index 0ada2cc..f53321c 100644 --- a/src/Controller/InternController.php +++ b/src/Controller/InternController.php @@ -2,8 +2,10 @@ namespace App\Controller; +use App\Entity\Announcement; use App\Entity\Degree; use App\Entity\Intern; +use App\Entity\InternApplication; use App\Entity\InternDegree; use App\Form\InternType; use App\Repository\InternRepository; @@ -108,4 +110,39 @@ final class InternController extends AbstractController return $this->redirectToRoute('app_profile'); } + + #[Route('/application/send', name:'app_intern_send_application', methods:['POST'])] + public function sendApplication(Request $request, EntityManagerInterface $entityManager): Response + { + $intern = $this->getUser(); + if (!$intern instanceof Intern) { + throw $this->createAccessDeniedException("Seuls les stagiaires peuvent envoyer des candidatures."); + } + + $announcementRepository = $entityManager->getRepository(Announcement::class); + $internApplicationRepository = $entityManager->getRepository(InternApplication::class); + + $announcementId = $request->request->get('announcement_id'); + $announcement = $announcementRepository->find($announcementId); + + $existingInternApplication = $internApplicationRepository->findOneBy([ + 'intern' => $intern, + 'application' => $announcement + ]); + + if (!$existingInternApplication) { + $internApplication = new InternApplication(); + $internApplication->setIntern($intern); + $internApplication->setApplication($announcement); + $internApplication->setApplicationDate(new \DateTime()); + + $entityManager->persist($internApplication); + } + $entityManager->flush(); + + $this->addFlash('success', 'La candidature à bien été envoyée.'); + + return $this->redirectToRoute('app_profile'); + + } } diff --git a/templates/announcement/show.html.twig b/templates/announcement/show.html.twig index 09e50e1..260e57c 100644 --- a/templates/announcement/show.html.twig +++ b/templates/announcement/show.html.twig @@ -52,6 +52,15 @@ {{ announcement.creationDate | date('d/m/Y') }} + {% if 'ROLE_INTERN' in app.user.roles %} +
+ + +
+ {% endif %} + {% if 'ROLE_ADMIN' in app.user.roles %} diff --git a/templates/degree/index.html.twig b/templates/degree/index.html.twig index a6016d5..93b9be5 100644 --- a/templates/degree/index.html.twig +++ b/templates/degree/index.html.twig @@ -28,19 +28,22 @@ {% if 'ROLE_INTERN' in app.user.roles %} {% endif %} {% if 'ROLE_ADMIN' in app.user.roles %} - + Modifier -
+