Sélection de compétences.
This commit is contained in:
parent
89e0dd4d58
commit
57a8eba238
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -34,19 +34,19 @@
|
||||
{% endif %}
|
||||
|
||||
{% if 'ROLE_ADMIN' in app.user.roles %}
|
||||
<!-- Modifier le diplôme -->
|
||||
<a href="{{ path('app_degree_edit', {'id': degree.id}) }}" class="text-yellow-500 hover:text-yellow-700 mr-3">
|
||||
<i class="fas fa-edit"></i> Modifier
|
||||
</a>
|
||||
<!-- Modifier le diplôme -->
|
||||
<a href="{{ path('app_degree_edit', {'id': degree.id}) }}" class="text-yellow-500 hover:text-yellow-700 mr-3">
|
||||
<i class="fas fa-edit"></i> Modifier
|
||||
</a>
|
||||
|
||||
<!-- Formulaire pour supprimer le diplôme -->
|
||||
<form method="post" action="{{ path('app_degree_delete', {'id': degree.id}) }}" style="display:inline;">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ degree.id) }}">
|
||||
<button type="submit" class="text-red-500 hover:text-red-700">
|
||||
<i class="fas fa-trash-alt"></i> Supprimer
|
||||
</button>
|
||||
</form>
|
||||
<!-- Formulaire pour supprimer le diplôme -->
|
||||
<form method="post" action="{{ path('app_degree_delete', {'id': degree.id}) }}" style="display:inline;">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ degree.id) }}">
|
||||
<button type="submit" class="text-red-500 hover:text-red-700">
|
||||
<i class="fas fa-trash-alt"></i> Supprimer
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -48,4 +48,18 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 class="text-lg font-semibold mt-6">Vos compétences :</h3>
|
||||
<ul class="list-disc list-inside text-gray-800">
|
||||
{% if app.user.skills|length > 0 %}
|
||||
{% for internSkill in app.user.skills %}
|
||||
<li>{{ internSkill.skill.label }}</li>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<li>Aucune compétence sélectionnée</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<a class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full"
|
||||
href="{{ path('app_profile_pickSkill') }}">Sélectionner vos compétences</a>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -27,8 +27,8 @@
|
||||
<h3 class="text-lg font-semibold mt-6">Vos compétences :</h3>
|
||||
<ul class="list-disc list-inside text-gray-800">
|
||||
{% if app.user.skills|length > 0 %}
|
||||
{% for comp in app.user.skills %}
|
||||
<li>{{ comp.label }}</li>
|
||||
{% for internSkill in app.user.skills %}
|
||||
<li>{{ internSkill.skill.label }}</li>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<br>
|
||||
@ -37,9 +37,10 @@
|
||||
</ul>
|
||||
<br>
|
||||
<a class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full"
|
||||
href="{{ path('app_user_edit',{id: app.user.id}) }}"> Selectionner vos compétences
|
||||
href="{{ path('app_skill_index',{id: app.user.id}) }}"> Sélectionner vos compétences
|
||||
</a>
|
||||
|
||||
|
||||
<div class="flex justify-center mt-6">
|
||||
<a class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full"
|
||||
href="{{ path('app_user_edit',{id: app.user.id}) }}"> Accéder aux favoris
|
||||
|
@ -6,47 +6,70 @@
|
||||
<div class="container mx-auto p-6">
|
||||
<h1 class="text-3xl font-bold mb-4">Liste des Compétences</h1>
|
||||
|
||||
<div class="overflow-x-auto bg-white shadow-lg rounded-lg">
|
||||
<table class="min-w-full table-auto">
|
||||
<thead>
|
||||
<tr class="bg-gray-800 text-white">
|
||||
<th class="px-4 py-2 text-left">ID</th>
|
||||
<th class="px-4 py-2 text-left">Label</th>
|
||||
<th class="px-4 py-2 text-left">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for skill in skills %}
|
||||
<tr class="border-b">
|
||||
<td class="px-4 py-2">{{ skill.id }}</td>
|
||||
<td class="px-4 py-2">{{ skill.label }}</td>
|
||||
<td class="px-4 py-2">
|
||||
<a href="{{ path('app_skill_show', {'id': skill.id}) }}" class="text-teal-500 hover:text-teal-700 mr-3">
|
||||
<i class="fas fa-eye"></i> Voir
|
||||
</a>
|
||||
{% if 'ROLE_INTERN' in app.user.roles %}
|
||||
<form method="post" action="{{ path('app_intern_add_skills') }}">
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ path('app_skill_edit', {'id': skill.id}) }}" class="text-yellow-500 hover:text-yellow-700 mr-3">
|
||||
<i class="fas fa-edit"></i> Modifier
|
||||
</a>
|
||||
|
||||
<form method="post" action="{{ path('app_skill_delete', {'id': skill.id}) }}" style="display:inline;">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ skill.id) }}">
|
||||
<button type="submit" class="text-red-500 hover:text-red-700">
|
||||
<i class="fas fa-trash-alt"></i> Supprimer
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
<!-- Tableau des compétences -->
|
||||
<div class="overflow-x-auto bg-white shadow-lg rounded-lg">
|
||||
<table class="min-w-full table-auto">
|
||||
<thead>
|
||||
<tr class="bg-gray-800 text-white">
|
||||
<th class="px-4 py-2 text-left">ID</th>
|
||||
<th class="px-4 py-2 text-left">Label</th>
|
||||
<th class="px-4 py-2 text-left">Actions</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for skill in skills %}
|
||||
<tr class="border-b">
|
||||
<td class="px-4 py-2">{{ skill.id }}</td>
|
||||
<td class="px-4 py-2">{{ skill.label }}</td>
|
||||
<td class="px-4 py-2">
|
||||
{% if 'ROLE_INTERN' in app.user.roles %}
|
||||
<label>
|
||||
<input type="checkbox" name="selected_skills[]" value="{{ skill.id }}" class="mr-2">
|
||||
Sélectionner
|
||||
</label>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-4">
|
||||
<a href="{{ path('app_skill_new') }}" class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full">
|
||||
<i class="fas fa-plus-circle"></i> Ajouter une nouvelle compétence
|
||||
</a>
|
||||
</div>
|
||||
{% if 'ROLE_ADMIN' in app.user.roles %}
|
||||
<!-- Modifier la compétence -->
|
||||
<a href="{{ path('app_skill_edit', {'id': skill.id}) }}" class="text-yellow-500 hover:text-yellow-700 mr-3">
|
||||
<i class="fas fa-edit"></i> Modifier
|
||||
</a>
|
||||
|
||||
<!-- Supprimer la compétence -->
|
||||
<form method="post" action="{{ path('app_skill_delete', {'id': skill.id}) }}" style="display:inline;">
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ skill.id) }}">
|
||||
<button type="submit" class="text-red-500 hover:text-red-700">
|
||||
<i class="fas fa-trash-alt"></i> Supprimer
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if 'ROLE_INTERN' in app.user.roles %}
|
||||
<div class="mt-4">
|
||||
<button type="submit" class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded-full">
|
||||
<i class="fas fa-check-circle"></i> Valider la sélection
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if 'ROLE_ADMIN' in app.user.roles %}
|
||||
<div class="mt-4">
|
||||
<a href="{{ path('app_skill_new') }}" class="bg-teal-500 hover:bg-teal-600 text-white py-2 px-4 rounded-full">
|
||||
<i class="fas fa-plus-circle"></i> Ajouter une compétence
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user