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;
|
2021-06-17 17:24:53 +02:00
|
|
|
use Symfony\Component\Mime\Address;
|
2021-05-28 11:23:04 +02:00
|
|
|
use Symfony\Component\Mime\Email;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
2021-05-29 19:45:45 +02:00
|
|
|
|
2021-05-28 11:23:04 +02:00
|
|
|
class TradeController extends AbstractController
|
|
|
|
{
|
|
|
|
#[Route('/trade/{id}', name: 'trade')]
|
2021-06-06 11:20:51 +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())
|
2021-06-17 17:24:53 +02:00
|
|
|
->from(new Address('no-reply@pflaenz.li', 'Pflänzli no-reply'))
|
2021-05-28 17:33:10 +02:00
|
|
|
->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,
|
2021-06-06 11:20:51 +02:00
|
|
|
'id' => $user->getId(),
|
2021-05-28 17:33:10 +02:00
|
|
|
])
|
|
|
|
;
|
|
|
|
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
|
|
|
|
2022-01-17 19:11:00 +01:00
|
|
|
return $this->redirectToRoute('show_offer', ['urlId' => $offer->getId()]);
|
2021-05-28 11:23:04 +02:00
|
|
|
}
|
|
|
|
}
|