<?php
namespace App\Controller\Front;
use App\Entity\Comment;
use App\Entity\Masjid;
use App\Form\CommentType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mime\Address;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/comment")
*/
class CommentController extends AbstractController
{
/**
* @Route("/{masjidid}/new", name="comment_new", methods={"GET","POST"})
*/
public function new( $masjidid, Request $request, MailerInterface $mailer): Response
{
$comment = new Comment();
$entityManager = $this->getDoctrine()->getManager();
$masjid = $this->getDoctrine()
->getRepository(Masjid::class)
->find($masjidid);
$author = $this->get('security.token_storage')->getToken()->getUser();
$form = $this->createForm(CommentType::class, $comment);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$comment->setMasjid($masjid);
$comment->setAuthor($author);
$entityManager->persist($comment);
$entityManager->flush();
/*
$message ="Un nouveau commentaire";
$the_mail = "sharjah.masjids@gmail.com";
$email = (new TemplatedEmail())
->from('sharjah.masjids@gmail.com')
->to('sharjah.masjids@gmail.com')
->subject('New comment on sharjah-masjids.com')
// path of the Twig template to render
->htmlTemplate('mail/comment_new.html.twig')
// pass variables (name => value) to the template
->context([
'mess' => $message,
'masjid' => $masjid,
'the_mail' => $the_mail,
])
;
try {
$mailer->send($email);
} catch (TransportExceptionInterface $e) {
// some error prevented the email sending; display an
// error message or try to resend the message
}
*/
return $this->redirectToRoute('masjid_show',['slug'=>$masjid->getSlug()]);
}
return $this->render('comment/new.html.twig', [
'comment' => $comment,
'form' => $form->createView(),
'masjidid' => $masjidid
]);
}
}