src/Controller/Front/Scholar/Training/Payment/PaymentFundingContactController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front\Scholar\Training\Payment;
  3. use App\Entity\Account\User;
  4. use App\Entity\Scholar\Training\Training;
  5. use App\Form\Payment\FundingType;
  6. use App\Service\Mailer\MailerService;
  7. use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerGetter;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class PaymentFundingContactController extends AbstractController
  14. {
  15.     public function __construct(
  16.         private MailerService   $mailerService,
  17.         private UserOwnerGetter $userOwnerGetter,
  18.     )
  19.     {
  20.     }
  21.     #[Route(path'/training_payment/funding/{training_id}/contact'name'front_channel_training_payment_funding_contact')]
  22.     #[ParamConverter('training'options: ['id' => 'training_id'])]
  23.     public function __invoke(Request $requestTraining $training): Response
  24.     {
  25.         if ($training->getTrainingProduct() === null) {
  26.             return $this->redirectToRoute('front_channel_training_show', ['id' => $training->getId()]);
  27.         }
  28.         $fundingContactForm $this->createForm(FundingType::class);
  29.         $fundingContactForm->handleRequest($request);
  30.         if ($fundingContactForm->isSubmitted() && $fundingContactForm->isValid()) {
  31.             $data $fundingContactForm->getData();
  32.             $this->mailerService->sendFundingDemandMail($data$training);
  33.             $owners $this->userOwnerGetter->getOwnersFor($training);
  34.             $this->mailerService->sendFundingReceive($data$training$owners);
  35.             return $this->redirectToRoute('front_channel_training_show', ['id' => $training->getId()]);
  36.         }
  37.         return $this->render('Front/Scholar/Training/Payment/payment_funding_contact.html.twig', [
  38.             'training' => $training,
  39.             'form' => $fundingContactForm->createView()
  40.         ]);
  41.     }
  42. }