WIP: Implement profile editing
This commit is contained in:
@@ -10,6 +10,7 @@ use App\Model\AjaxModalResponseDto;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -20,7 +21,8 @@ class AddController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UploadHandler $uploadHandler
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -52,6 +54,11 @@ class AddController extends AbstractController
|
||||
$this->entityManager->persist($license);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Lizenz wurde hinzugefügt.');
|
||||
$this->logger->info('Add license', [
|
||||
'user' => $user->getUserIdentifier(),
|
||||
]);
|
||||
|
||||
$redirectUrl = $this->generateUrl('app_teamer_profile_skills');
|
||||
$response->setCloseAndRedirect($redirectUrl);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Teamer\Profile\License;
|
||||
|
||||
use App\Entity\License;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('//teamer/profile/license/delete/{uuid}', name: 'app_teamer_profile_license_delete')]
|
||||
#[IsGranted('DELETE', subject: 'license')]
|
||||
public function index(License $license): Response
|
||||
{
|
||||
$this->entityManager->remove($license);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Die Lizenz wurde gelöscht.');
|
||||
$this->logger->info('Delete license', [
|
||||
'user' => $this->getUser()->getUserIdentifier(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_teamer_profile_skills');
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,10 @@
|
||||
namespace App\Controller\Teamer\Profile;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\TeamerJobProfileType;
|
||||
use App\Repository\JobProfileRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -11,6 +15,13 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class SkillsController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly JobProfileRepository $jobProfileRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/profile/skills', name: 'app_teamer_profile_skills')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): Response
|
||||
@@ -19,8 +30,38 @@ class SkillsController extends AbstractController
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
$jobProfiles = $this->jobProfileRepository->getList();
|
||||
$selectableJobProfiles = [];
|
||||
|
||||
foreach ($jobProfiles as $profile) {
|
||||
$selectableJobProfiles[$profile->getId()] = true;
|
||||
if (null !== $profile->getRequiredTraining() && false === $teamer->hasTraining($profile->getRequiredTraining())) {
|
||||
$selectableJobProfiles[$profile->getId()] = false;
|
||||
}
|
||||
foreach ($profile->getRequiredLicenses() as $license) {
|
||||
if (false === $teamer->hasLicenseOfType($license)) {
|
||||
$selectableJobProfiles[$profile->getId()] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form = $this->createForm(TeamerJobProfileType::class, $teamer, ['job_profiles' => $jobProfiles, 'selectable_job_profiles' => $selectableJobProfiles]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Dein Profil wurde aktualisiert.');
|
||||
$this->logger->info('Update teamer profile', [
|
||||
'user' => $user->getUserIdentifier(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_teamer_profile_skills');
|
||||
}
|
||||
|
||||
return $this->render('teamer/profile/skills.html.twig', [
|
||||
'teamer' => $teamer,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user