<?php
namespace App\Controller\Front\Scholar\Training\Payment;
use App\Entity\Account\User;
use App\Entity\Scholar\Training\Training;
use App\Form\Payment\FundingType;
use App\Service\Mailer\MailerService;
use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerGetter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PaymentFundingContactController extends AbstractController
{
public function __construct(
private MailerService $mailerService,
private UserOwnerGetter $userOwnerGetter,
)
{
}
#[Route(path: '/training_payment/funding/{training_id}/contact', name: 'front_channel_training_payment_funding_contact')]
#[ParamConverter('training', options: ['id' => 'training_id'])]
public function __invoke(Request $request, Training $training): Response
{
if ($training->getTrainingProduct() === null) {
return $this->redirectToRoute('front_channel_training_show', ['id' => $training->getId()]);
}
$fundingContactForm = $this->createForm(FundingType::class);
$fundingContactForm->handleRequest($request);
if ($fundingContactForm->isSubmitted() && $fundingContactForm->isValid()) {
$data = $fundingContactForm->getData();
$this->mailerService->sendFundingDemandMail($data, $training);
$owners = $this->userOwnerGetter->getOwnersFor($training);
$this->mailerService->sendFundingReceive($data, $training, $owners);
return $this->redirectToRoute('front_channel_training_show', ['id' => $training->getId()]);
}
return $this->render('Front/Scholar/Training/Payment/payment_funding_contact.html.twig', [
'training' => $training,
'form' => $fundingContactForm->createView()
]);
}
}