src/Controller/DepotAnnonceController.php line 72

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * @author Mehrez Labidi
  5.  */
  6. namespace App\Controller;
  7. use App\Entity\Model\Annonces;
  8. use App\Entity\DetailsAnnoncePartenariat;
  9. use App\Entity\PeriodesAnnoncePrioritaire;
  10. use App\Form\Models\DepotAnnonce\DepotAnnonceFirstStep;
  11. use App\Form\Type\DepotAnnonce\{
  12.     DepotAnnonceFirstStepType,
  13.     DepotAnnonceSecondStepType,
  14.     DepotAnnonceThirdStepType
  15. };
  16. use App\Helper\Utils;
  17. use App\Services\Annonces\DepotAnnonce;
  18. use Symfony\Component\HttpFoundation\{
  19.     Request,
  20.     Response
  21. };
  22. use Symfony\Component\Form\Extension\Core\Type\{
  23.     RadioType,
  24.     SubmitType,
  25.     ChoiceType
  26. };
  27. use App\Services\PDFGenerator;
  28. use App\Services\LogMarketingProvider;
  29. use Symfony\Component\Form\Forms;
  30. use Doctrine\ORM\EntityManagerInterface;
  31. use App\Entity\StatistiquesNbConsultationsAnnoncesVendeurEntity;
  32. use App\Entity\StatistiquesNbConsultationsAnnoncesAcheteurEntity;
  33. use App\Exception\MissingMandatoryParams;
  34. use App\Services\ManagerEntity\PropositionsAcquereurs;
  35. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  36. use Psr\Log\LoggerInterface;
  37. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  38. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  39. class DepotAnnonceController extends EntityUsingController {
  40.     public const MAX_AGE 43200// 12heures
  41.     /**
  42.      * @var DepotAnnonce
  43.      */
  44.     private $depotAnnonceService;
  45.     /**
  46.      * @var PDFGenerator
  47.      */
  48.     private $pf;
  49.     /**
  50.      * @var LogMarketingProvider
  51.      */
  52.     private $lmp;
  53.     /**
  54.      * @var EntityManagerInterface
  55.      */
  56.     private $em;
  57.     /**
  58.      * 
  59.      * @return Response
  60.      */
  61.     public function index(): Response {
  62.         if ($this->getUser()) { //   authentifié
  63.             $response $this->render('annonces/depot-annonce/index.html.twig', [
  64.                 'controller_name' => 'DepotAnnonceController',
  65.             ]);
  66.         } else { // non  authentifié
  67.             $response $this->render('annonces/depot-annonce/no_auth_index.html.twig', [
  68.                 'controller_name' => 'DepotAnnonceController',
  69.             ]);
  70.         }
  71.         $response->setPublic();
  72.         $response->setMaxAge(self::MAX_AGE); // 12heures
  73.         return $response;
  74.     }
  75.     /**
  76.      * @param Request $request
  77.      * @param type $codePays
  78.      * @return type
  79.      */
  80.     public function depotFirstStep(Request $request$codePays) {
  81.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  82.         $model = new DepotAnnonceFirstStep();
  83.         $form $this->createForm(DepotAnnonceFirstStepType::class, $model, [
  84.             'action' => $this->generateUrl(
  85.                     $request->attributes->get('_route'),
  86.                     [
  87.                         'codePays' => $codePays,
  88.                     ]
  89.             ),
  90.             'method' => 'POST',
  91.         ]);
  92.         if ($request->isMethod('POST')) {
  93.             $form->submit($request->request->get($form->getName()));
  94.             if ($form->isSubmitted() && $form->isValid()) {
  95.                 $data $form->getData();
  96.                 $annonce $this->depotAnnonceService->enregistreAnnonceFirstStep((array) $data);
  97.                 $userIdentity $this->getUser();
  98.                 $typeRaprochement $data->getTypeAnnonce();
  99.                 if ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_CESSION) {
  100.                     //stats annonce insertion quand dept
  101.                     $statsAnnonce $this->em->getRepository(StatistiquesNbConsultationsAnnoncesVendeurEntity::class)->find($annonce->getId());
  102.                     if (empty($statsAnnonce)) {
  103.                         $statsAnnonce = new StatistiquesNbConsultationsAnnoncesVendeurEntity();
  104.                         $statsAnnonce->_set("id_annonce"$annonce->getId());
  105.                         $statsAnnonce->_set("nb_consultations"0);
  106.                         $this->em->persist($statsAnnonce);
  107.                         $this->em->flush();
  108.                     }
  109.                     //ajouter l'action <<  Création annonce cession entreprise >> dans les logs_actions, type_action n°3
  110.                     $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(3), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  111.                 } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_CESSION_ACTIF) {
  112.                     //stats annonce insertion quand dept
  113.                     $statsAnnonce $this->em->getRepository(StatistiquesNbConsultationsAnnoncesVendeurEntity::class)->find($annonce->getId());
  114.                     if (empty($statsAnnonce)) {
  115.                         $statsAnnonce = new StatistiquesNbConsultationsAnnoncesVendeurEntity();
  116.                         $statsAnnonce->_set("id_annonce"$annonce->getId());
  117.                         $statsAnnonce->_set("nb_consultations"0);
  118.                         $this->em->persist($statsAnnonce);
  119.                         $this->em->flush();
  120.                     }
  121.                     //ajouter l'action <<  Création annonce cession actif >> dans les logs_actions, type_action n°4
  122.                     $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(4), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  123.                 } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_LEVEE_FONDS) {
  124.                     //stats annonce insertion quand dept
  125.                     $statsAnnonce $this->em->getRepository(StatistiquesNbConsultationsAnnoncesVendeurEntity::class)->find($annonce->getId());
  126.                     if (empty($statsAnnonce)) {
  127.                         $statsAnnonce = new StatistiquesNbConsultationsAnnoncesVendeurEntity();
  128.                         $statsAnnonce->_set("id_annonce"$annonce->getId());
  129.                         $statsAnnonce->_set("nb_consultations"0);
  130.                         $this->em->persist($statsAnnonce);
  131.                         $this->em->flush();
  132.                     }
  133.                     //ajouter l'action <<  Création annonce levée de fonds >> dans les logs_actions, type_action n°27
  134.                     $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(27), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  135.                 } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_ACQUISITION) {
  136.                     //stats annonce insertion quand dept
  137.                     $statsAnnonce $this->em->getRepository(StatistiquesNbConsultationsAnnoncesAcheteurEntity::class)->find($annonce->getId());
  138.                     if (empty($statsAnnonce)) {
  139.                         $statsAnnonce = new StatistiquesNbConsultationsAnnoncesAcheteurEntity();
  140.                         $statsAnnonce->_set("id_annonce"$annonce->getId());
  141.                         $statsAnnonce->_set("nb_consultations"0);
  142.                         $this->em->persist($statsAnnonce);
  143.                         $this->em->flush();
  144.                     }
  145.                     //ajouter l'action <<  Création annonce cession acquisition >> dans les logs_actions, type_action n°5
  146.                     $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(5), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  147.                 } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENTE_PARTENARIAT) {
  148.                     //stats annonce insertion quand dept
  149.                     $statsAnnonce $this->em->getRepository(StatistiquesNbConsultationsAnnoncesAcheteurEntity::class)->find($annonce->getId());
  150.                     if (empty($statsAnnonce)) {
  151.                         $statsAnnonce = new StatistiquesNbConsultationsAnnoncesAcheteurEntity();
  152.                         $statsAnnonce->_set("id_annonce"$annonce->getId());
  153.                         $statsAnnonce->_set("nb_consultations"0);
  154.                         $this->em->persist($statsAnnonce);
  155.                         $this->em->flush();
  156.                     }
  157.                     //ajouter l'action <<  Création annonce cession partenariat >> dans les logs_actions, type_action n°6
  158.                     $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(6), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  159.                 }
  160.                 return $this->redirectToRoute('depot_annonce_second_step', [// depotSecondStep
  161.                             'codePays' => $codePays,
  162.                             'type_raprochement' => $annonce->_get('type_raprochement'),
  163.                             'id_annonce' => $annonce->getId()
  164.                                 ]
  165.                         );
  166.             } else {
  167.                 $this->get('session')->getFlashBag()->clear(); // Clear tous les flashbags
  168.                 $this->addFlash('error_depot_annonce_first_step''Le formulaire contient des champs invalides');
  169.             }
  170.         }
  171.         $response $this->render('annonces/depot-annonce/first_step.html.twig', [
  172.             'controller_name' => 'DepotAnnonceController',
  173.             'form' => $form->createView(),
  174.         ]);
  175.         $response->setPublic();
  176.         $response->setMaxAge(self::MAX_AGE); // 12heures
  177.         return $response;
  178.     }
  179.     /**
  180.      * @IsGranted("ROLE_USER")
  181.      * @IsGranted("VIEW_OWN_ANNONCE")
  182.      */
  183.     public function depotSecondStep(Request $request$id_annonce$type_raprochement$codePays) {
  184.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  185.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  186.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->find($id_annonce);
  187.         if (!$annonce) {
  188.             throw $this->createNotFoundException('annonce ' $type_raprochement ' introuvable avec id ' $id_annonce);
  189.         }
  190.  
  191.         if ($annonce->getTypeRaprochement() == NULL && $type_raprochement != NULL) {
  192.             $annonce->_set('type_raprochement'$type_raprochement);
  193.         }
  194.         $dataAnnonce Utils::convertObjectToArray($annonce);
  195.         if (Annonces::$TYPE_ID_ANNONCE[$annonce->getTypeRaprochement()] == 'V') {
  196.             $dataDevise $this->depotAnnonceService->getDataAnnonceDevise('V'$dataAnnonce['id_annonce_vendeur']);
  197.             if (!empty($dataDevise)) {
  198.                 $dataAnnonce array_merge($dataAnnonce$dataDevise);
  199.             }
  200.         }
  201.         if (Annonces::$TYPE_ID_ANNONCE[$annonce->getTypeRaprochement()] == 'A') {
  202.             $dataDevise $this->depotAnnonceService->getDataAnnonceDevise('A'$dataAnnonce['id_annonce_acheteur']);
  203.             if (!empty($dataDevise)) {
  204.                 $dataAnnonce array_merge($dataAnnonce$dataDevise);
  205.             }
  206.         }
  207.         if ($annonce->getTypeRaprochement() === array_keys(Annonces::$TYPE_RAPROCHEMENT)[4]) { // exception pour annonce acheteur partenaire
  208.             $detailsAnnoncePartenariat $this->getDoctrine()->getRepository(DetailsAnnoncePartenariat::class)->findOneBy(array('id_annonce_acheteur' => $id_annonce));
  209.             if (!$detailsAnnoncePartenariat) {// exception pour annonce acheteur partenaire
  210.                 //  throw $this->createNotFoundException('annonce details_annonce_partenariat introuvable pour id annonce acheteur ' . $id_annonce);
  211.             // on fusionne les données annonce acheteur + details_annonce_partenariat
  212.             $dataAnnonce array_merge($dataAnnonceUtils::convertObjectToArray($detailsAnnoncePartenariat));
  213.         }
  214.         $form $this->createForm(DepotAnnonceSecondStepType::class, $dataAnnonce, [
  215.             'action' => $this->generateUrl(
  216.                     $request->attributes->get('_route'),
  217.                     [
  218.                         'codePays' => $codePays,
  219.                         'type_raprochement' => $annonce->getTypeRaprochement() ?? $type_raprochement,
  220.                         'id_annonce' => $id_annonce,
  221.                     ]
  222.             ),
  223.             'method' => 'POST',
  224.             'devise' => $dataAnnonce['devise'] ?? 'EUR',
  225.             'type_raprochement' => $annonce->getTypeRaprochement() ?? $type_raprochement,
  226.             'mode_annonce' => $annonce->_get("mode_annonce")
  227.                 ]
  228.         );
  229.         $displayModalGrandesRegions true;
  230.         if ($request->isMethod('POST')) {
  231.             $form->submit($request->request->get($form->getName()));
  232.             if ($form->isSubmitted()) {
  233.                 if ($form->getClickedButton() && DepotAnnonceSecondStepType::$BOUTON_METTRE_EN_LIGNE === $form->getClickedButton()->getName()) {
  234.                     if ($form->isValid()) {
  235.                         $data $form->getData();
  236.                         $annonce $this->depotAnnonceService->enregistreAnnonceSecondStep($dataDepotAnnonceSecondStepType::$BOUTON_METTRE_EN_LIGNE);
  237.                         //redirection vers capital immateriel
  238.                         if ($annonce && in_array($annonce->getTypeRaprochement(), Annonces::$TYPE_RAPROCHEMENT_ANNONCE_CAPITAL_IMMATERIEL)) {//redirection vers capital immateriel
  239.                             return $this->redirectToRoute('depot_annonce_capital_immateriel_index',
  240.                                             [
  241.                                                 'codePays' => $codePays,
  242.                                                 'type_raprochement' => $annonce->getTypeRaprochement() ?? $type_raprochement,
  243.                                                 'id_annonce' => $annonce->getId()
  244.                                             ]
  245.                                     );
  246.                         }
  247.                         return $this->redirectToRoute('depot_annonce_third_step',
  248.                                         [// depotThirdtep
  249.                                             'codePays' => $codePays,
  250.                                             'type_raprochement' => $annonce->getTypeRaprochement() ?? $type_raprochement,
  251.                                             'id_annonce' => $annonce->getId()
  252.                                         ]
  253.                                 );
  254.                     } else {
  255.                         $this->get('session')->getFlashBag()->clear(); // Clear tous les flashbags
  256.                         $this->addFlash('error_depot_annonce_second_step'"Votre annonce ne peut pas être publiée. Certains champs sont vides ou invalides.");
  257.                     }
  258.                 }
  259.                 if ($form->getClickedButton() && DepotAnnonceSecondStepType::$BOUTON_ENREGISTRER_TEMPORAIREMENT === $form->getClickedButton()->getName()) {
  260.                     $form->clearErrors(true);
  261.                     $data $form->getData();
  262.                     $annonce $this->depotAnnonceService->enregistreAnnonceSecondStep($dataDepotAnnonceSecondStepType::$BOUTON_ENREGISTRER_TEMPORAIREMENT);
  263.                     $this->get('session')->getFlashBag()->clear(); // Clear tous les flashbags
  264.                     $this->addFlash('success_depot_annonce''Votre annonce a bien été enregistrée. Vous pouvez la compléter ultérieurement');
  265.                 }
  266.             }
  267.         }
  268.         $hasServiceAnnoncePrio false;
  269.         if (!empty($annonce->_get("id_period_annonce_prioritaire"))) {
  270.             $periodeAnnoncePrioritaire $this->getDoctrine()->getRepository(PeriodesAnnoncePrioritaire::class)->find($annonce->_get("id_period_annonce_prioritaire"));
  271.             if (!empty($periodeAnnoncePrioritaire) && $periodeAnnoncePrioritaire->_get("etat") != "annule" && $periodeAnnoncePrioritaire->_get("etat") != "fini" && $periodeAnnoncePrioritaire->_get("etat") != "attente") {
  272.                 $hasServiceAnnoncePrio true;
  273.             }
  274.         }
  275.         $response $this->render("annonces/depot-annonce/$type_raprochement.html.twig", [
  276.             "controller_name" => "DepotAnnonceController",
  277.             "form" => $form->createView(),
  278.             "hasServiceAnnoncePrio" => $hasServiceAnnoncePrio,
  279.             "annonce" => $annonce"id_annonce" => $id_annonce,
  280.             "displayModalGrandesRegions" => $displayModalGrandesRegions,
  281.             "type_raprochement" => $type_raprochement
  282.         ]);
  283.         $response->setPublic();
  284.         $response->setMaxAge(self::MAX_AGE); // 12heures
  285.         return $response;
  286.     }
  287.     /**
  288.      * @IsGranted("ROLE_USER")
  289.      * @IsGranted("VIEW_OWN_ANNONCE")
  290.      */
  291.     public function depotThirdStep(Request $request$id_annonce$type_raprochement$codePays) {
  292.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  293.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  294.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->find($id_annonce);
  295.         if (!$annonce) {
  296.             throw $this->createNotFoundException('annonce ' $type_raprochement ' introuvable avec id ' $id_annonce);
  297.         }
  298.         
  299.         $form $this->createForm(DepotAnnonceThirdStepType::class, Utils::convertObjectToArray($annonce),
  300.                 [
  301.                     'action' => $this->generateUrl(
  302.                             "depot_annonce_fourth_step",
  303.                             [
  304.                                 'codePays' => $codePays,
  305.                                 'type_raprochement' => $type_raprochement,
  306.                                 'id_annonce' => $id_annonce,
  307.                             ]
  308.                     ),
  309.                     'method' => 'POST''type_raprochement' => $type_raprochement
  310.         ]);
  311.         $propositionAnnonceElite $this->depotAnnonceService->propositionAnnonceEliteSemaineGratuite($id_annonce);
  312.         $charIdAnnonce Annonces::$TYPE_ID_ANNONCE[$type_raprochement];
  313.         $response $this->render('annonces/depot-annonce/third_step.html.twig', [
  314.             'controller_name' => "DepotAnnonceController",
  315.             "annonce" => $annonce"id_annonce" => $id_annonce"type_raprochement" => $type_raprochement,
  316.             "charIdAnnonce" => $charIdAnnonce,
  317.             "propositionAnnonceElite" => $propositionAnnonceElite ?? false,
  318.             "form" => $form->createView(),
  319.         ]);
  320.         $response->setPublic();
  321.         $response->setMaxAge(self::MAX_AGE); // 12heures
  322.         return $response;
  323.     }
  324.     /**
  325.      * @IsGranted("ROLE_USER")
  326.      * @IsGranted("VIEW_OWN_ANNONCE")
  327.      */
  328.     public function depotFourthStep(Request $request$id_annonce$type_raprochement$codePays) {
  329.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  330.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  331.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->find($id_annonce);
  332.         if (!$annonce) {
  333.             throw $this->createNotFoundException('annonce ' $type_raprochement ' introuvable avec id ' $id_annonce);
  334.         }
  335.         
  336.         $data $request->request->get('form');
  337.         if (!empty($data)) {
  338.             $data['type_raprochement'] = !empty($data['type_raprochement']) ? $data['type_raprochement'] : $type_raprochement;
  339.             $annonce $this->depotAnnonceService->enregistreAnnonceThirdStep($data$annonce);
  340.         }
  341.         $formFactory Forms::createFormFactoryBuilder()->getFormFactory();
  342.         $form $formFactory->createBuilder()
  343.                 ->add('remonter'ChoiceType::class, [
  344.                     'choices' => ["true""false"],
  345.                     'expanded' => true,
  346.                     'multiple' => false
  347.                 ])
  348.                 ->add('btn_submit'SubmitType::class, [
  349.                     'label' => "terminer",
  350.                     'attr' => [
  351.                         'class' => "button-rond"
  352.                     ],
  353.                 ])
  354.                 ->setAction($this->generateUrl('depot_annonce_fifth_step', ['codePays' => $codePays'type_raprochement' => $type_raprochement'id_annonce' => $id_annonce]))
  355.                 ->setMethod('POST')
  356.                 ->getForm();
  357.         $response $this->render('annonces/depot-annonce/fourth_step.html.twig', [
  358.             'controller_name' => 'DepotAnnonceController'"form" => $form->createView(), 'annonce' => $annonce
  359.         ]);
  360.         $response->setPublic();
  361.         $response->setMaxAge(self::MAX_AGE); // 12heures
  362.         return $response;
  363.     }
  364.     /**
  365.      * @IsGranted("ROLE_USER")
  366.      * @IsGranted("VIEW_OWN_ANNONCE")
  367.      */
  368.     public function depotFifthStep(Request $request$id_annonce$type_raprochement$codePays) {
  369.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  370.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  371.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->find($id_annonce);
  372.         if (!$annonce) {
  373.             throw $this->createNotFoundException('annonce ' $type_raprochement ' introuvable avec id ' $id_annonce);
  374.         }
  375.      
  376.         $userIdentity $this->getUser();
  377.         $typeRaprochement $type_raprochement;
  378.         if ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_CESSION) {
  379.             //ajouter l'action <<  Demande mise en ligne annonce cession entreprise  >> dans les logs_actions, type_action n°7
  380.             $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(7), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  381.         } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_CESSION_ACTIF) {
  382.             //ajouter l'action <<  Demande mise en ligne annonce cession actif >> dans les logs_actions, type_action n°8
  383.             $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(8), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  384.         } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_LEVEE_FONDS) {
  385.             //ajouter l'action <<  Demande mise en ligne annonce levée de fonds >> dans les logs_actions, type_action n°28
  386.             $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(28), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  387.         } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENT_ACQUISITION) {
  388.             //ajouter l'action <<  Demande mise en ligne annonce acquisition >> dans les logs_actions, type_action n°9
  389.             $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(9), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  390.         } elseif ($typeRaprochement == Annonces::$TYPE_RAPROCHEMENTE_PARTENARIAT) {
  391.             //ajouter l'action <<  Demande mise en ligne annonce partenariat >> dans les logs_actions, type_action n°10
  392.             $this->lmp->ajouterActionLogsActions($userIdentity->_get('id_utilisateur'), intval(10), $userIdentity->_get('type_utilisateur'), $annonce->getId());
  393.         }
  394.         $form $request->request->get('form');
  395.         if (!empty($form)) { // save archive
  396.             $remonter Utils::transformStringBoolToBool($form["remonter"]);
  397.             $res $this->depotAnnonceService->enregistreAnnonceFourthStep($remonter$annonce$id_annonce$type_raprochement);
  398.             if (!empty($res)) {
  399.                 if ($res == "non_active_carte") {
  400.                     return $this->redirect('/compte/facturation/carte-bancaire');
  401.                 }
  402.                 if ($res == "non_cordonnee") {
  403.                     return $this->redirect('/compte/facturation');
  404.                 }
  405.             }
  406.         }
  407.         if (in_array($typeRaprochementAnnonces::$TYPE_RAPROCHEMENT_VENDEUR)) {// ( Voir des propositions d'acquéreurs )
  408.             $id_secteur $annonce->_get('id_secteur_activite');
  409.             $id_pays $annonce->_get('id_pays');
  410.             $id_region $annonce->_get('id_region');
  411.             $id_departement $annonce->_get('id_departement');
  412.             $id_localisation Utils::getLocalisationPlusPrecisPossible($id_pays$id_region$id_departement);
  413.             $nbAnnoncesAcquisitions $this->pa->getNbAnnoncesAcquisitions($id_localisation$id_secteur);
  414.             $nbCVrepreneurs $this->pa->getNbCVrepreneurs($id_localisation$id_secteurnull);
  415.             $nbAcheteursPotentiels $this->pa->getNbAcheteursPotentiels($id_localisation$id_secteur);
  416.             $nbInvestisseursAcquereurs $this->pa->getNbInvestisseursAcquereurs($id_localisation$id_secteur);
  417.             $nbTransactionComparable $this->pa->getNbAnnonceVenteCR((string) $id_secteur);
  418.             $propositions = [
  419.                 "annonces_acquisitions" => [
  420.                     "nb" => $nbAnnoncesAcquisitions,
  421.                     "lien" => $this->pa->generateLien($codePays$id_secteur$id_pays$id_region$id_departement)['lienNbAnnoncesAcquisitions'],
  422.                 ],
  423.                 "cv_repreneurs" => [
  424.                     "nb" => $nbCVrepreneurs,
  425.                     "lien" => $this->pa->generateLien($codePays$id_secteur$id_pays$id_region$id_departement)['lienNbCVrepreneurs'],
  426.                 ],
  427.                 "acheteurs_potentiels" => [
  428.                     "nb" => $nbAcheteursPotentiels,
  429.                     "lien" => $this->pa->generateLien($codePays$id_secteur$id_pays$id_region$id_departement)['lienNbAcheteursPotentiels'],
  430.                 ],
  431.                 "investisseurs_acquereurs" => [
  432.                     "nb" => $nbInvestisseursAcquereurs,
  433.                     "lien" => $this->pa->generateLien($codePays$id_secteur$id_pays$id_region$id_departement)['lienNbInvestisseursAcquereurs'],
  434.                 ],
  435.                 "transaction_comparable" => [
  436.                     "nb" => $nbTransactionComparable,
  437.                     "lien" => $this->pa->generateLien($codePays$id_secteur$id_pays$id_region$id_departement)['lienNbTransactionComparable'],
  438.                 ]
  439.             ];
  440.         }
  441.         $response $this->render('annonces/depot-annonce/fifth_step.html.twig', [
  442.             'controller_name' => 'DepotAnnonceController',
  443.             "propositions" => $propositions ?? [],
  444.             "type_raprochement" => $type_raprochement
  445.         ]);
  446.         $response->setPublic();
  447.         $response->setMaxAge(self::MAX_AGE); // 12heures
  448.         return $response;
  449.     }
  450.     /**
  451.      * @param DepotAnnonce $depotAnnonceService
  452.      * @param PDFGenerator $pf
  453.      */
  454.     public function __construct(LoggerInterface $loggerDepotAnnonce $depotAnnonceServicePDFGenerator $pfEntityManagerInterface $emLogMarketingProvider $lmpPropositionsAcquereurs $paUrlGeneratorInterface $urlGenerator) {
  455.         $this->depotAnnonceService $depotAnnonceService;
  456.         $this->pf $pf;
  457.         $this->lmp $lmp;
  458.         $this->em $em;
  459.         $this->pa $pa;
  460.         $this->urlGenerator $urlGenerator;
  461.         $this->logger $logger;
  462.     }
  463.     /**
  464.      * 
  465.      * @param Request $request
  466.      * @param type $type_raprochement
  467.      * @param type $id_annonce
  468.      * @param type $lang
  469.      * @param type $codePays
  470.      * @throws type
  471.      */
  472.     public function imprimerAnnonce(Request $request$type_raprochement$id_annonce$lang$codePays) {
  473.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  474.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  475.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->findAnnonceWithDetailsById($id_annonce);
  476.         $arr array_merge(['lang' => $lang'type' => Annonces::$TYPE_ID_ANNONCE[$type_raprochement], 'id' => $id_annonce], $annonce);
  477.         if (!array_key_exists("devise"$arr)) {
  478.             $arr["devise"] = "EUR";
  479.         }
  480.         $arr["date_demande_publication"] = ($arr["date_demande_publication"]) ? Utils::getDateObjectFromFUSACQDate($arr["date_demande_publication"]) : NULL;
  481.         $arr["type_raprochement"] = $type_raprochement;
  482.         return $this->pf->generatePDFviewBrowser(
  483.                         'templates_pdf/annonces/print.html.twig'$arr'impression annonce de ' $type_raprochement'impression annonce'
  484.                 );
  485.     }
  486.     /**
  487.      * @IsGranted("ROLE_USER")
  488.      * @IsGranted("VIEW_OWN_ANNONCE")
  489.      */
  490.     public function changeModeAnnonce(Request $request$type_raprochement$action$id_annonce$codePays) {
  491.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification 
  492.         if (!isset($type_raprochement) || !isset($action) || !isset($id_annonce)) {
  493.             throw new MissingMandatoryParams();
  494.         }
  495.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  496.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->find($id_annonce);
  497.         $this->depotAnnonceService->changeModeAnnonce($action$annonce);
  498.         if ($action == "attente_envoi") {
  499.             return $this->redirectToRoute('compte_annonce_attente', ['codePays' => $codePays]);
  500.         }
  501.         return $this->redirectToRoute('compte_annonce_publique', ['codePays' => $codePays]);
  502.     }
  503.     /**
  504.      * @IsGranted("ROLE_USER")
  505.      * @IsGranted("VIEW_OWN_ANNONCE")
  506.      */
  507.     public function switchAnnoncePrioritaire(Request $request$type_raprochement$id_annonce$codePays) {
  508.         $this->denyAccessUnlessGranted('ROLE_USER'); //  page inaccessible sans authentification
  509.         if (!isset($type_raprochement) || !isset($id_annonce)) {
  510.             throw new MissingMandatoryParams();
  511.         }
  512.         $entityAnnonce Annonces::getEntityAnnonceByTypeRaprochement($type_raprochement); // type_raprochement: validé dans le routing depot_annonce_routing.yml
  513.         $annonce $this->getDoctrine()->getRepository($entityAnnonce)->find($id_annonce);
  514.         if ($request->isMethod('POST')) {
  515.             $souscrire $request->request->get('souscrire');
  516.             $page $request->request->get('page');
  517.             $res $this->depotAnnonceService->switchAnnoncePrioritaire($souscrire$annonce$id_annonce$type_raprochement);
  518.             if (!empty($res)) {
  519.                 if ($res == "non_active_carte") {
  520.                     return $this->redirect('/compte/facturation/carte-bancaire');
  521.                 }
  522.                 if ($res == "non_cordonnee") {
  523.                     return $this->redirect('/compte/facturation');
  524.                 }
  525.             }
  526.             if ($page == "detail-annonce") {
  527.                 return $this->redirectToRoute('depot_annonce_second_step', ['type_raprochement' => $type_raprochement'id_annonce' => $id_annonce'codePays' => $codePays]);
  528.             }
  529.         }
  530.         return $this->redirectToRoute('compte_annonce_publique', ['codePays' => $codePays]);
  531.     }
  532.  
  533. }