mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
tpl engine
This commit is contained in:
parent
79c4bd2519
commit
bfd938d190
@ -139,7 +139,7 @@ class PollController extends FramadateController {
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function newPollAction( Request $request, Swift_Mailer $mailer, MailService $mail_service ) {
|
||||
public function newPollAction( Request $request ) {
|
||||
|
||||
$data = $request->getContent();
|
||||
|
||||
@ -227,7 +227,7 @@ class PollController extends FramadateController {
|
||||
$precision = 'from an existing user : ' . $foundOwner->getEmail();
|
||||
}
|
||||
|
||||
$mail_service->sendCreationMailAction( $foundOwner, $newpoll );
|
||||
$this->mail_service->sendCreationMailAction( $foundOwner, $newpoll );
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'you created a poll ' . $precision,
|
||||
@ -258,7 +258,6 @@ class PollController extends FramadateController {
|
||||
*/
|
||||
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
|
||||
public function testSendCreationMailAction(
|
||||
MailService $mail_service,
|
||||
$emailChoice = 'tktest_commentateur@tktest.com'
|
||||
) {
|
||||
$em = $this->getDoctrine()->getRepository( Owner::class );
|
||||
@ -267,9 +266,9 @@ class PollController extends FramadateController {
|
||||
$poll = $foundOwner->getPolls()[ 0 ];
|
||||
$comment = $foundOwner->getComments()[ 0 ];
|
||||
|
||||
$sent = $mail_service->sendCreationMailAction( $foundOwner, $poll );
|
||||
$sent = $this->mail_service->sendCreationMailAction( $foundOwner, $poll );
|
||||
if ( $sent ) {
|
||||
return $this->json( [ "message" => "test email sent!" ], 200 );
|
||||
return $this->json( [ "message" => $this->mail_service->numSent. "test email sent to ".$foundOwner->getEmail()."!" ], 200 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ use Exception;
|
||||
use Swift_Mailer;
|
||||
use Swift_Message;
|
||||
use Swift_SmtpTransport;
|
||||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
|
||||
|
||||
class MailService {
|
||||
|
||||
@ -22,10 +23,23 @@ class MailService {
|
||||
private $em;
|
||||
|
||||
private $mailer;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $numSent;
|
||||
|
||||
// public function __construct( EntityManagerInterface $entityManager , Mailer $mailer) {
|
||||
public function __construct( EntityManagerInterface $entityManager ) {
|
||||
$this->em = $entityManager;
|
||||
/**
|
||||
* @var EngineInterface
|
||||
*/
|
||||
private $templating;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $entityManager,
|
||||
EngineInterface $templating
|
||||
) {
|
||||
$this->em = $entityManager;
|
||||
$this->templating = $templating;
|
||||
|
||||
// Create the Transport
|
||||
$transport = new Swift_SmtpTransport( 'localhost', 25 );
|
||||
@ -150,14 +164,22 @@ class MailService {
|
||||
'creation_vote' => 'Framadate | Vote de "' . $config[ 'owner' ]->getPseudo() . '" - sondage ' . $config[ 'poll' ]->getTitle(),
|
||||
];
|
||||
// Create a message
|
||||
$message = ( new Swift_Message( 'Wonderful Subject' ) )
|
||||
->setFrom( [ 'contact@framadate-api.cipherbliss.com' ] )
|
||||
->setTo( ['contact@cipherbliss.com'] )
|
||||
->setBody( 'Here is the message itself' );
|
||||
$htmlbody = $this->templating->render(
|
||||
// templates/emails/registration.html.twig
|
||||
$config[ 'email_template' ],
|
||||
$config
|
||||
);
|
||||
$message = ( new Swift_Message( 'Wonderful Subject from FAT computer' ) )
|
||||
->setContentType( "text/html" )
|
||||
->setCharset( 'UTF-8' )
|
||||
->setFrom( [ 'contact@framadate-api.cipherbliss.com' ] )
|
||||
->setTo( [ 'contact@cipherbliss.com' ] )
|
||||
->setBody( $htmlbody, 'text/html' );
|
||||
|
||||
|
||||
// Send the message
|
||||
$numSent = $this->mailer->send( $message );
|
||||
printf( "Sent %d messages\n", $numSent );
|
||||
$numSent = $this->mailer->send( $message );
|
||||
$this->numSent = $numSent;
|
||||
// $email = ( new TemplatedEmail() )
|
||||
// ->from( new Address( $config[ 'from' ] ) )
|
||||
// ->subject( $config[ 'title' ] )
|
||||
|
Loading…
Reference in New Issue
Block a user