src/MDS/WebInOutTravelBundle/Controller/ApiSaveEmailNewsletterController.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: DEVELUP-USER3
  5.  * Date: 12/12/2019
  6.  * Time: 10:09
  7.  */
  8. namespace App\MDS\WebInOutTravelBundle\Controller;
  9. use App\Entity\NewsLetterControl;
  10. use App\Entity\NewsLetterEmail;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use FOS\RestBundle\Controller\Annotations as Rest;
  15. use FOS\RestBundle\Controller\AbstractFOSRestController;
  16. class ApiSaveEmailNewsletterController extends AbstractFOSRestController
  17. {
  18.     /**
  19.      * @Rest\Post("/api/savenewsletter/inGet")
  20.      * @param Request $request
  21.      * @return Response
  22.      */
  23.     public function apiNewsWebListGetAction(Request $request){
  24.         $em $this->getDoctrine()->getManager();
  25.             $tokenList $request->request->get('token');
  26.         $file fopen('newsletter.txt'"wb");
  27.         fwrite($file$tokenList'carlos' 'hola');
  28.         fclose($file);
  29.             if (!empty($tokenList)){
  30.                 switch ($tokenList) {
  31.                     case "7013ae93b6de16c9c935dad6ca66f83f"// Web InOut
  32.                         $controlName "WEB INOUT";
  33.                         $type "WebInOut";
  34.                         break;
  35.                     case "7013ae93b6de16c9c935dad6ca66f83fem"// Web InOut
  36.                         $controlName "WEB INOUT EMPLEO";
  37.                         $type "WebInOutEmpleo";
  38.                         break;
  39.                     case "5dc65d4195b9e1ab55b269da93c90455"// Web Develup
  40.                         $controlName "WEB DEVELUP";
  41.                         $type "Webdevelup";
  42.                         break;
  43.                     case "765b9d325b17b6d82c873259355c7cfc"// Web LoLiTa
  44.                         $controlName "WEB LOLITA";
  45.                         $type "WebLolita";
  46.                         break;
  47.                     case "2b9c7dc24f8e68bac2f0c1e9e7360779"// Web AvExpress
  48.                         $controlName "WEB AVEXPRESS";
  49.                         $type "WebAvexpress";
  50.                         break;
  51.                     case "98f06708915a31c53e52a6bed2ed804a"// Web InOutEvents
  52.                         $controlName "WEB INOUT EVENTS";
  53.                         $type "WebInoutEvents";
  54.                         break;
  55.                     default:
  56.                         $controlName "ko";
  57.                 }
  58.                 if ($controlName != "ko"){
  59. //                  $email = $request->query->get('email');
  60.                     $email $request->request->get('email');
  61.                     $ip $request->request->get('ip');
  62.                     if (!empty($email)){
  63.                         $NewsLetterControl $em->getRepository(NewsLetterControl::class)->findOneBy(
  64.                             array(
  65.                                 'name' => $controlName
  66.                             )
  67.                         );
  68.                         $NewsLetterEmail $em->getRepository(NewsLetterEmail::class)->findOneBy(
  69.                             array(
  70.                                 'email' => $email,
  71.                                 'type' => $type,
  72.                             )
  73.                         );
  74.                         if (empty($NewsLetterEmail)){
  75.                             $newsletter = new NewsLetterEmail();
  76.                             $newsletter->setNewsletterId($NewsLetterControl->getId());
  77.                             $newsletter->setEmail($email);
  78.                             $newsletter->setType($type);
  79.                             $newsletter->setIp($ip);
  80.                             $newsletter->setCreatedId(0);
  81.                             $newsletter->setUpdatedId(0);
  82.                             $em->persist($newsletter);
  83.                             $em->flush();
  84.                             $response = new JsonResponse("ok"200);
  85.                         }else{
  86.                             $response = new JsonResponse("ko, exists"200);
  87.                         }
  88.                     }else{
  89.                         $response = new JsonResponse("ko"401);
  90.                     }
  91.                 }else{
  92.                     $response = new JsonResponse("ko"401);
  93.                 }
  94.             }else{
  95.                 $response = new JsonResponse("ko"401);
  96.             }
  97.         return $response;
  98.     }
  99. }