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 @@

Liste des Compétences

-
- - - - - - - - - - {% for skill in skills %} - - - - + +
+
IDLabelActions
{{ skill.id }}{{ skill.label }} - - Voir - + {% if 'ROLE_INTERN' in app.user.roles %} +
+ {% endif %} - - Modifier - - - - - - -
-
+ + + + + - {% endfor %} - -
IDLabelActions
-
+ + + {% for skill in skills %} + + {{ skill.id }} + {{ skill.label }} + + {% if 'ROLE_INTERN' in app.user.roles %} + + {% endif %} -
+ {% if 'ROLE_ADMIN' in app.user.roles %} + + + Modifier + + + +
+ + + +
+ {% endif %} + + + {% endfor %} + + +
+ + {% if 'ROLE_INTERN' in app.user.roles %} +
+ +
+ + {% endif %} + + {% if 'ROLE_ADMIN' in app.user.roles %} +
+ + Ajouter une compétence + +
+ {% endif %}
{% endblock %}