feat: financial data check for teamers, improved enforced checks logic
addresses #869at5rtp
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Teamer\Check;
|
||||
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
use App\Form\PersonalDataConfirmationType;
|
||||
use App\Model\PersonalDataConfirmationDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
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\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class PersonalDataController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly ValidatorInterface $validator,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/check/personal-data', name: 'app_teamer_check_personal_data')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
if (null === $teamer) {
|
||||
$teamer = new Teamer();
|
||||
$user->setTeamer($teamer);
|
||||
$this->entityManager->persist($teamer);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
$form = $this->createForm(PersonalDataConfirmationType::class, new PersonalDataConfirmationDto());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
$teamer->setDataVerifiedAt(new \DateTimeImmutable());
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Vielen Dank, deine Daten wurden bestätigt.');
|
||||
$this->logger->info('Confirm teamer personal data', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_teamer_index');
|
||||
}
|
||||
|
||||
return $this->render('teamer/check/personal_data.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'teamer' => $teamer,
|
||||
// surfaced as a hint only, deliberately not blocking the confirmation
|
||||
'errors' => $this->validator->validate($teamer, null, ['profile_preflight']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user