src/Controller/AccountController.php line 615

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Fpdf\Fpdf;
  4. use DateTime;
  5. use ZipArchive;
  6. use App\Entity\Address;
  7. use App\Entity\Job;
  8. use App\Entity\City;
  9. use App\Entity\Page;
  10. use App\Entity\Post;
  11. use App\Entity\Role;
  12. use App\Entity\User;
  13. use App\Entity\Topic;
  14. use App\Form\IdeaType;
  15. use App\Service\Email;
  16. use App\Entity\Contact;
  17. use App\Entity\Invoice;
  18. use App\Form\FicheType;
  19. use App\Form\FicheVisitorType;
  20. use App\Form\UserType;
  21. use App\Entity\SubTheme;
  22. use App\Form\SchoolType;
  23. use App\Service\Utility;
  24. use App\Form\ContactType;
  25. use App\Form\SchoolEditType;
  26. use App\Form\PartnerEditType;
  27. use App\Entity\PasswordUpdate;
  28. use App\Form\ForgetPasswordType;
  29. use App\Form\PasswordUpdateType;
  30. use App\Form\FicheSchoolEditType;
  31. use App\Repository\JobRepository;
  32. use App\Repository\CityRepository;
  33. use App\Repository\PostRepository;
  34. use App\Repository\UserRepository;
  35. use App\Repository\SchoolRepository;
  36. use App\Form\SubscribeUserSchoolType;
  37. use App\Repository\PartnerRepository;
  38. use Symfony\Component\Form\FormError;
  39. use App\Form\PartnerEditConfirmedType;
  40. use App\Form\SubscribeUserPartnerType;
  41. use Symfony\Component\Serializer\Serializer;
  42. use Symfony\Component\HttpFoundation\Request;
  43. use Symfony\Component\Routing\Annotation\Route;
  44. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  45. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  46. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  47. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  48. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  49. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  50. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  51. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  52. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  53. class AccountController extends AbstractController
  54. {
  55.    private $encoder;
  56.     public function __construct(UserPasswordEncoderInterface $encoder){
  57.          $this->encoder $encoder;
  58.     }
  59.    /**
  60.     * Permet de se connecter
  61.     *
  62.     * @Route("/account/login", name="account_login")
  63.     *
  64.     * @return Response
  65.     */
  66.    public function login(AuthenticationUtils $utils){
  67.       $error $utils->getLastAuthenticationError();
  68.       $username $utils->getLastUsername();
  69.       return $this->render('user/login.html.twig');
  70.    }
  71.    /**
  72.     * Permet de créer un compte utilisateur
  73.     *
  74.     * @Route("/user/signup", name="user_signup")
  75.     *
  76.     * @return Response
  77.     */
  78.    public function signup(Request $requestUserRepository $repositoryUserPasswordEncoderInterface $encoder){
  79.       $role $this->getDoctrine()->getRepository(Role::class)->findOneBy(['access' => 'ROLE_VISITOR']);
  80.       $user = new User();
  81.       $form $this->createForm(UserType::class, $user);
  82.       // -> Handle request POST
  83.       $form->handleRequest($request);
  84.       if ($form->isSubmitted() && $form->isValid()) {
  85.          // -> Check if user has already this email and has finished its registration
  86.             $userExist $this->getDoctrine()->getRepository(User::class)->findOneBy(['email' => $form->getData()->getEmail()]);
  87.             if($userExist){
  88.             $this->addFlash('error','Ce compte existe déjà');
  89.                 return $this->redirectToRoute('user_signup');
  90.             }
  91.             // -> Encoder password
  92.             $hash $this->encoder->encodePassword($user$user->getPassword());
  93.             // -> Set password to user
  94.             $user->setPassword($hash)
  95.             ->setRole($role)
  96.          ->setTypeAccount('visitor')
  97.             ->setCreatedAt(new DateTime());
  98.          $manager $this->getDoctrine()->getManager();
  99.             $manager->persist($user);
  100.             $manager->flush();
  101.             // -> Send email signup success
  102.          /*
  103.             $email = Email::sendEmail($user->getEmail(),"CUSTOMER_SIGNUP", "Votre inscription", [
  104.                 'fullName' => $user->getFullName(),
  105.                 'url' => $this->generateUrl('auth_login', [], UrlGeneratorInterface::ABSOLUTE_URL),
  106.             ]);
  107.          */
  108.             $this->addFlash(
  109.                 'success',
  110.                 "Votre compte a bien été créé"
  111.           );
  112.         return $this->redirectToRoute('account_login');
  113.         /*
  114.           $token = new UsernamePasswordToken(
  115.                 $user,
  116.                 $hash,
  117.                 'main',
  118.                 $user->getRoles()
  119.           );
  120.           $this->get('security.token_storage')->setToken($token);
  121.           $this->get('session')->set('_security_main', serialize($token));
  122.           // -> new Session
  123.           $session = new Session();
  124.           // -> Get all data in session
  125.           $data = $session->all();
  126.         */
  127.       }
  128.       $form $form->createView();
  129.       return $this->render('user/signup.html.twig'compact('form'));
  130.    }
  131.    /**
  132.     * Edit la fiche User
  133.     * @Route("/account/edit", name="account_edit")
  134.     * @return [type] [description]
  135.     */
  136.    public function edit(Request $requestUserRepository $repository)
  137.    {
  138.       // -> Get current user
  139.       $user $this->getUser();
  140.       if(!$user){
  141.          return $this->redirectToRoute('home');
  142.       }
  143.       $last_media $user->getPicture();
  144.       if($user->getTypeAccount() == "pro"){
  145.          $form $this->createForm(FicheType::class, $user);
  146.       } elseif ($user->getTypeAccount() == "school") {
  147.          $form $this->createForm(FicheSchoolEditType::class, $user);
  148.       } elseif ($user->getTypeAccount() == "partner") {
  149.          $form $this->createForm(PartnerEditType::class, $user);
  150.       } elseif ($user->getTypeAccount() == "visitor") {
  151.           $form $this->createForm(FicheVisitorType::class, $user);
  152.       }
  153.       // -> Handle request POST
  154.       $form->handleRequest($request);
  155.       if ($form->isSubmitted() && $form->isValid()) {
  156.          // // Update user profile
  157.          // $media = $form['picture']->getData();
  158.          // if($media){
  159.          //    $user->setPicture(Utility::saveMedia($media, $user->getTypeAccount()));
  160.          // }else{
  161.          //    $user->setPicture($last_media);
  162.          // }
  163.          $manager $this->getDoctrine()->getManager();
  164.          $manager->persist($user);
  165.          $manager->flush();
  166.          // -> Send flash message
  167.          $this->addFlash(
  168.             "success",
  169.             "Vos modifications ont bien été enregistrées"
  170.          );
  171.          return $this->redirectToRoute('account_edit');
  172.        }
  173.        return $this->render('account/edit.html.twig', [
  174.            'form' => $form->createView()
  175.        ]);
  176.    }
  177.    /**
  178.     * Subscription
  179.     * @Route("/account/subscription", name="account_subscription")
  180.     * @return [type] [description]
  181.     */
  182.    public function subscription(Request $requestUserRepository $repository)
  183.    {
  184.        $user $this->getUser();
  185.        $role =$this->getUser()->getRole()->getAccess() == "ROLE_USER";
  186.        return $this->render('account/subscription.html.twig');
  187.    }
  188.    /**
  189.     * Datas
  190.     * @Route("/account/data", name="account_data")
  191.     * @return [type] [description]
  192.     */
  193.    public function data(Request $requestUserRepository $repository)
  194.    {
  195.        $user $this->getUser();
  196.        $role =$this->getUser()->getRole()->getAccess() == "ROLE_USER";
  197.        return $this->render('account/data.html.twig');
  198.    }
  199.    /**
  200.     * Datas
  201.     * @Route("/account/contract", name="account_contract")
  202.     * @return [type] [description]
  203.     */
  204.    public function contract(Request $requestUserRepository $repository)
  205.    {
  206.        $user $this->getUser();
  207.        if ($user->getTypeAccount() === "pro") {
  208.          $page $this->getDoctrine()->getRepository(Page::class)->findOneBy([
  209.             'identifier' => 'contract'
  210.          ]);
  211.        }else {
  212.          $page $this->getDoctrine()->getRepository(Page::class)->findOneBy([
  213.             'identifier' => 'contract-partner'
  214.          ]);
  215.        }
  216.        return $this->render('account/contract.html.twig',compact('user','page'));
  217.    }
  218.    /**
  219.     * Liste des factures
  220.     * @Route("account/invoice", name="account_invoice")
  221.     * @return [type] [description]
  222.     */
  223.    public function invoice(Request $requestUserPasswordEncoderInterface $encoderUserRepository $repository)
  224.    {
  225.       $user $this->getUser();
  226.       return $this->render('account/invoice.html.twig'compact('user'));
  227.    }
  228.    /**
  229.     * Téléchargement d'une facture
  230.     * @Route("account/invoice/{id}/download", name="account_invoice_download")
  231.     * @return [type] [description]
  232.     */
  233.    public function invoiceDownload(Request $request$id)
  234.    {
  235.       $user $this->getUser();
  236.       $invoice $this->getDoctrine()->getRepository(Invoice::class)->findOneBy([
  237.          'id' => $id,
  238.          'user' => $user
  239.       ]);
  240.       define('EURO',chr(128));
  241.       define('CURRENCY',chr(128));
  242.       $black 27;
  243.       $pdf = new FPDF('P','mm','A4');
  244.       $pdf->AddPage();
  245.       $pdf->SetTextColor($black);
  246.       $pdf->SetFillColor(255,255,255);
  247.       $pdf->SetFont('Arial','B',12);
  248.       $pdf->SetXY(128,24);
  249.       $pdf->Cell(0,4,utf8_decode("Facturé à :"),0,2,'L');
  250.       // -> Client
  251.       $pdf->SetFont('Arial','',8);
  252.       $pdf->SetXY(128,30);
  253.       $pdf->Cell(0,4,utf8_decode($invoice->getUser()->getCompany()),0,2,'L');
  254.       $pdf->Cell(0,4,utf8_decode($invoice->getLastname()).' '.utf8_decode($invoice->getFirstname()),0,2,'L');
  255.       $pdf->MultiCell(80,4,utf8_decode($invoice->getUser()->getAddress()),0,2,'L',true);
  256.       $pdf->SetXY(128,50);
  257.       $pdf->Cell(0,5,utf8_decode('Adresse de facturation:'),0,2,'L');
  258.       $pdf->MultiCell(80,4,utf8_decode($invoice->getUser()->getBillingAddress()),0,2,'L',true);
  259.       $pdf->MultiCell(40,4,utf8_decode(''),0,2,'L',true);
  260.       $pdf->setX(138);
  261.       $pdf->Cell(0,4,utf8_decode('').' '.utf8_decode(''),0,2,'L');
  262.       $pdf->Cell(0,4,utf8_decode(""),0,2,'L');
  263.       // -> Date de facturation
  264.       $pdf->SetXY(11,89);
  265.       $pdf->SetFont('Arial','B',10);
  266.       $pdf->Cell(13,5,'Date : ',0,0,'L');
  267.       $pdf->SetFont('Arial','B',10);
  268.       $pdf->Cell(0,5,$invoice->getCreated()->format('d/m/Y'),0,2,'L');
  269.           // My brand
  270.           $pdf->setXY(11,38);
  271.           $pdf->Image('https://www.celeritup.fr/images/logo.png',12,16,17,17,'PNG');
  272.           $pdf->SetFont('Arial','',8);
  273.           $pdf->Cell(0,4,utf8_decode('CELERITUP'),0,2,'L',false);
  274.           $pdf->Cell(0,4,utf8_decode('9 boulevard Louis Blanc'),0,2,'L',false);
  275.           $pdf->Cell(0,4,utf8_decode('83990 Saint-Tropez - France'),0,2,'L',false);
  276.           $pdf->Cell(0,3,utf8_decode('SIRET : 85195388500015'),0,2,'L',false);
  277.           $pdf->Cell(0,3,utf8_decode('N° TVA intracommunautaire : FR34 851 953 885'),0,2,'L',false);
  278.           $pdf->Cell(0,4,utf8_decode('Site internet : www.celeritup.fr'),0,2,'L',false);
  279.           $pdf->Cell(0,4,utf8_decode('Tél: 06 98 80 23 24'),0,2,'L',false);
  280.           $pdf->Cell(0,4,utf8_decode('Email: contact@celeritup.fr'),0,2,'L',false);
  281.           // ORDER SUMMARY
  282.           $pdf->SetXY(11,82);
  283.           $pdf->SetFont('Arial','B',16);
  284.           $pdf->Cell(0,6,utf8_decode('FACTURE N°00'.$invoice->getId()),0,1,'L',false);
  285.           // Contenue summayr
  286.           $currentY $pdf->GetY();
  287.           $currentY+= 15;
  288.           // Tableau des produits
  289.           $pdf->SetLineWidth(0.4);
  290.           $pdf->Line(11,$currentY,199,$currentY);
  291.           $currentY+= 3;
  292.           $pdf->SetFont('Arial','B',8);
  293.           //$currentY = 25;
  294.           $pdf->SetXY(10,$currentY);
  295.           $pdf->MultiCell(20,3,utf8_decode('Désignation'),0,2,'L',false);
  296.           $pdf->SetXY(110,$currentY);
  297.           $pdf->MultiCell(25,3,utf8_decode('Quantité '),0,2,'L',false);
  298.           $pdf->SetXY(140,$currentY);
  299.           $pdf->MultiCell(40,3,utf8_decode('Prix unitaire H.T'),0,2,'L',false);
  300.           $pdf->SetXY(175,$currentY);
  301.           $pdf->MultiCell(30,3,utf8_decode('Total H.T'),0,2,'L',false);
  302.           $currentY $pdf->GetY();
  303.           $currentY+= 3;
  304.           $pdf->Line(11,$currentY,199,$currentY);
  305.           $pdf->SetFont('Arial','',8);
  306.           $currentY += 5;
  307.           $pdf->SetXY(10,$currentY);
  308.           $pdf->Cell(20,3,utf8_decode($invoice->getContent()),0,2,'L',false);
  309.           $pdf->SetXY(110,$currentY);
  310.           $pdf->Cell(20,3,utf8_decode(1),0,2,'L',false);
  311.           $pdf->SetXY(140,$currentY);
  312.           $pdf->Cell(20,3,EURO.utf8_decode($invoice->getAmountWithoutTax()/100),0,2,'L',false);
  313.           $pdf->SetXY(175,$currentY);
  314.           $pdf->Cell(20,3,EURO.utf8_decode($invoice->getAmountWithoutTax()/100),0,2,'L',false);
  315.           $currentY += 7;
  316.           $currentY += 15;
  317.           if($currentY 260){
  318.              $pdf->AddPage();
  319.              $currentY 20;
  320.           }
  321.           $pdf->SetXY(10,$currentY);
  322.           $pdf->SetFont('Arial','B',8);
  323.           $pdf->MultiCell(30,3,utf8_decode('Statut : Réglé'),0,2,'L',false);
  324.           $pdf->SetXY(10,$currentY+4);
  325.           $pdf->SetFont('Arial','',8);
  326.           if(true){
  327.              //$pdf->MultiCell(80,3,utf8_decode('Réglé le ').utf8_decode($invoice->pay_date->format('d/m/Y à H:i')),0,2,'L',false);
  328.           } else {
  329.              //$pdf->MultiCell(80,3,utf8_decode('En attente de réglement'),0,2,'L',false);
  330.           }
  331.           $pdf->SetXY(140,$currentY);
  332.           $pdf->SetFont('Arial','B',8);
  333.           $pdf->MultiCell(30,3,utf8_decode('Total H.T'),0,2,'L',false);
  334.           $pdf->SetXY(175,$currentY);
  335.           $pdf->SetFont('Arial','',8);
  336.           $pdf->Cell(20,3,EURO.utf8_decode($invoice->getAmountWithoutTax()/100),0,2,'L',false);
  337.           $currentY += 7;
  338.           $pdf->SetXY(140,$currentY);
  339.           $pdf->SetFont('Arial','B',8);
  340.           $pdf->MultiCell(30,3,utf8_decode('Total T.V.A').' '.utf8_decode('20').'%',0,2,'L',false);
  341.           $pdf->SetXY(175,$currentY);
  342.           $pdf->SetFont('Arial','',8);
  343.           $pdf->Cell(20,3,EURO.utf8_decode($invoice->getAmountTax()/100),0,2,'L',false);
  344.           $currentY += 7;
  345.           $pdf->SetXY(140,$currentY);
  346.           $pdf->SetFont('Arial','B',8);
  347.           $pdf->MultiCell(30,3,utf8_decode('Total T.T.C'),0,2,'L',false);
  348.           $pdf->SetXY(175,$currentY);
  349.           $pdf->SetFont('Arial','',8);
  350.           $pdf->Cell(20,3,EURO.utf8_decode($invoice->getAmountWithTax()/100),0,2,'L',false);
  351.           $currentY += 7;
  352.           $currentY+=10;
  353.           $pdf->SetFont('Arial','',7);
  354.           $pdf->SetXY(11,225);
  355.           $text_legal "L'indemnité forfaitaire prévue en cas d'impayé après la date d'échéance est de 40 euros par facture. Le défaut de paiement de cette facture au-delà de 15 jours a compter de la réception de la présente entrainera de votre part le versement d'une pénalité correspondant aux intérêts calcules prorata temporis sur le montant du et non rélglé dans les délais stipules sur la base de 1,5 fois le taux d'intérêt en vigueur majore des  frais juridiques éventuels. ";
  356.           $pdf->SetFont('Arial','',7);
  357.           $pdf->Output('FACT001 - INVOICE.pdf','I');
  358.           die();
  359.       dump($invoice);
  360.       die();
  361.       return $this->render('account/invoice.html.twig'compact('user'));
  362.    }
  363.    /**
  364.     * Permet de modifier le password quand on est connecté
  365.     * @Route("account/security", name="account_security")
  366.     * @return [type] [description]
  367.     */
  368.    public function securitys(Request $requestUserPasswordEncoderInterface $encoderUserRepository $repository)
  369.    {
  370.        $user $this->getUser();
  371.        $form $this->createForm(PasswordUpdateType::class);
  372.        $form->handleRequest($request);
  373.        if ($form->isSubmitted() && $form->isValid()) {
  374.            $data $form->getData();
  375.            // Check if password correct
  376.            if(!password_verify($data['password'], $user->getPassword())){
  377.               // -> Error message
  378.               $this->addFlash('error''Votre mot de passe est incorrect');
  379.               // -> Redirect
  380.               return $this->redirectToRoute('home');
  381.            }
  382.            // -> Hash password
  383.            $password $data['newPassword'];
  384.            $hashPassword $encoder->encodePassword($user$password);
  385.            // -> Update password
  386.            $user->setPassword($hashPassword);
  387.            $manager $this->getDoctrine()->getManager();
  388.            $manager->persist($user);
  389.            $manager->flush();
  390.            // -> Send email
  391.            $email Email::send($user,"SUBSCRIBE_PASSWORD_UPDATE""Mot de passe modifé", [
  392.               'fullName' => $user->getFullName()
  393.            ]);
  394.            // -> Flash success message
  395.            $this->addFlash('success''Votre mot de passe a bien été modifié');
  396.            // -> Redirect
  397.            return $this->redirectToRoute('account_security');
  398.        }
  399.        return $this->render('account/security.html.twig', [
  400.            'form' => $form->createView()
  401.        ]);
  402.    }
  403.    /**
  404.     * Mot de passe réinitialisé
  405.     * @Route("/password/reset/{token}", name="account_password_reset")
  406.     */
  407.    public function passwordReset(Request $requestUserPasswordEncoderInterface $encoder$token)
  408.    {
  409.       // -> Get user
  410.       // ***********
  411.       $user $this->getDoctrine()->getRepository(User::class)->findOneBy([
  412.          'passwordResetToken' => $token
  413.       ]);
  414.       // -> If user not found with password reset token
  415.       // **********************************************
  416.       if(!$user){
  417.          // -> Flash error
  418.          // **************
  419.          $this->addFlash("error""Cette requêtes n\'est pas valide.");
  420.          // -> Redirect
  421.          // ***********
  422.          return $this->redirectToRoute('home');
  423.       }
  424.       // -> Update password
  425.       $password Utility::randomString(8);
  426.       $hashPassword $encoder->encodePassword($user$password);
  427.       $user->setPassword($hashPassword);
  428.       $manager $this->getDoctrine()->getManager();
  429.       $manager->persist($user);
  430.       $manager->flush();
  431.       // -> Send email
  432.       $email Email::send($user,"SUBSCRIBE_PASSWORD_RESET""Vos nouveaux accès à votre compte", [
  433.          'fullName' => $user->getFullName(),
  434.          'password' => $password,
  435.          'url' => $this->generateUrl('home', [], UrlGeneratorInterface::ABSOLUTE_URL)
  436.       ]);
  437.       // -> Flash success
  438.       $this->addFlash("success""Votre mot de passe a été reinitialisé");
  439.       // -> Redirect to the Admin users index
  440.       // ************************************
  441.       return $this->redirectToRoute('home');
  442.    }
  443.    /**
  444.     * Mot de passe oublié
  445.     * @Route("/mot-de-passe-oublie", name="account_password_forget")
  446.     */
  447.    public function passwordForget(Request $requestUserPasswordEncoderInterface $encoder)
  448.    {
  449.       // -> Create a ForgetPasswordType form
  450.       // ***********************************
  451.       $form $this->createForm(ForgetPasswordType::class);
  452.       // -> Receives the request for the form
  453.       // ************************************
  454.       $form->handleRequest($request);
  455.       // -> If the form is compliant, the processing is started
  456.       // ******************************************************
  457.       if ($form->isSubmitted() && $form->isValid()) {
  458.            // -> extract and recover the data into variable
  459.            // *********************************************
  460.            extract($form->getData());
  461.            // -> Find user
  462.            // ************************
  463.            $user $this->getDoctrine()->getRepository(User::class)->findOneByEmail($email);
  464.            // -> If user doesn't exist
  465.            if(!$user){
  466.               // -> Flash error
  467.               $this->addFlash("error""Aucun compte existe avec cette adresse mail");
  468.               // -> Redirect
  469.               return $this->redirectToRoute('home');
  470.            }
  471.            // -> Update password reset token and password reset time
  472.            $token Utility::randomString(20);
  473.            $user->setPasswordResetToken($token)
  474.            ->setPasswordResetTime(time());
  475.            $manager $this->getDoctrine()->getManager();
  476.            $manager->persist($user);
  477.            $manager->flush();
  478.            // -> Create a random password
  479.            // ***************************
  480.            /*
  481.            $password = $this->randomString(15);
  482.            $hashPassword = $encoder->encodePassword($user, $password);
  483.            $user->setPassword($hashPassword);
  484.            $manager->persist($user);
  485.            $manager->flush();
  486.            */
  487.            // -> Send email
  488.            $email Email::send($user,"SUBSCRIBE_PASSWORD_FORGET""Mot de passe oublié", [
  489.               'fullName' => $user->getFullName(),
  490.               'url' => $this->generateUrl('account_password_reset'compact('token'), UrlGeneratorInterface::ABSOLUTE_URL)
  491.            ]);
  492.            // -> Flash success
  493.            $this->addFlash("success""Un email de réinitialisation de mot de passe vous a été envoyé");
  494.            // -> Redirect to the Admin users index
  495.            // ************************************
  496.            return $this->redirectToRoute('home');
  497.       }
  498.       return $this->render('account/forgot_password.html.twig',[
  499.            'form' => $form->createView()
  500.       ]);
  501.    }
  502.    /**
  503.     * Suppression du compte et des données de l'utilisateur
  504.     * @Route("account/data/delete", name="account_data_delete")
  505.     * @return [type] [description]
  506.     */
  507.    public function delete(UserRepository $repo_users){
  508.       $user $this->getUser();
  509.       // -> Get user's movies
  510.       $user_videos[] = ['url' => "https://vimeo.com/" $user->getMovie()];
  511.       // -> get picture of each of its posts
  512.       $user_posts_movie $this->getDoctrine()->getRepository(Post::class)->findBy([
  513.          'author' => $user->getId(),
  514.          'type' => 'movie'
  515.       ]);
  516.       foreach ($user_posts_movie as $movie) {
  517.          $user_videos[] = ['url' => "https://vimeo.com/" $movie->getMedia()];
  518.       }
  519.       $admin = new User();
  520.       $admin->setEmail("contact@celeritup.fr");
  521.       // -> Send email to admin
  522.       $email Email::send($admin,"DELETED_ACCOUNT_TO_CELERITUP""Demande de suppression d'un compte", [
  523.          'fullName' => $user->getFullName(),
  524.          'movies' => $user_videos
  525.       ]);
  526.       // -> Send email to user
  527.       $email_user Email::send($admin,"DELETED_ACCOUNT_TO_USER""Demande de suppression de votre compte", [
  528.          'fullName' => $user->getFullName()
  529.       ]);
  530.       $user->setIsDelete(true);
  531.       $manager $this->getDoctrine()->getManager();
  532.       $manager->persist($user);
  533.       $manager->flush();
  534.       return $this->redirectToRoute('account_logout');
  535.    }
  536.    /**
  537.     * Exporter les données de l'utilisateur
  538.     * @Route("account/data/export", name="account_data_export")
  539.     * @return [type] [description]
  540.     */
  541.     public function export(){
  542.       $encoders = [new XmlEncoder(), new JsonEncoder()];
  543.       $normalizers = [new ObjectNormalizer()];
  544.       $serializer = new Serializer($normalizers$encoders);
  545.       $user $this->getUser();
  546.       if(empty($user->getServices())){
  547.          foreach ($user->getServices() as $service) {
  548.             $services[] = $service->getName();
  549.           };
  550.       }else{
  551.          $services[] = "pas de services";
  552.       }
  553.       if(empty($user->getPosts())){
  554.          foreach ($user->getPosts() as $post) {
  555.             $posts[] = [
  556.                'name' => $post->getName(),
  557.                'content' => $post->getContent()
  558.             ];
  559.          }
  560.       }else{
  561.          $posts[] = "pas de posts";
  562.       }
  563.       // -> Get user's movies
  564.       $user_videos[] = "https://vimeo.com/" $user->getMovie();
  565.       // -> get picture of each of its posts
  566.       $user_posts_movie $this->getDoctrine()->getRepository(Post::class)->findBy([
  567.          'author' => $user->getId(),
  568.          'type' => 'movie'
  569.       ]);
  570.       foreach ($user_posts_movie as $movie) {
  571.          $user_videos[] = "https://vimeo.com/" $movie->getMedia();
  572.       }
  573.       // -> If user is a pro
  574.       if ($user->getTypeAccount() == "pro") {
  575.          $result = [
  576.             'firstname' => $user->getFirstName(),
  577.             'lastname' => $user->getLastName(),
  578.             'email' => $user->getEmail(),
  579.             'job'=> $user->getJob()->getName(),
  580.             'city' => $user->getCity()->getName(),
  581.             'site' => $user->getSite(),
  582.             'phone' => $user->getPhone(),
  583.             'siret' => $user->getSiret(),
  584.             'description' => $user->getDescription(),
  585.             'url_facebook' => $user->getUrlFacebook(),
  586.             'url_twitter' =>  $user->getUrlTwitter(),
  587.             'url_instagram' => $user->getUrlInstagram(),
  588.             'url_linkedin' => $user->getUrlLinkedin(),
  589.             'url_youtube' =>  $user->getUrlYoutube(),
  590.             'comment' => $user->getComment(),
  591.             'liability_insurance' => $user->getLiabilityInsurance(),
  592.             'company' => $user->getCompany(),
  593.             'motivation' => $user->getMotivation(),
  594.             'symptoms' => $user->getSymptoms(),
  595.             'tarifAtHome' => $user->getTarifAtHome(),
  596.             'tarifAtDistance' => $user->getTarifAtDistance(),
  597.             'tarifAtOffice'=> $user->getTarifAtOffice(),
  598.             'individual' => $user->getIndividual(),
  599.             'collective' => $user->getCollective(),
  600.             'publicBaby' => $user->getPublicBaby(),
  601.             'publicChildren' => $user->getPublicChildren(),
  602.             'publicAdult' => $user->getPublicAdult(),
  603.             'publicSenior' => $user->getPublicSenior(),
  604.             'prestationParticular' => $user->getPrestationParticular(),
  605.             'prestationCompany' => $user->getPrestationCompany(),
  606.             'wishCompany' => $user->getWishCompany(),
  607.             'nameInsurance' => $user->getNameInsurance(),
  608.             'zip' => $user->getZip(),
  609.             'publicAnimals' => $user->getPublicAnimals(),
  610.             'billingAddress' => $user->getBillingAddress(),
  611.             'sponsor' => $user->getSponsor(),
  612.             'services' => $services,
  613.             'posts' => $posts,
  614.             'videos' => $user_videos
  615.          ];
  616.       }elseif($user->getTypeAccount() == 'partner'){
  617.          $result = [
  618.             'firstname' => $user->getFirstName(),
  619.             'lastname' => $user->getLastName(),
  620.             'email' => $user->getEmail(),
  621.             'job'=> $user->getPartner()->getJobPartner()->getName(),
  622.             'city' => $user->getPartner()->getCity()->getName(),
  623.             'site' => $user->getPartner()->getSite(),
  624.             'phone' => $user->getPartner()->getPhone(),
  625.             'siret' => $user->getPartner()->getSiret(),
  626.             'offer' => $user->getPartner()->getOffer(),
  627.             'comment' => $user->getPartner()->getComment(),
  628.             'sponsor' => $user->getSponsor(),
  629.             'services' => $services,
  630.             'posts' => $posts,
  631.             'videos' => $user_videos
  632.          ];
  633.       }
  634.       // -> Get profile picture's user
  635.       $profile_picture 'images/' $user->getTypeAccount() . '/'.$user->getPicture();
  636.       // -> get picture of each of its posts
  637.       $user_posts $this->getDoctrine()->getRepository(Post::class)->findBy([
  638.          'author' => $user->getId()
  639.       ]);
  640.       // -> Get all posts picture
  641.       foreach ($user_posts as $post) {
  642.          if ($post->getMedia()) {
  643.             $posts_picture[] = "images/" $post->getType() . "/" $post->getMedia();
  644.          }
  645.          if ($post->getMediaBack()) {
  646.             $posts_picture_back[] = "images/" $post->getType() . "/" $post->getMediaBack();
  647.          }
  648.       };
  649.       // -> Create a new zip
  650.       $zip = new ZipArchive;
  651.       // -> Set name to zip
  652.       $zip_name time().".zip";
  653.       // -> Init file
  654.       touch($zip_name);
  655.       // -> If success to create zip
  656.       if($zip->open($zip_nameZipArchive::CREATE)===TRUE){
  657.          // -> Add user data
  658.          $zip->addFromString('data.txt'json_encode($resulttrue));
  659.          // -> Add profile picture in zip
  660.          $zip->addFile($profile_picture);
  661.          // -> Add posts picture in zip
  662.          if(empty($posts_picture) == false){
  663.             foreach ($posts_picture as $post_media) {
  664.                if($post_media) {
  665.                   $zip->addFile($post_media);
  666.                };
  667.             };
  668.          };
  669.          // -> Add posts second picture (book) in zip
  670.          if(empty($posts_media_back) == false){
  671.             foreach ($posts_picture_back as $post_media_back) {
  672.                $zip->addFile($post_media_back);
  673.             }
  674.          }
  675.          // -> Close zip
  676.          $zip->close();
  677.          // -> Check to make sure the zip exists
  678.          if(file_exists($zip_name)){
  679.             // -> Push to download the zip
  680.             header('Content-Type: application/zip');
  681.             header('Content-disposition: attachment; filename='.$zip_name);
  682.             header('Content-Length: ' filesize($zip_name));
  683.             readfile($zip_name);
  684.             unlink($zip_name);
  685.          }
  686.       } else {
  687.          echo("Recommencez le téléchargement");
  688.       }
  689.    }
  690.    /**
  691.     * @Route("/logout_message", name="logout_message")
  692.     */
  693.    public function logoutMessage()
  694.    {
  695.       $this->addFlash('success'"Vous avez été déconnecté(e) !");
  696.       return $this->redirectToRoute('home');
  697.    }
  698. }