79 lines
2.7 KiB
PHP
79 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Admin\Teamer\TrainingAttendance;
|
|
|
|
use App\Entity\Teamer;
|
|
use App\Entity\Training;
|
|
use App\Entity\TrainingAttendance;
|
|
use App\Form\AbbreviatedDateType;
|
|
use App\Form\FeeType;
|
|
use App\Model\AjaxModalResponseDto;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
class CreateController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly EntityManagerInterface $entityManager,
|
|
private readonly LoggerInterface $logger
|
|
) {
|
|
}
|
|
|
|
#[Route('/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'])]
|
|
Training $training,
|
|
#[MapEntity(mapping: ['teamer_id' => 'id'])]
|
|
Teamer $teamer,
|
|
Request $request
|
|
): JsonResponse {
|
|
$response = new AjaxModalResponseDto();
|
|
$action = $this->generateUrl('app_admin_teamer_skills_training_attendance_create', [
|
|
'training_id' => $training->getId(),
|
|
'teamer_id' => $teamer->getId(),
|
|
]);
|
|
|
|
$attendance = new TrainingAttendance();
|
|
$attendance
|
|
->setTeamer($teamer)
|
|
->setTraining($training)
|
|
;
|
|
|
|
$form = $this
|
|
->createFormBuilder($attendance, ['action' => $action, 'ajax_submit' => true])
|
|
->add('date', AbbreviatedDateType::class, [
|
|
'label' => 'Datum',
|
|
])
|
|
->getForm()
|
|
;
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->entityManager->persist($attendance);
|
|
$this->entityManager->flush();
|
|
|
|
$this->addFlash('success', 'Die Teilnahme wurde hinzugefügt');
|
|
$this->logger->info('Create training attendance', [
|
|
'teamer' => $teamer->getUuid(),
|
|
'training' => $training->getName(),
|
|
]);
|
|
|
|
$redirectUrl = $this->generateUrl('app_admin_teamer_skills', ['uuid' => $teamer->getUuid()]);
|
|
$response->setCloseAndRedirect($redirectUrl);
|
|
} else {
|
|
$content = $this->renderView('admin/teamer/training_attendance/create.html.twig', [
|
|
'form' => $form
|
|
]);
|
|
$response->setContent($content);
|
|
}
|
|
|
|
return $this->json($response);
|
|
}
|
|
} |