feat: rework automatic job profile assignment

This commit is contained in:
Björn Fromme committed 2024-11-26 16:46:29 +01:00
1 parent d52cdfca85
commit 97d658e71a
11 files changed
+220 -68

No files matched your search

@@ -3,10 +3,10 @@
namespace App\Controller\Admin\Teamer\TrainingAttendance;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\JobProfile;
use App\Entity\Teamer;
use App\Entity\Training;
use App\Entity\TrainingAttendance;
use App\Event\TrainingAttendanceCreatedEvent;
use App\Form\AbbreviatedDateType;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
@@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class CreateController extends AbstractController
{
@@ -24,11 +25,15 @@ class CreateController extends AbstractController
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly LoggerInterface $logger
) {
}
#[Route('/admin/teamer/skills/training-attendance/create/{training_id}/{teamer_id}', name: 'app_admin_teamer_skills_training_attendance_create')]
#[Route(
path: '/admin/teamer/skills/training-attendance/create/{training_id}/{teamer_id}',
name: 'app_admin_teamer_skills_training_attendance_create'
)]
#[IsGranted('ROLE_ADMIN')]
public function index(
#[MapEntity(mapping: ['training_id' => 'id'])]
@@ -58,9 +63,13 @@ class CreateController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$this->entityManager->persist($attendance);
// $this->assignJobProfiles($teamer, $attendance);
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new TrainingAttendanceCreatedEvent($attendance),
TrainingAttendanceCreatedEvent::NAME
);
$this->addFlash('success', 'Die Teilnahme wurde hinzugefügt');
$this->logger->info('Create training attendance', [
'attendance_id' => $attendance->getId(),
@@ -81,25 +90,4 @@ class CreateController extends AbstractController
'form' => $form->createView(),
]);
}
private function assignJobProfiles(Teamer $teamer, TrainingAttendance $attendance): void
{
$qb = $this
->entityManager
->getRepository(JobProfile::class)
->createQueryBuilder('job_profile')
;
$jobProfiles = $qb
->leftJoin('job_profile.requiredTrainings', 'required_trainings')
->where($qb->expr()->in('required_trainings', ':training'))
->setParameter('training', $attendance->getTraining())
->getQuery()
->getResult()
;
foreach ($jobProfiles as $jobProfile) {
$teamer->addJobProfile($jobProfile);
}
}
}
@@ -4,6 +4,7 @@ namespace App\Controller\Admin\Teamer\TrainingAttendance;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\TrainingAttendance;
use App\Event\TrainingAttendanceDeletedEvent;
use App\Htmx\HxRedirectResponse;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
@@ -12,6 +13,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class DeleteController extends AbstractController
{
@@ -19,11 +21,15 @@ class DeleteController extends AbstractController
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly LoggerInterface $logger
) {
}
#[Route('/admin/teamer/skills/training-attendance/delete/{uuid}', name: 'app_admin_teamer_skills_training_attendance_delete')]
#[Route(
path: '/admin/teamer/skills/training-attendance/delete/{uuid}',
name: 'app_admin_teamer_skills_training_attendance_delete'
)]
#[IsGranted('ROLE_ADMIN')]
public function index(TrainingAttendance $attendance, Request $request): Response
{
@@ -33,6 +39,11 @@ class DeleteController extends AbstractController
$this->entityManager->remove($attendance);
$this->entityManager->flush();
$this->eventDispatcher->dispatch(
new TrainingAttendanceDeletedEvent($attendance),
TrainingAttendanceDeletedEvent::NAME
);
$this->addFlash('success', 'Die Teilnahme an der Fortbilundg wurde gelöscht');
$this->logger->info('Delete training attendance', [
'attendance_id' => $attendance->getId(),