diff --git a/src/Controller/Admin/Teamer/SkillsController.php b/src/Controller/Admin/Teamer/SkillsController.php index bebdde5..c57bb94 100644 --- a/src/Controller/Admin/Teamer/SkillsController.php +++ b/src/Controller/Admin/Teamer/SkillsController.php @@ -4,26 +4,66 @@ namespace App\Controller\Admin\Teamer; use App\Entity\Teamer; use App\Repository\TrainingRepository; +use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; class SkillsController extends AbstractController { - public function __construct(private readonly TrainingRepository $trainingRepository) - { + public function __construct( + private readonly TrainingRepository $trainingRepository, + private readonly EntityManagerInterface $entityManager, + private readonly LoggerInterface $logger, + ) { } #[Route('/admin/teamer/skills/{uuid}', name: 'app_admin_teamer_skills')] #[IsGranted('ROLE_ADMIN')] - public function index(Teamer $teamer): Response + public function index(Teamer $teamer, Request $request): Response { $trainings = $this->trainingRepository->getList(); + $form = $this->createStatusForm($teamer); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->flush(); + + $this->addFlash('success', 'Der Status wurde aktualisiert'); + + $this->logger->info('Update teamer status to '.$teamer->getStatus(), [ + 'teamer' => $teamer->getFullName(), + ]); + + return $this->redirectToRoute('app_admin_teamer_skills', [ + 'uuid' => $teamer->getUuid(), + ]); + } + return $this->render('admin/teamer/skills.html.twig', [ 'teamer' => $teamer, 'trainings' => $trainings, + 'form' => $form->createView(), ]); } + + private function createStatusForm(Teamer $teamer): FormInterface + { + return $this + ->createFormBuilder($teamer) + ->add('status', ChoiceType::class, [ + 'label' => 'Status', + 'choices' => [ + 'Neuteamer' => Teamer::STATUS_NEW, + 'Bestandsteamer' => Teamer::STATUS_EXISTING, + ], + ]) + ->getForm(); + } } diff --git a/src/Form/TeamerJobProfileType.php b/src/Form/TeamerJobProfileType.php index 18780ee..b58ac8c 100644 --- a/src/Form/TeamerJobProfileType.php +++ b/src/Form/TeamerJobProfileType.php @@ -61,13 +61,6 @@ class TeamerJobProfileType extends AbstractType 'expanded' => true, 'multiple' => true, ]) - ->add('status', ChoiceType::class, [ - 'label' => 'Status', - 'choices' => [ - 'Neuteamer' => Teamer::STATUS_NEW, - 'Bestandsteamer' => Teamer::STATUS_EXISTING, - ], - ]) ->add('remarks', TextareaType::class, [ 'label' => 'Wünsche/Anmerkungen', 'required' => false, diff --git a/src/Menu/AdminMenuBuilder.php b/src/Menu/AdminMenuBuilder.php index e73b8cd..94de511 100644 --- a/src/Menu/AdminMenuBuilder.php +++ b/src/Menu/AdminMenuBuilder.php @@ -266,7 +266,7 @@ class AdminMenuBuilder extends AbstractMenuBuilder 'title' => 'Stammdaten & Foto', ], ]); - $menu->addChild('Jobprofile & Skills', [ + $menu->addChild('Jobprofile, Skills & Status', [ 'route' => 'app_admin_teamer_skills', 'routeParameters' => $this->getDefaultRouteParameters('uuid'), 'linkAttributes' => [ diff --git a/templates/admin/teamer/skills.html.twig b/templates/admin/teamer/skills.html.twig index 174f9c9..a6d68d0 100644 --- a/templates/admin/teamer/skills.html.twig +++ b/templates/admin/teamer/skills.html.twig @@ -9,9 +9,24 @@