From 57a8eba23843c256f3e91cd714b2ea148df03e70 Mon Sep 17 00:00:00 2001 From: bourgoino Date: Tue, 8 Apr 2025 08:11:56 +0200 Subject: [PATCH] =?UTF-8?q?S=C3=A9lection=20de=20comp=C3=A9tences.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/InternController.php | 48 +++++++++++++ src/Controller/ProfileController.php | 13 ++++ templates/degree/index.html.twig | 24 +++---- templates/intern/index.html.twig | 14 ++++ templates/profile/intern.html.twig | 7 +- templates/skill/index.html.twig | 101 ++++++++++++++++----------- 6 files changed, 153 insertions(+), 54 deletions(-) diff --git a/src/Controller/InternController.php b/src/Controller/InternController.php index 0ada2cc..c8f0cb6 100644 --- a/src/Controller/InternController.php +++ b/src/Controller/InternController.php @@ -5,6 +5,8 @@ namespace App\Controller; use App\Entity\Degree; use App\Entity\Intern; use App\Entity\InternDegree; +use App\Entity\InternSkill; +use App\Entity\Skill; use App\Form\InternType; use App\Repository\InternRepository; use Doctrine\ORM\EntityManagerInterface; @@ -108,4 +110,50 @@ final class InternController extends AbstractController return $this->redirectToRoute('app_profile'); } + + #[Route('/skills/add', name:'app_intern_add_skills', methods:['POST'])] + public function addSkills(Request $request, EntityManagerInterface $entityManager): Response + { + $intern = $this->getUser(); + + if (!$intern instanceof Intern) { + throw $this->createAccessDeniedException("Seuls les stagiaires peuvent sélectionner des compétences."); + } + + $selectedSkillIds = $request->request->all('selected_skills'); + + if ($selectedSkillIds == []) { + $this->addFlash('error', "Aucune sélection valide n'a été effectuée."); + return $this->redirectToRoute('app_skill_index'); + } + + $skillRepository = $entityManager->getRepository(Skill::class); + $internSkillRepository = $entityManager->getRepository(InternSkill::class); + + foreach ($selectedSkillIds as $skillId) { + $skill = $skillRepository->find($skillId); + + if (!$skill) continue; + + $existingInternSkill = $internSkillRepository->findOneBy([ + 'intern' => $intern, + 'skill' => $skill + ]); + + if (!$existingInternSkill) { + $internSkill = new InternSkill(); + $internSkill->setIntern($intern); + $internSkill->setSkill($skill); + + $entityManager->persist($internSkill); + } + } + + $entityManager->flush(); + + $this->addFlash('success', 'Les compétences ont été ajoutées avec succès.'); + + return $this->redirectToRoute('app_profile'); + } + } diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index d25e351..7f84be2 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Entity\UserApp; use App\Form\UserAppType; +use App\Repository\SkillRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -51,4 +52,16 @@ class ProfileController extends AbstractController 'user_app' => $userApp, ]); } + + #[Route('/profile/pickSkill', name: 'app_profile_pickSkill', methods: ['GET'])] + public function pickSkill(UserApp $userApp): Response + { + + return $this->render('skill/index.html.twig', [ + 'user_app' => $userApp, + ]); + } + + + } \ No newline at end of file diff --git a/templates/degree/index.html.twig b/templates/degree/index.html.twig index a6016d5..906f149 100644 --- a/templates/degree/index.html.twig +++ b/templates/degree/index.html.twig @@ -34,19 +34,19 @@ {% endif %} {% if 'ROLE_ADMIN' in app.user.roles %} - - - Modifier - + + + Modifier + - -
- - - -
+ +
+ + + +
{% endif %} diff --git a/templates/intern/index.html.twig b/templates/intern/index.html.twig index 02c128a..29708b1 100644 --- a/templates/intern/index.html.twig +++ b/templates/intern/index.html.twig @@ -48,4 +48,18 @@ {% endfor %} +

Vos compétences :

+ + + Sélectionner vos compétences + {% endblock %} diff --git a/templates/profile/intern.html.twig b/templates/profile/intern.html.twig index d74a3ff..21b4313 100644 --- a/templates/profile/intern.html.twig +++ b/templates/profile/intern.html.twig @@ -27,8 +27,8 @@

Vos compétences :


Selectionner vos compétences + href="{{ path('app_skill_index',{id: app.user.id}) }}"> Sélectionner vos compétences +
Accéder aux favoris diff --git a/templates/skill/index.html.twig b/templates/skill/index.html.twig index e5e911f..0b31564 100644 --- a/templates/skill/index.html.twig +++ b/templates/skill/index.html.twig @@ -6,47 +6,70 @@ + + {% if 'ROLE_INTERN' in app.user.roles %} +
+ +
+ + {% endif %} + + {% if 'ROLE_ADMIN' in app.user.roles %} + + {% endif %}
{% endblock %}