src/Controller/InstallateurController.php line 521

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Installateur;
  4. use App\Entity\ContactInstallateur;
  5. use App\Entity\ChampsInstallateur;
  6. use App\Repository\EquipeRepository;
  7. use App\Entity\Champs;
  8. use App\Entity\Tokenpassword;
  9. use App\Entity\CommentaireInstalleur;
  10. use App\Form\InstallateurType;
  11. use App\Repository\InstallateurRepository;
  12. use App\Repository\UserRepository;
  13. use App\Repository\ChampsDefautRepository;
  14. use App\Repository\ChampsInstallateurRepository;
  15. use App\Repository\OperationStandardRepository;
  16. use App\Repository\ChampsRepository;
  17. use App\Repository\NotificationsRepository;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use App\Entity\User;
  23. use App\Entity\Notifications;
  24. use Doctrine\ORM\EntityManagerInterface;
  25. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  26. use App\Service\FileUploader;
  27. use Datetime;
  28. use App\Service\MailerService;
  29. use App\Service\MessageService;
  30. use App\Repository\DealRepository;
  31. use App\Service\EmailSender;
  32. use Symfony\Component\Mailer\MailerInterface;
  33. use Symfony\Component\Mime\Address;
  34. use Symfony\Contracts\Translation\TranslatorInterface;
  35. use SymfonyCasts\Bundle\ResetPassword\Controller\ResetPasswordControllerTrait;
  36. use SymfonyCasts\Bundle\ResetPassword\Exception\ResetPasswordExceptionInterface;
  37. use Symfony\Component\HttpFoundation\RedirectResponse;
  38. use SymfonyCasts\Bundle\ResetPassword\ResetPasswordHelperInterface;
  39. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  40. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  41. use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordToken;
  42. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  43. use Symfony\Component\Security\Csrf\CsrfToken;
  44. use App\Repository\SoustraitantRepository;
  45. use App\Repository\ResetPasswordRequestRepository;
  46. use App\Repository\ChampsSoustraitantRepository;
  47. use App\Repository\ChampsDealRepository;
  48. use App\Repository\DepotDossierRepository;
  49. use App\Repository\ChampsDepotDossierRepository;
  50. use App\Repository\ActiviteDealRepository;
  51. use App\Repository\CommentairesControlleRepository;
  52. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  53. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  54. use Symfony\Component\Process\Process;
  55. use Symfony\Component\Filesystem\Filesystem;
  56. use Symfony\Component\Finder\Finder;
  57. use App\Form\ChangePasswordFormType;
  58. use App\Form\ResetPasswordRequestFormType;
  59. use Symfony\Component\HttpFoundation\JsonResponse;
  60. use App\Repository\CommentaireInstalleurRepository;
  61. use App\Repository\TokenpasswordRepository;
  62. use App\Repository\FactureAafRepository ;
  63. use App\Repository\AppelqualiteRepository;
  64. use App\Repository\ContratRepository;
  65. use App\Repository\ContactInstallateurRepository;
  66. /**
  67.  * @Route("/installateur")
  68.  */
  69. class InstallateurController extends AbstractController
  70. {
  71.     private $resetPasswordHelper;
  72.     private $entityManager;
  73.     public function __construct(ResetPasswordHelperInterface $resetPasswordHelperEntityManagerInterface $entityManager)
  74.     {
  75.         $this->resetPasswordHelper $resetPasswordHelper;
  76.         $this->entityManager $entityManager;
  77.     }
  78.     /**
  79.      * @Route("/", name="app_installateur_index", methods={"GET"})
  80.      */
  81.     public function index(InstallateurRepository $installateurRepository,OperationStandardRepository $operationStandardRepository,
  82.     ChampsDefautRepository $champsDefautRepository,EmailSender $emailSender): Response
  83.     {
  84.        
  85.     
  86.         
  87.         
  88.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  89.             
  90.             return $this->redirectToRoute('app_installateur_edit', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
  91.         }
  92.         $installateur$installateurRepository->findAll();
  93.         $tab=[];
  94.         $installateurs=[];
  95.         // id,type as owner,client as name ,date,file ,batiment
  96.         foreach ($installateur as  $value) {
  97.          if ($value->getStatus() != "archive") {
  98.             $tab['id']=$value->getId();
  99.             $tab['name']=$value->getSociete();
  100.             $tab['owner']=$value->getNom();
  101.             $tab['industry_type']=$value->getPhone();
  102.             $tab['location']=$value->getAdresse();
  103.             $tab['contact_email']=$value->getEmail();
  104.             $tab['employee']="installateur";
  105.             $tab['icone']="ri-archive-line";
  106.             if ($value->getStatus()=='Validé') {
  107.                 $tab['star_value']='<span class="badge progress-green p-2 border-0" >'.$value->getStatus().'</span>';
  108.                 $tab['row_tr']='row-green';
  109.             } elseif($value->getStatus()=="Bloqué") {
  110.                 $tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
  111.                 $tab['row_tr']='row-red';
  112.             }elseif($value->getStatus()=="En Attente"){
  113.                 $tab['star_value']='<span class="badge progress-yellow p-2 border-0" >'.$value->getStatus().'</span>';
  114.                 $tab['row_tr']='row-yellow';
  115.             }else{
  116.                 $tab['star_value']='<span class="badge progress-grey p-2 border-0" >Nouveau</span>';
  117.                 $tab['row_tr']='row-grey';
  118.             }
  119.             
  120.             
  121.             $tab['image_src']=$value->getPhoto() != null "https://kaje-cee.net/assets/uplaod-installateur/".$value->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
  122.             $installateurs[]=$tab;
  123.          }
  124.            
  125.         }
  126.         $clientjson json_encode($installateurs);
  127.         // var_dump(json_encode($clientjson ));
  128.         file_put_contents('assets/json/installateur-list.json'$clientjson);
  129.        
  130.         //       $emailpart ="contact@kaje-cee.net";
  131.           
  132.           
  133.           
  134.         //   $mailerService->send(
  135.         //       "Prise de contact de la part de  rouget",
  136.         //       "contact@redcat-studio.fr",
  137.         //       $emailpart,
  138.         //       'installateur/_email.html.twig',
  139.         //       [
  140.         //           "firstname" => 'rouget',
  141.         //           "lastname" => "sall",
  142.         //           "email" => "rouget@redcat-studio.fr",
  143.         //           "message" => "teste"
  144.         //       ]
  145.         //   );
  146.           
  147.         //   $messageService->addSuccess("Message bien envoyé");
  148.         return $this->render('installateur/index.html.twig', [
  149.             'installateurs' => $installateurRepository->findAll(),
  150.             'operations' => $operationStandardRepository->findAll(),
  151.             'champs' => $champsDefautRepository->findAll(),
  152.         ]);
  153.     }
  154.     
  155.      /**
  156.      * @Route("/archivesinstallateur", name="app_installateur_indexarchive", methods={"GET"})
  157.      */
  158.     public function indexarchive(InstallateurRepository $installateurRepository,OperationStandardRepository $operationStandardRepository,
  159.     ChampsDefautRepository $champsDefautRepository,EmailSender $emailSender): Response
  160.     {
  161.        
  162.         $installateur$installateurRepository->findAll();
  163.         $tab=[];
  164.         $installateurs=[];
  165.         // id,type as owner,client as name ,date,file ,batiment
  166.         foreach ($installateur as  $value) {
  167.          if ($value->getStatus() == "archive") {
  168.             $tab['id']=$value->getId();
  169.             $tab['name']=$value->getSociete();
  170.             $tab['owner']=$value->getNom();
  171.             $tab['industry_type']=$value->getPhone();
  172.             $tab['location']=$value->getAdresse();
  173.             $tab['contact_email']=$value->getEmail();
  174.             $tab['employee']="installateur";
  175.             $tab['icone']="ri-delete-bin-fill";
  176.             
  177.             if($value->getStatus()=="archive") {
  178.                 $tab['star_value']='<span class="badge progress-red p-2 border-0" >'.$value->getStatus().'</span>';
  179.                 $tab['row_tr']='row-red';
  180.             }else{
  181.                 $tab['star_value']='<span class="badge progress-grey p-2 border-0" >Nouveau</span>';
  182.                 $tab['row_tr']='row-grey';
  183.             }
  184.             
  185.             
  186.             $tab['image_src']=$value->getPhoto() != null "https://kaje-cee.net/assets/uplaod-installateur/".$value->getPhoto() : "https://kaje-cee.net/assets/images/user.png";
  187.             $installateurs[]=$tab;
  188.          }
  189.            
  190.         }
  191.         $clientjson json_encode($installateurs);
  192.        // dd(json_encode($clientjson ));
  193.         file_put_contents('assets/json/installateur-list.json'$clientjson);
  194.        
  195.         //       $emailpart ="contact@kaje-cee.net";
  196.           
  197.           
  198.           
  199.         //   $mailerService->send(
  200.         //       "Prise de contact de la part de  rouget",
  201.         //       "contact@redcat-studio.fr",
  202.         //       $emailpart,
  203.         //       'installateur/_email.html.twig',
  204.         //       [
  205.         //           "firstname" => 'rouget',
  206.         //           "lastname" => "sall",
  207.         //           "email" => "rouget@redcat-studio.fr",
  208.         //           "message" => "teste"
  209.         //       ]
  210.         //   );
  211.           
  212.         //   $messageService->addSuccess("Message bien envoyé");
  213.         return $this->render('installateur/archive.html.twig', [
  214.             'installateurs' => $installateurRepository->findBy(['status' => 'archive'])
  215.         ]);
  216.     }
  217.     
  218.     /**
  219.      * @Route("/new", name="app_installateur_new", methods={"GET", "POST"})
  220.      */
  221.     public function new(Request $requestInstallateurRepository $installateurRepository,EntityManagerInterface $entityManager ,UserPasswordHasherInterface $userPasswordHasher,
  222.     ChampsInstallateurRepository $champsInstallateurRepository,ChampsRepository $champsRepository,FileUploader $uploader,OperationStandardRepository $operationStandardRepository
  223.     ,UserRepository $userRepository,ChampsDefautRepository $champsDefautRepository,ResetPasswordHelperInterface $resetPasswordHelper,MailerInterface $mailerTranslatorInterface $translatorNotificationsRepository $notificationsRepository): Response
  224.     {
  225.         $installateur = new Installateur();
  226.         // $form = $this->createForm(InstallateurType::class, $installateur);
  227.         // $form->handleRequest($request);
  228.         if ($request->getMethod() == "POST") {
  229.             
  230.             
  231.              $form $request->request;
  232.             // $date = date('d.m.Y', strtotime($form->get('datekbis'))) ;
  233.             // $datetime = new Datetime($date);
  234.             // var_dump($datetime) ;die('test');
  235.            
  236.             $userold=$userRepository->findOneBy(["email"=>$form->get('email')]);
  237.             // var_dump($userold);die('test');
  238.             if ($userold != null) {
  239.                 return $this->render('installateur/index.html.twig', [
  240.                     'installateurs' => $installateurRepository->findAll(),
  241.                     'messageuser'=>'Installateur déja Ajouter',
  242.                     'operations' => $operationStandardRepository->findAll(),
  243.                     'champs' => $champsRepository->findAll(),
  244.                 ]);
  245.             }
  246.             
  247.             $user = new User();
  248.             $user->setEmail($form->get('email'));
  249.             $roles[]=$form->get('role');
  250.             $user->setRoles($roles);
  251.             $user->setPassword(
  252.                 $userPasswordHasher->hashPassword(
  253.                         $user,'kagekali01'
  254.                     )
  255.                 );
  256.     
  257.                
  258.                 $entityManager->persist($user);
  259.                 $installateur->setUser($user);
  260.                 
  261.                 // $permission=[];
  262.                 // foreach ($form->get('permission') as  $value) {
  263.                 //     $permission[]=$value;
  264.                 // }
  265.                 if ($request->files->get('logo-file')) {
  266.                     $nom='logo-'.$form->get('societe');
  267.                     $uploader->setTargetDirectory($this->getParameter('installateur_directory'));
  268.                     $uploader->upload($request->files->get('logo-file'),$nom);
  269.                     $installateur->setPhoto($uploader->getFileName());
  270.                 }
  271.                 $installateur->setNom($form->get('nom'));
  272.                 $installateur->setPrenom($form->get('prenom'));
  273.                 $installateur->setSociete($form->get('societe'));
  274.                 $installateur->setEmail($form->get('email')); 
  275.                 $installateur->setAdresse($form->get('adresse'));
  276.                 $installateur->setPhone($form->get('phone'));
  277.                 $installateur->setStatus("new");
  278.                 
  279.                 $installateur->setEquipe($this->getUser()->getEquipe());
  280.                
  281.              
  282.             // $produit->setNom($form->get("nom"));
  283.             // $produit->setReference($form->get("reference"));
  284.             // $produit->setPrix($form->get("prix"));
  285.             // $produit->setDescription($form->get("description"));
  286.             // $produitRepository->add($produit, true);
  287.             if ($form->get('operations') !=null ) {
  288.                 foreach ($form->get('operations') as  $value) {
  289.                     $ops$operationStandardRepository->findOneBy(["id"=>intval($value)]);
  290.                     $installateur->addOperationStandard($ops);
  291.                 }
  292.             }
  293.             
  294.             
  295.             $installateurRepository->add($installateurtrue);
  296.             
  297.             $notifications = new Notifications();
  298.             $notifications->setUserId($user);
  299.             $notifications->setMessage("Bienvenue sur Kali  & Co, veuillez compléter vos informations.");
  300.             $notifications->setAction("app_installateur_edit");
  301.             $notifications->setActionId($installateur->getId());
  302.             $notifications->setSender($this->getUser());
  303.             $notifications->setStatuts("non lu");
  304.             $notifications->setDate(new DateTime());
  305.             $notificationsRepository->add($notificationstrue);
  306.          
  307.             foreach ($champsDefautRepository->findAll() as $key => $champsDefaut) {
  308.                 $champsInstallateur = new ChampsInstallateur();
  309.                   
  310.                 $champsInstallateur->setNom($champsDefaut->getNom());
  311.                 $champsInstallateur->setType($champsDefaut->getType());
  312.                 $champsInstallateur->setType($champsDefaut->getType());
  313.                 $champsInstallateur->setStatus('Non Transmis');
  314.                 if ($champsDefaut->getDurevalidite()) {
  315.                     $champsInstallateur->setDurevalidite($champsDefaut->getDurevalidite());
  316.                 }
  317.                 $champsInstallateur->setInstallateur($installateur);
  318.                 
  319.                 $champsInstallateurRepository->add($champsInstallateurtrue);
  320.             }
  321.             $notificationsRepository->add($notificationstrue);
  322.             $username$installateur->getPrenom()." ".$installateur->getNom();
  323.             
  324.             $destination="installateur";
  325.             return $this->processSendingPasswordResetEmail(
  326.                 $form->get('email'),
  327.                 $mailer,
  328.                 $translator,$destination,$username
  329.             );
  330.             
  331.             return $this->redirectToRoute('app_installateur_edit', ['id' => $installateur->getId()], Response::HTTP_SEE_OTHER);
  332.         }
  333.         // if ($form->isSubmitted() && $form->isValid()) {
  334.         //     $installateurRepository->add($installateur, true);
  335.         //     return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
  336.         // }
  337.         return $this->renderForm('installateur/new.html.twig', [
  338.             'installateur' => $installateur,
  339.             'operations' => $operationStandardRepository->findAll()
  340.         ]);
  341.     }
  342.     /**
  343.      * @Route("/newcontact", name="app_contact_new", methods={"GET", "POST"})
  344.      */
  345.     public function newcontact(Request $request,InstallateurRepository $installateurRepository,EntityManagerInterface $entityManager ,ContactInstallateurRepository $contactInstallateurRepository){
  346.         if ($request->getMethod() == "POST") {
  347.             
  348.             
  349.             $form $request->request;
  350.             
  351.              $contact = new ContactInstallateur();
  352.              //dd($form );
  353.              $contact->setNom($form->get('nom'));
  354.              $contact->setMail($form->get('mail'));
  355.              $contact->setTel($form->get('tel'));
  356.              $contact->setFonction($form->get('fonction'));
  357.              $installateur $installateurRepository->findOneBy(["id" => intval($form->get('installateur_id'))]);
  358.                
  359.              $contact->setInstallateur($installateur);
  360.              //dd($contact);
  361.              $contactInstallateurRepository->add($contacttrue);
  362.              return $this->redirectToRoute('app_installateur_edit', ['id' =>$installateur->getId() ], Response::HTTP_SEE_OTHER);
  363.         }else{
  364.             return $this->redirectToRoute('app_installateur_index'Response::HTTP_SEE_OTHER);
  365.         }
  366.     }
  367.     
  368.       /**
  369.      * @Route("/newdeal", name="app_installateur_newdeal", methods={"GET", "POST"})
  370.      */
  371.     public function newdeal(Request $requestInstallateurRepository $installateurRepository,EntityManagerInterface $entityManager ,UserPasswordHasherInterface $userPasswordHasher,
  372.     ChampsInstallateurRepository $champsInstallateurRepository,ChampsRepository $champsRepository,FileUploader $uploader,OperationStandardRepository $operationStandardRepository
  373.     ,UserRepository $userRepository,ChampsDefautRepository $champsDefautRepository,ResetPasswordHelperInterface $resetPasswordHelper,MailerInterface $mailerTranslatorInterface $translator): Response
  374.     {
  375.         $installateur = new Installateur();
  376.         // $form = $this->createForm(InstallateurType::class, $installateur);
  377.         // $form->handleRequest($request);
  378.         if ($request->getMethod() == "POST") {
  379.             
  380.             
  381.             $form $request->request;
  382.             $date date('d.m.Y'strtotime($form->get('datekbis'))) ;
  383.             $datetime = new Datetime($date);
  384.             // var_dump($datetime) ;die('test');
  385.            
  386.             $userold=$userRepository->findOneBy(["email"=>$form->get('email')]);
  387.             // var_dump($userold);die('test');
  388.             if ($userold != null) {
  389.                 return $this->render('installateur/index.html.twig', [
  390.                     'installateurs' => $installateurRepository->findAll(),
  391.                     'messageuser'=>'Installateur déja Ajouter',
  392.                     'operations' => $operationStandardRepository->findAll(),
  393.                     'champs' => $champsRepository->findAll(),
  394.                 ]);
  395.             }
  396.             
  397.             $user = new User();
  398.             $user->setEmail($form->get('email'));
  399.             $roles[]=$form->get('role');
  400.             $user->setRoles($roles);
  401.             $user->setPassword(
  402.                 $userPasswordHasher->hashPassword(
  403.                         $user,'kagekali01'
  404.                     )
  405.                 );
  406.     
  407.                
  408.                 $entityManager->persist($user);
  409.                 $installateur->setUser($user);
  410.                 
  411.                 // $permission=[];
  412.                 // foreach ($form->get('permission') as  $value) {
  413.                 //     $permission[]=$value;
  414.                 // }
  415.                 if ($request->files->get('logo-file')) {
  416.                     $nom='logo-'.$form->get('societe');
  417.                     $uploader->setTargetDirectory($this->getParameter('installateur_directory'));
  418.                     $uploader->upload($request->files->get('logo-file'),$nom);
  419.                     $installateur->setPhoto($uploader->getFileName());
  420.                 }
  421.                 $installateur->setNom($form->get('nom'));
  422.                 $installateur->setPrenom($form->get('prenom'));
  423.                 $installateur->setSociete($form->get('societe'));
  424.                 $installateur->setEmail($form->get('email')); 
  425.                 $installateur->setAdresse($form->get('adresse'));
  426.                 $installateur->setPhone($form->get('phone'));
  427.                 $installateur->setStatus("new");
  428.              
  429.            
  430.             if ($form->get('operations') !=null ) {
  431.                 foreach ($form->get('operations') as  $value) {
  432.                     $ops$operationStandardRepository->findOneBy(["id"=>intval($value)]);
  433.                     $installateur->addOperationStandard($ops);
  434.                 }
  435.             }
  436.             
  437.            
  438.             $installateurRepository->add($installateurtrue);
  439.             
  440.             foreach ($champsDefautRepository->findAll() as $key => $champsDefaut) {
  441.                 $champsInstallateur = new ChampsInstallateur();
  442.                   
  443.                 $champsInstallateur->setNom($champsDefaut->getNom());
  444.                 $champsInstallateur->setType($champsDefaut->getType());
  445.                 $champsInstallateur->setType($champsDefaut->getType());
  446.                 $champsInstallateur->setStatus('Non Transmis');
  447.                 if ($champsDefaut->getDurevalidite()) {
  448.                     $champsInstallateur->setDurevalidite($champsDefaut->getDurevalidite());
  449.                 }
  450.                 $champsInstallateur->setInstallateur($installateur);
  451.                 
  452.                 $champsInstallateurRepository->add($champsInstallateurtrue);
  453.             }
  454.             
  455.             $destination ="deal";
  456.             $username$installateur->getPrenom()." ".$installateur->getNom();
  457.             return $this->processSendingPasswordResetEmail(
  458.                 $form->get('email'),
  459.                 $mailer,
  460.                 $translator,$destination,$username
  461.             );
  462.            
  463.             return $this->redirectToRoute('app_deal_new', [], Response::HTTP_SEE_OTHER);
  464.         }
  465.       
  466.         return $this->renderForm('installateur/new.html.twig', [
  467.             'installateur' => $installateur,
  468.             'operations' => $operationStandardRepository->findAll()
  469.         ]);
  470.     }
  471.     /**
  472.      * @Route("/{id}", name="app_installateur_show", methods={"GET"})
  473.      */
  474.     public function show(Installateur $installateur,OperationStandardRepository $operationStandardRepository): Response
  475.     {
  476.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  477.             if ($installateur->getId() !=$this->getUser()->getInstallateur()->getId() ) {
  478.                 return $this->redirectToRoute('app_installateur_edit', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
  479.             }else{
  480.                 return $this->redirectToRoute('app_installateur_edit', ['id' => $installateur->getId()], Response::HTTP_SEE_OTHER);
  481.             }
  482.            
  483.         }else{
  484.             return $this->redirectToRoute('app_installateur_edit', ['id' => $installateur->getId()], Response::HTTP_SEE_OTHER);
  485.         }
  486.         
  487.     }
  488.     /**
  489.      * @Route("/{id}/edit", name="app_installateur_edit", methods={"GET", "POST"})
  490.      */
  491.     public function edit(Request $requestInstallateur $installateurInstallateurRepository $installateurRepositoryChampsInstallateurRepository $champsInstallateurRepository,
  492.     FileUploader $uploader,ChampsRepository $champsRepository,OperationStandardRepository $operationStandardRepository,
  493.     CsrfTokenManagerInterface $csrfTokenManager,NotificationsRepository $notificationsRepositoryEquipeRepository $equipeRepository): Response
  494.     {
  495.         // return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
  496.         // $form = $this->createForm(InstallateurType::class, $installateur);
  497.         // $form->handleRequest($request);
  498.         $csrfToken $csrfTokenManager->getToken('installateur_edit');
  499.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  500.             if ($installateur->getId() !=$this->getUser()->getInstallateur()->getId() ) {
  501.                 return $this->redirectToRoute('app_installateur_edit', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
  502.             }
  503.            
  504.         }
  505.         $isCompleted "oui";
  506.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  507.             if($installateur->getNom() == null || $installateur->getPrenom() == null || $installateur->getSociete() == null || 
  508.                 $installateur->getPhone() == null || $installateur->getEmail() == null || $installateur->getAdresse() == null ){
  509.                     $isCompleted "non";
  510.             }
  511.             foreach($installateur->getChampsinstallateur() as $key => $value){
  512.                 if($value->getType() !="file" && $value->getValeur() == null){
  513.                     $isCompleted "non";
  514.                 }
  515.                 if($value->getType() =="file" && $value->getStatus() == "Non Transmis"){
  516.                     $isCompleted "non";
  517.                 }
  518.             }
  519.             if(count($installateur->getOperationStandards()) < 1){
  520.                 $isCompleted "non";
  521.             }
  522.         }
  523.         if ($request->getMethod() == "POST") {
  524.             
  525.             $token $request->request->get('_token');
  526.             $id explode("A@",explode("12OU#@R",$token)[1])[0];
  527.             if ($id!=$installateur->getId()) {
  528.                 return $this->redirectToRoute('app_installateur_edit', ['id' => $id], Response::HTTP_SEE_OTHER);
  529.             }
  530.             
  531.             $form $request->request;
  532.             
  533.         
  534.                 if ($request->files->get('logo-file')) {
  535.                     $nom='logo-'.$form->get('societe');
  536.                     $uploader->setTargetDirectory($this->getParameter('installateur_directory'));
  537.                     $uploader->upload($request->files->get('logo-file'),$nom);
  538.                     $installateur->setPhoto($uploader->getFileName());
  539.                 }
  540.                 
  541.                 $installateur->setNom($form->get('nom'));
  542.                 $installateur->setPrenom($form->get('prenom'));
  543.                 $installateur->setSociete($form->get('societe'));
  544.                 $installateur->setEmail($form->get('email')); 
  545.                 $installateur->setAdresse($form->get('adresse'));
  546.                 $installateur->setPhone($form->get('phone'));
  547.                 if (!$this->isGranted('ROLE_INSTALLATEUR')) {
  548.                     $installateur->setStatus($form->get('status'));
  549.                 }
  550.                 $installateur->setCommentaire($form->get('commentaire'));
  551.                
  552.             
  553.                 // $installateur->setPermissions($permission);
  554.               
  555.                if ($form->get('operations') != null) {
  556.                 // $tabopext=[];
  557.                 foreach ($installateur->getOperationStandards() as  $value) {
  558.                     // $tabopext[]=$value->getId();
  559.                     if (!in_array($value->getId(),$form->get('operations'))) {
  560.                      $installateur->removeOperationStandard($value);
  561.                     }
  562.                  }
  563.                  foreach ($form->get('operations') as  $value) {
  564.                     $ops$operationStandardRepository->findOneBy(["id"=>intval($value)]);
  565.                     $installateur->addOperationStandard($ops);
  566.                 }
  567.                }else{
  568.                 foreach ($installateur->getOperationStandards() as  $value) {
  569.                    
  570.                      $installateur->removeOperationStandard($value);
  571.                     
  572.                  }
  573.                }
  574.                
  575.                 
  576.            
  577.             $installateurRepository->add($installateurtrue);
  578.             $com $installateurRepository->findOneBy(["id" => $installateur->getId() ]);
  579.             if($form->get('commentaire') != $com->getCommentaire()){
  580.             
  581.                 $notifications = new Notifications();
  582.                 $notifications->setUserId($installateur->getUser());
  583.                 $notifications->setMessage("Un commentaire a été posté dans votre profil.");
  584.                 $notifications->setAction("app_installateur_edit");
  585.                 $notifications->setActionId($installateur->getId());
  586.                 $notifications->setSender($this->getUser());
  587.                 $notifications->setStatuts("non lu");
  588.                 $notifications->setDate(new DateTime());
  589.                 $notificationsRepository->add($notificationstrue);
  590.                 
  591.             }
  592.                
  593.                 if ($form->get('datekbis')!=null) {
  594.                     $date date('d.m.Y'strtotime($form->get('datekbis'))) ;
  595.                     $datetime = new Datetime($date);
  596.                     // var_dump($form->get('datekbis'));
  597.                     // var_dump($datetime);die('test');
  598.                     $id=$form->get("id_kbis");
  599.                     
  600.                    
  601.                     $champsinst$champsInstallateurRepository->findOneBy(["id" => intval($id)]);
  602.                     if ($request->files->get('kbis')) {
  603.     
  604.                         $nom='kbis-'.$form->get('societe');
  605.                         $uploader->setTargetDirectory($this->getParameter('installateur_directory'));
  606.                         $uploader->upload($request->files->get('kbis'),$nom);
  607.                         $valeur[]=$uploader->getFileName();
  608.                         if ($champsinst->getValeur() != null ) {
  609.                             foreach ($champsinst->getValeur() as $key => $value) {
  610.                                 $valeur[]=$value;
  611.                             }
  612.                         }
  613.                         
  614.                         $champsinst->setValeur($valeur);
  615.                         
  616.                         $champsinst->setStatus("Transmis");
  617.                         // Notif admin
  618.                         // $notifications = new Notifications();
  619.                         // $notifications->setUserId($installateur->getUser()->getId());
  620.                         // $notifications->setMessage($installateur->getSociete() + " vous a transmis son KBIS.");
  621.                         // $notifications->setAction("app_installateur_edit");
  622.                         // $notifications->setActionId($installateur->getId());
  623.                         // $notifications->setSender($this->getUser());
  624.                         // $notifications->setStatuts("non lu");
  625.                         // $notifications->setDate(new DateTime());
  626.                         // $notificationsRepository->add($notifications, true);
  627.                         
  628.                     }
  629.                     $champsinst->setDate($datetime);
  630.                     
  631.                     $champsInstallateurRepository->add($champsinsttrue);
  632.                 }
  633.             foreach ($form as $key => $value) {
  634.                
  635.                 if (count(explode("-",$key)) ==&& explode("-",$key)[0]=="champsinstvaleur") {
  636.                     $id=$form->get('champsinstvaleur-'.explode("-",$key)[1]);
  637.                     $champsinst$champsInstallateurRepository->findOneBy(["id" => $id]);
  638.                     if ($champsinst->getType()=="file") {
  639.                         
  640.                              if ($request->files->get('champsinstallateur-'.explode("-",$key)[1])) {
  641.  
  642.                                  $nom=explode(".",$request->files->get('champsinstallateur-'.explode("-",$key)[1])->getClientOriginalName())[0];
  643.                                  $uploader->setTargetDirectory($this->getParameter('installateur_directory'));
  644.                                  $uploader->upload($request->files->get('champsinstallateur-'.explode("-",$key)[1]),$nom);
  645.                                 //  $champsinst->setValeur($uploader->getFileName());
  646.                                 $valeur=[];
  647.                                 $valeur[]=$uploader->getFileName();
  648.                                  if ($champsinst->getValeur() != null ) {
  649.                                      foreach ($champsinst->getValeur() as $key => $value) {
  650.                                          $valeur[]=$value;
  651.                                      }
  652.                                  }
  653.                                  
  654.                                  $champsinst->setValeur($valeur);
  655.                                  $champsinst->setStatus('Transmis');
  656.                              }
  657.                              
  658.                              $champsInstallateurRepository->add($champsinsttrue);
  659.                     }
  660.                 }
  661.                 if (count(explode("-",$key)) ==&& explode("-",$key)[0]=="champsinstallateur") {
  662.                     $id=$form->get('champsinstvaleur-'.explode("-",$key)[1]);
  663.                     $champsinst$champsInstallateurRepository->findOneBy(["id" => $id]);
  664.                    
  665.                    
  666.                     $valeur=[];
  667.                     $valeur[]=$value;
  668.                     if ($champsinst->getValeur() != null ) {
  669.                         foreach ($champsinst->getValeur() as $key => $val) {
  670.                             $valeur[]=$val;
  671.                         }
  672.                     }
  673.                     
  674.                     $champsinst->setValeur($valeur);
  675.                     if ($champsinst->getStatus()==null) {
  676.                         $champsinst->setStatus('Non Transmis');
  677.                      }else{
  678.                         $champsinst->setStatus('Transmis');
  679.                      }
  680.                     $date = new Datetime();
  681.                     $champsinst->setDate($date);
  682.                     $champsInstallateurRepository->add($champsinsttrue);
  683.                   
  684.                 }
  685.                 if (count(explode("_",$key)) >&& explode("_",$key)[1]=="old"){
  686.                     
  687.                     $champsInstallateur = new ChampsInstallateur();
  688.                    $chmps$champsRepository->find(["id"=>intval($value)]);
  689.                    if ($chmps) {
  690.                     $champsInstallateur->setNom($chmps->getNom());
  691.                     $champsInstallateur->setType($chmps->getType());
  692.                     $champsInstallateur->setInstallateur($installateur);
  693.                     
  694.                     $champsInstallateur->setStatus('Non Transmis');
  695.                     
  696.                     $champsInstallateurRepository->add($champsInstallateurtrue);
  697.                    }
  698.                    
  699.                 }
  700.                 if ( count(explode("_",$key)) >&& explode("_",$key)[2]=="type") {
  701.                  
  702.                     if (explode("_",$key)[3]=="nom") {
  703.                         $champs->setNom($value);
  704.                         if($champs->getType() != "file"){
  705.                             $champsRepository->add($champstrue);
  706.                             $champsInstallateur = new ChampsInstallateur();
  707.                             // $champsInstallateur->setNom($champs->getNom());
  708.                             // $champsInstallateur->setType($champs->getType());
  709.                             // $champsInstallateur->setInstallateur($installateur);
  710.                             // $champsInstallateur->setStatus('Non Transmis');
  711.                             // $champsInstallateurRepository->add($champsInstallateur, true);
  712.     
  713.                             $champsInstallateur->setNom($champs->getNom());
  714.                             $champsInstallateur->setType($champs->getType());
  715.                             $champsInstallateur->setInstallateur($installateur);
  716.                             $champsInstallateur->setStatus('Non Transmis');
  717.                             $champsInstallateurRepository->add($champsInstallateurtrue);
  718.                             
  719.                             if($this->isGranted("ROLE_INSTALLATEUR") == false || $this->isGranted("ROLE_OBLIGE") == false){
  720.                                 $notifications = new Notifications();
  721.                                 $notifications->setUserId($champsInstallateur->getInstallateur()->getUser());
  722.                                 $notifications->setAction("app_installateur_edit");
  723.                                 $notifications->setMessage("De nouveaux éléments vous sont demandés dans votre profil.");
  724.                                 $notifications->setActionId($champsInstallateur->getInstallateur()->getId());
  725.                                 $notifications->setSender($this->getUser());
  726.                                 $notifications->setStatuts("non lu");
  727.                                 $notifications->setDate(new DateTime());
  728.                             }
  729.     
  730.                             $notificationsRepository->add($notificationstrue);
  731.                         }
  732.                         
  733.                     }elseif(explode("_",$key)[3]=="dure"){
  734.                         if($champs->getType() == "file"){
  735.                             if($value!=null){
  736.                                 $champs->setDurevalidite($value);
  737.                             }
  738.                             
  739.                             $champsRepository->add($champstrue);
  740.                             $champsInstallateur = new ChampsInstallateur();
  741.                             $champsInstallateur->setNom($champs->getNom());
  742.                             $champsInstallateur->setType($champs->getType());
  743.                             $champsInstallateur->setDurevalidite($champs->getDurevalidite());
  744.                             $champsInstallateur->setInstallateur($installateur);
  745.                             $champsInstallateur->setStatus('Non Transmis');
  746.                             $champsInstallateurRepository->add($champsInstallateurtrue);
  747.                             if($this->isGranted("ROLE_INSTALLATEUR") == false || $this->isGranted("ROLE_OBLIGE") == false){
  748.                                 $notifications = new Notifications();
  749.                                 $notifications->setUserId($champsInstallateur->getInstallateur()->getUser());
  750.                                 $notifications->setAction("app_installateur_edit");
  751.                                 $notifications->setMessage("De nouveaux éléments vous sont demandés dans votre profil.");
  752.                                 $notifications->setActionId($champsInstallateur->getInstallateur()->getId());
  753.                                 $notifications->setSender($this->getUser());
  754.                                 $notifications->setStatuts("non lu");
  755.                                 $notifications->setDate(new DateTime());
  756.                             }
  757.                             $notificationsRepository->add($notificationstrue);
  758.                         }
  759.                     }
  760.                     else{
  761.                         
  762.                         $champs = new Champs();
  763.                         $champs->setType($value);
  764.                     }   
  765.                
  766.                 }
  767.             }
  768.             if(!$this->isGranted('ROLE_INSTALLATEUR')){
  769.                 $notifications = new Notifications();
  770.                 $notifications->setUserId($installateur->getUser());
  771.                 $notifications->setAction("app_installateur_edit");
  772.                 $notifications->setMessage("De nouveaux éléments vous sont demandés dans votre profil.");
  773.                 $notifications->setActionId($installateur->getId());
  774.                 $notifications->setSender($this->getUser());
  775.                 $notifications->setStatuts("non lu");
  776.                 $notifications->setDate(new DateTime());
  777.                 $notificationsRepository->add($notificationstrue);
  778.             }
  779.             
  780.             return $this->redirectToRoute('app_installateur_edit', ['id' =>$installateur->getId() ], Response::HTTP_SEE_OTHER);
  781.         }
  782.     
  783.         if ($this->isGranted('ROLE_INSTALLATEUR')) {
  784.             $notif $notificationsRepository->findBy(["user_id" => $installateur->getUser(),"statuts"=> "non lu","action" => "app_installateur_edit""action_id" => $installateur->getId()]);
  785.             if ($notif) {
  786.                 foreach ($notif as $value) {
  787.                     $datefinnotif $value->getDate();
  788.                     $dateday2 = new DateTime();
  789.                     // Ajouter 2 jours
  790.                     $datefinnotif->modify('+2 days');
  791.                    // dd($datefinnotif);
  792.                     // if ($dateday2 > $datefinnotif) {
  793.                     //     $value->setStatuts("lu");
  794.                     //     $notificationsRepository->add($value, true);
  795.                     // }
  796.                      $value->setStatuts("lu");
  797.                      $notificationsRepository->add($valuetrue);
  798.                 }
  799.               
  800.             }
  801.            
  802.         } else {
  803.             
  804.             $admins $equipeRepository->findAll();
  805.             foreach ($admins as $key => $value) {
  806.                 $listPermissions $value->getPermissions();
  807.                 foreach ($listPermissions as $v) {
  808.                     if($v == "NOTIFICATION" ){
  809.                         $notif $notificationsRepository->findBy(["statuts"=> "non lu""action_id" => "app_installateur_edit""action_id" => $installateur->getId()]);
  810.                         if ($notif) {
  811.                             foreach ($notif as $m => $n) {
  812.                                 $isEquipe $equipeRepository->findOneBy(["id" => $n->getUserId()]);
  813.                                if($isEquipe && $isEquipe->getRole() != "ROLE_INSTALLATEUR"){
  814.                                     $n->setStatuts("lu");
  815.                                     $notificationsRepository->add($ntrue);
  816.                                }
  817.                             }
  818.                         }
  819.                     }
  820.                 }
  821.             }
  822.            
  823.         }
  824.         return $this->renderForm('installateur/edit.html.twig', [
  825.             'installateur' => $installateur,
  826.             'champsInstallateurs' =>$champsInstallateurRepository->findAll(),
  827.             'operationsStandars' => $operationStandardRepository->findAll(),
  828.             'csrf_token' => $csrfToken->getValue().'12OU#@R'.$installateur->getId()."A@T9",
  829.             "dateday"=>new Datetime(),
  830.             "isCompleted" => $isCompleted
  831.         ]);
  832.     }
  833.     /**
  834.      * @Route("/{id}", name="app_installateur_delete", methods={"POST"})
  835.      */
  836.     public function delete(Request $requestInstallateur $installateurInstallateurRepository $installateurRepository,UserRepository $userRepository,
  837.     ChampsInstallateurRepository $champsInstallateurRepository,DealRepository $dealRepository,SoustraitantRepository $soustraitantRepository,
  838.     ResetPasswordRequestRepository $resetPasswordRequestRepository,ChampsSoustraitantRepository $champsSoustraitantRepository,
  839.     ChampsDealRepository $champsDealRepository,DepotDossierRepository $depotDossierRepository,ChampsDepotDossierRepository $champsDepotDossierRepository,
  840.     ActiviteDealRepository $activiteDealRepositoryNotificationsRepository $notificationsRepository,CommentairesControlleRepository $commentairesControlleRepository,
  841.     TokenpasswordRepository $tokenpasswordRepository,FactureAafRepository $factureAafRepository,AppelqualiteRepository $appelqualiteRepository,
  842.     CommentaireInstalleurRepository $commentaireInstalleurRepository,ContratRepository $contratRepository): Response
  843.     {
  844.         if ($this->isCsrfTokenValid('delete'.$installateur->getId(), $request->request->get('_token'))) {
  845.             $user=$userRepository->findOneBy(["email"=>$installateur->getEmail()]);
  846.             // var_dump($user->getId());die('test');
  847.  
  848.             
  849.             foreach ($installateur->getOperationStandards() as  $value) {
  850.                
  851.                  $installateur->removeOperationStandard($value);
  852.                 
  853.              }
  854.              foreach ($installateur->getChampsinstallateur() as  $value) {
  855.            
  856.                  $installateur->removeChampsinstallateur($value);
  857.                  $champsInstallateurRepository->remove($valuetrue);
  858.                 
  859.              }
  860.              foreach ($installateur->getCommentaireInstalleurs() as  $value) {
  861.            
  862.                 $installateur->removeCommentaireInstalleur($value);
  863.                 $commentaireInstalleurRepository->remove($valuetrue);
  864.                
  865.             }
  866.            
  867.              
  868.              foreach ($notificationsRepository->findBy(["action_id"=>$installateur->getId()]) as  $value) {
  869.                 $notificationsRepository->remove($valuetrue);
  870.              }
  871.              foreach ($user->getNotifications() as  $value) {
  872.            
  873.                 $user->removeNotification($value);
  874.                 $notificationsRepository->remove($valuetrue);
  875.                
  876.             }
  877.             foreach ($user->getTokenpasswords() as  $value) {
  878.            
  879.                 $user->removeTokenpassword($value);
  880.                 $tokenpasswordRepository->remove($valuetrue);
  881.                
  882.             }
  883.             
  884.             
  885.              foreach ($installateur->getDeals() as  $value) {
  886.                 
  887.                 foreach ($value->getDepotDossiers() as $dossier) {
  888.            
  889.                     foreach ($dossier->getChampsDepotDossiers() as $champdossier) {
  890.                         $champsDepotDossierRepository->remove($champdossiertrue);
  891.                     }
  892.                     foreach ($dossier->getCommentairesControlles() as $commentaire) {
  893.                         $commentairesControlleRepository->remove($commentairetrue);
  894.                     }
  895.                     foreach ($dossier->getFactureAafs() as  $value) {
  896.            
  897.                         // $depotDossier->removeFactureAaf($value);
  898.                         foreach ($value->getCommentaireFactureaafs() as  $commentaire) {
  899.     
  900.                             $value->removeCommentaireFactureaaf($commentaire);
  901.             
  902.                             // $activiteDealRepository->remove($commentaire, true);
  903.                         
  904.                         }
  905.         
  906.                         $factureAafRepository->remove($valuetrue);
  907.                        
  908.                     }
  909.         
  910.                     foreach ($dossier->getAppelqualites() as  $value) {
  911.                    
  912.                         // $depotDossier->removeAppelqualite($value);
  913.                         foreach ($value->getCommentaireAppelqualites() as  $commentaire) {
  914.     
  915.                             $value->removeCommentaireAppelqualite($commentaire);
  916.             
  917.                             // $activiteDealRepository->remove($commentaire, true);
  918.                         
  919.                         }
  920.                         $appelqualiteRepository->remove($valuetrue);
  921.                        
  922.                     }
  923.   
  924.        
  925.                     $depotDossierRepository->remove($dossiertrue);
  926.             
  927.                 }
  928.                 foreach ($value->getChampsdeal() as $champs) {
  929.            
  930.                     // $value->removeChampsSoustraitant($champs);
  931.     
  932.                     $champsDealRepository->remove($champstrue);
  933.             
  934.                 }
  935.                 foreach ($value->getActiviteDeals() as  $activite) {
  936.            
  937.                     $value->removeActiviteDeal($activite);
  938.     
  939.                     $activiteDealRepository->remove($activitetrue);
  940.                    
  941.                 }
  942.                 foreach ($value->getCommentaireDeals() as  $commentaire) {
  943.            
  944.                     $value->removeCommentaireDeal($commentaire);
  945.     
  946.                     // $activiteDealRepository->remove($commentaire, true);
  947.                    
  948.                 }
  949.                 foreach ($value->getHistoriqueDeals() as  $historique) {
  950.            
  951.                     $value->removeHistoriqueDeal($historique);
  952.     
  953.                     // $activiteDealRepository->remove($commentaire, true);
  954.                    
  955.                 }
  956.                 foreach ($value->getSoustraitants() as  $soustritant) {
  957.            
  958.                     $value->removeSoustraitant($soustritant);
  959.     
  960.                     // $activiteDealRepository->remove($commentaire, true);
  961.                    
  962.                 }
  963.                 foreach ($value->getOperation() as  $operation) {
  964.            
  965.                     $value->removeOperation($operation);
  966.     
  967.                 }
  968.                 if($value->getApporteurAffaire()){
  969.                     $value->setApporteurAffaire(NULL);
  970.                 }
  971.                 foreach ($value->getOperation() as  $value) {
  972.            
  973.                     $value->removeOperation($value);
  974.     
  975.                     
  976.                    
  977.                 }
  978.                if ($value->getContrat()) {
  979.                     foreach ($value->getContrat()->getCommentaireContrats() as  $commentaire) {
  980.             
  981.                         $value->getContrat()->removeCommentaireContrat($commentaire);
  982.         
  983.                         // $activiteDealRepository->remove($commentaire, true);
  984.                     
  985.                     }
  986.                     $contratRepository->remove($value->getContrat(), true);
  987.                }
  988.                 
  989.                 $installateur->removeDeal($value);
  990.                 $dealRepository->remove($valuetrue);
  991.         
  992.             }
  993.              
  994.             foreach ($installateur->getSoustraitants() as  $value) {
  995.            
  996.                 foreach ($value->getChampsSoustraitants() as  $champs) {
  997.            
  998.                     $value->removeChampsSoustraitant($champs);
  999.     
  1000.                     $champsSoustraitantRepository->remove($champstrue);
  1001.             
  1002.                 }
  1003.                 foreach ($value->getOperationstandard() as  $operation) {
  1004.            
  1005.                     $value->removeOperationstandard($operation);
  1006.                 }
  1007.                 $installateur->removeSoustraitant($value);
  1008.                 $soustraitantRepository->remove($valuetrue);
  1009.         
  1010.             }
  1011.             foreach ($resetPasswordRequestRepository->findBy(["user"=>$user->getId()]) as  $value) {
  1012.            
  1013.                 
  1014.                 $resetPasswordRequestRepository->remove($valuetrue);
  1015.         
  1016.             }
  1017.            
  1018.             $installateurRepository->remove($installateurtrue);
  1019.             $userRepository->remove($usertrue);
  1020.         }
  1021.         return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
  1022.     }
  1023.     private function processSendingPasswordResetEmail(string $emailFormDataMailerInterface $mailerTranslatorInterface $translator,$destination,$username): RedirectResponse
  1024.     
  1025.         
  1026.         $user $this->entityManager->getRepository(User::class)->findOneBy([
  1027.             'email' => $emailFormData,
  1028.         ]);
  1029.         
  1030.         // Do not reveal whether a user account was found or not.
  1031.         if (!$user) {
  1032.             return $this->redirectToRoute('app_check_email');
  1033.         }
  1034.         
  1035.         try {
  1036.             $resetToken $this->resetPasswordHelper->generateResetToken($user);
  1037.             $tokenpassword = new Tokenpassword();
  1038.             $tokenpassword->setToken($resetToken->getToken());
  1039.             $tokenpassword->setUser($user);
  1040.             $tokenpassword->setDate(new Datetime());
  1041.             $this->entityManager->persist($tokenpassword);
  1042.             $this->entityManager->flush();
  1043.         } catch (ResetPasswordExceptionInterface $e) {
  1044.             // If you want to tell the user why a reset email was not sent, uncomment
  1045.             // the lines below and change the redirect to 'app_forgot_password_request'.
  1046.             // Caution: This may reveal if a user is registered or not.
  1047.             //
  1048.             // $this->addFlash('reset_password_error', sprintf(
  1049.             //     '%s - %s',
  1050.             //     $translator->trans(ResetPasswordExceptionInterface::MESSAGE_PROBLEM_HANDLE, [], 'ResetPasswordBundle'),
  1051.             //     $translator->trans($e->getReason(), [], 'ResetPasswordBundle')
  1052.             // ));
  1053.             // var_dump($e->getReason()); die('test');
  1054.             return $this->redirectToRoute('app_check_email');
  1055.         }
  1056.       
  1057.         $email = (new TemplatedEmail())
  1058.             ->from(new Address('contact@kaje-cee.net''KAJE CEE'))
  1059.             ->to($user->getEmail())
  1060.             ->subject('Nouveau compte KAJE CEE')
  1061.             ->htmlTemplate('email/email-confirmation-compte.html.twig')
  1062.             ->context([
  1063.                 'resetToken' => $resetToken,
  1064.                 'username' => $username
  1065.             ])
  1066.         ;
  1067.         $mailer->send($email);
  1068.         if ($destination=="deal") {
  1069.             return $this->redirectToRoute('app_deal_new', [], Response::HTTP_SEE_OTHER);
  1070.         } else {
  1071.             return $this->redirectToRoute('app_installateur_index', [], Response::HTTP_SEE_OTHER);
  1072.         }
  1073.         
  1074.        
  1075.         // Store the token object in session for retrieval in check-email route.
  1076.         // $this->setTokenObjectInSession($resetToken);
  1077.     }
  1078.     private function processSendingPasswordResetEmailoublier(string $emailFormDataMailerInterface $mailerTranslatorInterface $translator,$destination): RedirectResponse
  1079.     
  1080.         
  1081.         $user $this->entityManager->getRepository(User::class)->findOneBy([
  1082.             'email' => $emailFormData,
  1083.         ]);
  1084.         
  1085.         // Do not reveal whether a user account was found or not.
  1086.         if (!$user) {
  1087.             return $this->redirectToRoute('app_check_email');
  1088.         }
  1089.         try {
  1090.             $resetToken $this->resetPasswordHelper->generateResetToken($user);
  1091.             $tokenpassword = new Tokenpassword();
  1092.             $tokenpassword->setToken($resetToken->getToken());
  1093.             $tokenpassword->setUser($user);
  1094.             $tokenpassword->setDate(new Datetime());
  1095.             $this->entityManager->persist($tokenpassword);
  1096.             $this->entityManager->flush();
  1097.         } catch (ResetPasswordExceptionInterface $e) {
  1098.             // If you want to tell the user why a reset email was not sent, uncomment
  1099.             // the lines below and change the redirect to 'app_forgot_password_request'.
  1100.             // Caution: This may reveal if a user is registered or not.
  1101.             //
  1102.             // $this->addFlash('reset_password_error', sprintf(
  1103.             //     '%s - %s',
  1104.             //     $translator->trans(ResetPasswordExceptionInterface::MESSAGE_PROBLEM_HANDLE, [], 'ResetPasswordBundle'),
  1105.             //     $translator->trans($e->getReason(), [], 'ResetPasswordBundle')
  1106.             // ));
  1107.             // var_dump($e->getReason()); die('test');
  1108.             return $this->redirectToRoute('app_check_email');
  1109.         }
  1110.       
  1111.         $email = (new TemplatedEmail())
  1112.             ->from(new Address('contact@kaje-cee.net''KAJE CEE'))
  1113.             ->to($user->getEmail())
  1114.             ->subject('KAJE CEE - Réinitialiser mon mot de passe')
  1115.             ->htmlTemplate('reset_password/email.html.twig')
  1116.             ->context([
  1117.                 'resetToken' => $resetToken,
  1118.             ])
  1119.         ;
  1120.         $mailer->send($email);
  1121.         return $this->redirectToRoute('app_login');
  1122.         
  1123.        
  1124.         // Store the token object in session for retrieval in check-email route.
  1125.         // $this->setTokenObjectInSession($resetToken);
  1126.     }
  1127.      
  1128.      /**
  1129.      * @Route("/zip/{id}", name="app_installateur_zip", methods={"GET"})
  1130.      */
  1131.     public function zip(Installateur $installateur): Response
  1132.     {
  1133.         
  1134.         // $sourceFolder = $this->getParameter('installateur_directory'). '/rouget'; // Remplacez par le chemin absolu de votre dossier
  1135.         // $filesystem = new Filesystem();
  1136.         // Vérifiez si le dossier existe
  1137.         // if ($filesystem->exists($sourceFolder)) {
  1138.             // Supprimez tous les fichiers et dossiers à l'intérieur du dossier
  1139.             // $filesystem->remove(glob($sourceFolder . '/*'));
  1140.               // Obtenez le nom du fichier à partir du chemin source
  1141.             // foreach ($installateur->getChampsinstallateur() as $value) {
  1142.             //        if ($value->getType()=="file") {
  1143.             //            if ($value->getValeur()!=null) {
  1144.             //             $fileName = pathinfo($this->getParameter('installateur_directory').'/'.$value->getValeur(), PATHINFO_BASENAME);
  1145.     
  1146.             //             // Copiez le fichier vers le dossier de destination
  1147.             //             $sourceFolder = $sourceFolder . '/' . $fileName;
  1148.             //             $filesystem->copy($this->getParameter('installateur_directory').'/'.$value->getValeur(), $sourceFolder);
  1149.             //            }
  1150.             //         }
  1151.                    
  1152.                     
  1153.             // }
  1154.             
  1155.             
  1156.         // }
  1157.         // sleep(5);
  1158.         // Créez un nom de fichier unique pour le fichier ZIP
  1159.         $zipFileName $installateur->getSociete().'_' date('YmdHis') . '.zip';
  1160.     
  1161.         // Créez le chemin absolu vers le fichier ZIP
  1162.         $zipFilePath $this->getParameter('installateur_directory') . '/archiver/' $zipFileName;
  1163.     
  1164.         // Utilisez la classe ZipArchive pour créer le fichier ZIP
  1165.         $zip = new \ZipArchive();
  1166.         $zip->open($zipFilePath\ZipArchive::CREATE \ZipArchive::OVERWRITE);
  1167.     
  1168.         // Utilisez la classe Finder pour parcourir les fichiers du dossier source
  1169.             // $finder = new Finder();
  1170.             // $finder->files()->in($sourceFolder);
  1171.             // foreach ($finder as $file) {
  1172.                 
  1173.             //     $filePath = $file->getRealPath();
  1174.             //     $relativePath = $file->getRelativePath();
  1175.             //     // Ajouter le fichier au dossier compressé
  1176.             //     $zip->addFile($filePath, $relativePath);
  1177.             // }
  1178.             foreach ($installateur->getChampsinstallateur() as $value) {
  1179.                 if ($value->getType()=="file") {
  1180.                     if ($value->getValeur()!=null) {
  1181.                      
  1182.                      $filePath $this->getParameter('installateur_directory').'/'.$value->getValeur()[0];
  1183.                      $relativePath $installateur->getSociete()."/".$value->getValeur()[0];
  1184.                      if (file_exists($filePath)) {
  1185.                         $zip->addFile($filePath$relativePath);
  1186.                     }
  1187.                     // $zip->addFile($filePath, $relativePath);
  1188.                     }
  1189.                  }
  1190.                 
  1191.                  
  1192.          }
  1193.             // Fermer le fichier ZIP
  1194.             $zip->close();
  1195.             // Envoyer le fichier ZIP en tant que réponse de téléchargement
  1196.             $response = new BinaryFileResponse($zipFilePath);
  1197.             $response->headers->set('Content-Type''application/zip');
  1198.             $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$zipFileName);
  1199.             // if ($filesystem->exists($sourceFolder)) {
  1200.             //     // Supprimez tous les fichiers et dossiers à l'intérieur du dossier
  1201.             //     $filesystem->remove(glob($sourceFolder . '/*'));
  1202.             // }
  1203.             return $response;
  1204.                 // return $this->redirectToRoute('app_installateur_sow', ['id' => $this->getUser()->getInstallateur()->getId()], Response::HTTP_SEE_OTHER);
  1205.       
  1206.        
  1207.         
  1208.     }
  1209.    
  1210.        /**
  1211.      * @Route("/document/{id}/{document}", name="app_installateur_document", methods={"GET"})
  1212.      */
  1213.     public function document(InstallateurRepository $installateurRepositoryint $idint $document): Response
  1214.     {
  1215.         $installateur$installateurRepository->findOneBy(["id" => $id]);
  1216.         return $this->render('documents/index.html.twig', [
  1217.             'installateur' => $installateur,
  1218.             "document" => intval($document)
  1219.         ]);
  1220.     }
  1221.      /**
  1222.      * @Route("/commentaire/{id}", methods={"POST"})
  1223.      */
  1224.     public function commentaire(Request $request,CommentaireInstalleurRepository $commentaireInstalleurRepository,Installateur $installateur,NotificationsRepository $notificationsRepository): JsonResponse
  1225.     
  1226.         
  1227.         
  1228.   
  1229.         if ($request->getMethod() == "POST") {
  1230.             
  1231.             // $file=$request->files->get('validedocument');
  1232.             $commentaire $request->request->get('commentaire');
  1233.           
  1234.              if ($commentaire) {
  1235.                
  1236.                     $commentaireInstalleur = new CommentaireInstalleur();
  1237.                     
  1238.                     $commentaireInstalleur->setCommentaire($commentaire);
  1239.                     $commentaireInstalleur->setDate(new DateTime());
  1240.                     $commentaireInstalleur->setInstalleur($installateur);
  1241.                     $commentaireInstalleur->setUser($this->getUser());
  1242.                     $commentaireInstalleurRepository->add($commentaireInstalleurtrue);
  1243.                     $notifications = new Notifications();
  1244.                     $notifications->setUserId($installateur->getUser());
  1245.                     $notifications->setMessage("Un commentaire a été posté dans votre profil.");
  1246.                     $notifications->setAction("app_installateur_edit");
  1247.                     $notifications->setActionId($installateur->getId());
  1248.                     $notifications->setSender($this->getUser());
  1249.                     $notifications->setStatuts("non lu");
  1250.                     $notifications->setDate(new DateTime());      
  1251.                     $notificationsRepository->add($notificationstrue);
  1252.                     return $this->json(['success' => true'message' => 'commentaire ajouter ']);
  1253.              }
  1254.         }
  1255.         return $this->json(['success' => false'error' => 'Erreur ']);
  1256.     }
  1257.      /**
  1258.      * @Route("/archiverinstallateur/{id}", methods={"POST"})
  1259.      */
  1260.     public function archiverinstallateur(Request $request,InstallateurRepository $installateurRepository,Installateur $installateur,DealRepository $dealRepository,
  1261.     DepotDossierRepository $depotDossierRepository): JsonResponse
  1262.     
  1263.         
  1264.         
  1265.   
  1266.         if ($request->getMethod() == "POST") {
  1267.             
  1268.             // $file=$request->files->get('validedocument');
  1269.             $id $request->request->get('id');
  1270.           
  1271.              if ($id) {
  1272.                     $installateur->setArchive($installateur->getStatus());
  1273.                     $installateur->setStatus("archive"); 
  1274.                     foreach ($installateur->getDeals() as $key => $deal) {
  1275.                            foreach ($deal->getDepotDossiers() as $key => $dossier) {
  1276.                                 $dossier->setArchive($deal->getStatus());
  1277.                                 $dossier->setStatus("archive"); 
  1278.                                 $depotDossierRepository->add($dossiertrue);
  1279.                            }
  1280.                            $deal->setArchive($deal->getStatus());
  1281.                            $deal->setStatus("archive");
  1282.                            $dealRepository->add($dealtrue);
  1283.                     }     
  1284.                     $installateurRepository->add($installateurtrue);
  1285.                     return $this->json(['success' => true'message' => 'installateur archive']);
  1286.              }
  1287.         }
  1288.         return $this->json(['success' => false'error' => 'Erreur ']);
  1289.     }
  1290.     
  1291.     
  1292.     /**
  1293.      * @Route("/suprimercommentaire/{id}", methods={"POST"})
  1294.      */
  1295.     public function suprimercommentaire(Request $request ,CommentaireInstalleurRepository $commentaireInstalleurRepository,CommentaireInstalleur $commentaireInstalleur): JsonResponse
  1296.     
  1297.         
  1298.         
  1299.   
  1300.         if ($request->getMethod() == "POST") {
  1301.             
  1302.             // $file=$request->files->get('validedocument');
  1303.             $id $request->request->get('id');
  1304.             
  1305.              if ($id) {
  1306.                     
  1307.                 $commentaireInstalleurRepository->remove($commentaireInstalleurtrue);
  1308.                    
  1309.                     
  1310.                     return $this->json(['success' => true'message' => 'champs supprimer succès']);
  1311.              }
  1312.         }
  1313.         return $this->json(['success' => false'error' => 'Erreur ']);
  1314.     }
  1315. }