2021-05-28 11:23:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2021-05-28 17:33:10 +02:00
|
|
|
use App\Entity\User;
|
|
|
|
use App\Entity\Offering;
|
|
|
|
|
2021-05-28 11:23:04 +02:00
|
|
|
use App\Repository\OfferingRepository;
|
|
|
|
use App\Repository\WishRepository;
|
|
|
|
|
2021-05-28 17:33:10 +02:00
|
|
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
2021-05-28 11:23:04 +02:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
|
|
use Symfony\Component\Mime\Email;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2021-05-28 17:33:10 +02:00
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
2021-05-28 11:23:04 +02:00
|
|
|
|
|
|
|
class TradeController extends AbstractController
|
|
|
|
{
|
|
|
|
#[Route('/trade/{id}', name: 'trade')]
|
2021-05-28 17:33:10 +02:00
|
|
|
public function sendEmail(MailerInterface $mailer, Offering $offer, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response
|
2021-05-28 11:23:04 +02:00
|
|
|
{
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
2021-05-28 17:33:10 +02:00
|
|
|
if($user != $offer->getByUser())
|
2021-05-28 11:23:04 +02:00
|
|
|
{
|
2021-05-28 17:33:10 +02:00
|
|
|
$email = (new TemplatedEmail())
|
|
|
|
->from('no-reply@pfleanz.li')
|
|
|
|
->to($offer->getByUser()->getEmail())
|
|
|
|
->replyTo($user->getEmail())
|
|
|
|
->subject($user->getUsername() . ' wants to trade with you!')
|
|
|
|
->text('Trade offer')
|
|
|
|
->htmlTemplate('user/trade/offer_email.html.twig')
|
|
|
|
->context([
|
|
|
|
'user' => $user,
|
|
|
|
'userOffersLink' => $this->generateUrl('user_public', [
|
|
|
|
'id' => $offer->getByUser()->getId(),
|
|
|
|
], UrlGeneratorInterface::ABSOLUTE_URL)
|
|
|
|
])
|
|
|
|
;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$mailer->send($email);
|
|
|
|
$this->addFlash('success', 'Trade offer sent!');
|
|
|
|
} catch (TransportExceptionInterface $e) {
|
|
|
|
$this->addFlash('error', 'There was an error: ' . $e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->addFlash('error','You can\'t trade with yourself!');
|
2021-05-28 11:23:04 +02:00
|
|
|
}
|
2021-05-28 17:33:10 +02:00
|
|
|
|
|
|
|
return $this->redirectToRoute('show_offer', ['id' => $offer->getId()]);
|
2021-05-28 11:23:04 +02:00
|
|
|
}
|
|
|
|
}
|