2019-11-05 12:16:16 +01:00
|
|
|
<?php
|
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
namespace App\Controller;
|
2020-01-28 20:43:16 +01:00
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
use App\Entity\Owner;
|
|
|
|
use FOS\RestBundle\Controller\Annotations\Get;
|
|
|
|
use FOS\RestBundle\Controller\Annotations\Route;
|
|
|
|
use Swift_Message;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
2020-01-28 20:43:16 +01:00
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
/**
|
|
|
|
* Class DefaultController
|
|
|
|
* @package App\Controller
|
|
|
|
* @Route("/api/v1",name="api_")
|
|
|
|
*/
|
|
|
|
class DefaultController extends AbstractController {
|
2020-01-28 20:43:16 +01:00
|
|
|
|
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
/**
|
|
|
|
* Send a mail with all the data to one user
|
|
|
|
* @Get(
|
|
|
|
* path = "/send-polls-to-user/{email}",
|
|
|
|
* name = "send_user_polls"
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* @param $email
|
|
|
|
* @param \Swift_Mailer $mailer
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function sendPollsToUser( $email, \Swift_Mailer $mailer ) {
|
|
|
|
$repository = $this->getDoctrine()->getRepository( Owner::class );
|
2020-04-10 18:02:52 +02:00
|
|
|
|
|
|
|
// find user by email
|
2020-01-30 11:28:24 +01:00
|
|
|
$founduser = $repository->findOneBy( [ 'email' => $email ] );
|
|
|
|
|
|
|
|
if ( $founduser ) {
|
|
|
|
$polls = $founduser->getPolls();
|
|
|
|
$templateVars = [
|
|
|
|
'owner' => $founduser,
|
|
|
|
'polls' => $polls,
|
2020-04-10 17:19:18 +02:00
|
|
|
'title' => 'Mes sondages - '.$email,
|
2020-01-28 20:43:16 +01:00
|
|
|
];
|
2019-11-28 16:48:35 +01:00
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
$message = ( new Swift_Message( 'Framadate - mes sondages' ) )
|
|
|
|
->setFrom( 'ne-pas-repondre@framadate-api.cipherbliss.com' )
|
|
|
|
->setTo( $founduser->getEmail() )
|
|
|
|
->setBody(
|
|
|
|
$this->renderView(
|
|
|
|
'emails/owner-list.html.twig',
|
|
|
|
$templateVars
|
|
|
|
)
|
|
|
|
);
|
2020-04-10 17:21:31 +02:00
|
|
|
// send email
|
2020-01-30 11:28:24 +01:00
|
|
|
$mailer->send( $message );
|
2019-11-05 16:31:27 +01:00
|
|
|
|
2020-04-10 17:21:31 +02:00
|
|
|
return $this->json( [
|
|
|
|
'message' => 'mail succefully sent to user ' . $email,
|
|
|
|
'data' => '',
|
|
|
|
],
|
|
|
|
200 );
|
|
|
|
|
2019-11-28 11:51:25 +01:00
|
|
|
|
2020-04-10 17:21:31 +02:00
|
|
|
|
|
|
|
} else { // user not found case
|
2020-01-28 20:43:16 +01:00
|
|
|
return $this->json( [
|
2020-01-30 11:28:24 +01:00
|
|
|
'message' => 'no user found for email ' . $email,
|
|
|
|
'data' => '',
|
2020-01-28 20:43:16 +01:00
|
|
|
],
|
2020-01-30 11:28:24 +01:00
|
|
|
400 );
|
2020-01-28 20:43:16 +01:00
|
|
|
}
|
2019-11-27 21:46:35 +01:00
|
|
|
|
2019-11-28 17:09:07 +01:00
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
}
|
2020-01-28 20:43:16 +01:00
|
|
|
|
2019-11-12 11:44:09 +01:00
|
|
|
|
2020-01-30 11:28:24 +01:00
|
|
|
}
|