fix emails and some other stuff

This commit is contained in:
2025-02-13 21:42:39 +01:00
parent fcabbaae65
commit 2b96383433
5 changed files with 28 additions and 48 deletions

View File

@ -7,6 +7,7 @@ use App\Controller\Admin\TicketCrudController;
use App\Entity\Payment;
use App\Entity\Ticket;
use chillerlan\QRCode\QRCode;
use Doctrine\Common\Collections\Collection;
use Nucleos\DompdfBundle\Factory\DompdfFactory;
use Nucleos\DompdfBundle\Wrapper\DompdfWrapper;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
@ -37,28 +38,14 @@ class TicketEmailService
->to(new Address($payment->getCustomer()?->getEmail(), $payment->getCustomer()?->getFirstname() . ' ' . $payment->getCustomer()?->getLastname()))
->context([
'payment' => $payment,
]);
$i = 0;
foreach ($payment->getCustomer()?->getTickets() as $ticket) {
++$i;
$mail->addPart(new DataPart($this->generateTicket($ticket), "ticket-$i.pdf", 'application/pdf'));
}
])
->addPart(new DataPart($this->generateTicket($payment->getCustomer()?->getTickets()), 'ticket.pdf', 'application/pdf'));
$this->mailer->send($mail);
}
private function generateTicket(Ticket $ticket): string
private function generateTicket(Collection $tickets): string
{
return (new DompdfWrapper(new DompdfFactory()))->getPdf($this->twig->render('test.html.twig', ['qr' => (new QRCode())->render($this->generateUrl($ticket))]));
}
private function generateUrl(Ticket $ticket): string
{
return $this->urlGenerator->generate('admin', [
'crudAction' => 'detail',
'crudControllerFqcn' => TicketCrudController::class,
'entityId' => $ticket->getCustomer()?->getId()
], UrlGeneratorInterface::ABSOLUTE_URL);
return (new DompdfWrapper(new DompdfFactory()))->getPdf($this->twig->render('test.html.twig', ['tickets' => $tickets]));
}
}