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;
|
2020-04-14 18:09:03 +02:00
|
|
|
use App\Service\MailService;
|
2020-01-30 11:28:24 +01:00
|
|
|
use FOS\RestBundle\Controller\Annotations\Get;
|
|
|
|
use FOS\RestBundle\Controller\Annotations\Route;
|
2020-04-16 17:11:01 +02:00
|
|
|
use Swift_Mailer;
|
2020-01-30 11:28:24 +01:00
|
|
|
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_")
|
|
|
|
*/
|
2020-04-16 17:11:01 +02:00
|
|
|
class DefaultController extends FramadateController {
|
2020-04-14 18:09:03 +02:00
|
|
|
/**
|
|
|
|
* @var MailService
|
|
|
|
*/
|
2020-04-16 17:11:01 +02:00
|
|
|
protected $mail_service;
|
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
|
2020-04-16 17:11:01 +02:00
|
|
|
* @param Swift_Mailer $mailer
|
2020-01-30 11:28:24 +01:00
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
2020-04-16 17:11:01 +02:00
|
|
|
public function sendPollsToUser( $email, Swift_Mailer $mailer ) {
|
2020-01-30 11:28:24 +01:00
|
|
|
$repository = $this->getDoctrine()->getRepository( Owner::class );
|
2020-04-10 18:02:52 +02:00
|
|
|
|
|
|
|
// find user by email
|
2020-04-14 18:09:03 +02:00
|
|
|
$founduser = $repository->findOneBy( [ 'email' => $email ] );
|
2020-01-30 11:28:24 +01:00
|
|
|
|
|
|
|
if ( $founduser ) {
|
|
|
|
$polls = $founduser->getPolls();
|
|
|
|
$templateVars = [
|
|
|
|
'owner' => $founduser,
|
|
|
|
'polls' => $polls,
|
2020-04-14 18:09:03 +02:00
|
|
|
'title' => 'Mes sondages - ' . $email,
|
2020-01-28 20:43:16 +01:00
|
|
|
];
|
2019-11-28 16:48:35 +01:00
|
|
|
|
2020-04-10 17:21:31 +02:00
|
|
|
// send email
|
2020-04-14 18:13:48 +02:00
|
|
|
if ( $this->mail_service->sendOwnerPollsAction( $founduser ) ) {
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'mail succefully sent to user ' . $email,
|
|
|
|
'data' => '',
|
|
|
|
],
|
|
|
|
200 );
|
|
|
|
} else { // user not found case
|
|
|
|
return $this->json( [
|
|
|
|
'message' => 'no user found for email ' . $email,
|
|
|
|
'data' => '',
|
|
|
|
],
|
|
|
|
400 );
|
|
|
|
}
|
2020-04-14 18:09:03 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|