src/Controller/DefaultController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Action;
  4. use App\Entity\Conversation;
  5. use App\Entity\Recherche;
  6. use App\Entity\Secteur;
  7. use App\Entity\SocietyList;
  8. use App\Entity\User;
  9. use App\Form\ActionType;
  10. use App\Repository\ActionRepository;
  11. use App\Repository\SecteurRepository;
  12. use App\Service\Siren;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. class DefaultController extends AbstractController
  19. {
  20.     /**
  21.      * @Route("", name="default")
  22.      */
  23.     public function index(Siren $sirenRequest $requestActionRepository $actionRepository): Response
  24.     {
  25.         $entityManager $this->getDoctrine()->getManager();
  26.         $conversation $entityManager->getRepository(Conversation::class)->find(1);
  27.         foreach ($conversation->getMessages() as $val) {
  28.             if (empty($val->getUser())) {
  29.                 $entityManager->remove($val);
  30.                 $entityManager->flush();
  31.             }
  32.         }
  33.         if (empty($conversation)) {
  34.             $conversation = new Conversation();
  35.             $entityManager->persist($conversation);
  36.             $entityManager->flush();
  37.         }
  38.         $society count($entityManager->getRepository(SocietyList::class)->findByCreator($this->getUser()));
  39.         $recherches count($entityManager->getRepository(Recherche::class)->findByUser($this->getUser()));
  40.         $allRecherches $entityManager->getRepository(Recherche::class)->findAll();
  41.         $users $entityManager->getRepository(User::class)->findAll();
  42.         $data = [];
  43.         $labels = [];
  44.         foreach ($users as $user) {
  45.             $labels[$user->getId()] = $user->getFirstname();
  46.             foreach ($allRecherches as $val) {
  47.                 if ($val->getUser() == $user) {
  48.                     key_exists($user->getId(), $data) ? $data[$user->getId()] += $data[$user->getId()] = 1;
  49.                 }
  50.             }
  51.         }
  52.         $actions $entityManager->getRepository(Action::class)->findByCreator($this->getUser());
  53.         foreach ($actions as $k => $val) {
  54.             $date date('Y') . date('m') . date('d');
  55.             $date1 explode('-'$val->getEnd());
  56.             $date1 $date1[2] . $date1[1] . $date1[0];
  57.             if ($date1 $date) {
  58.                 unset($actions[$k]);
  59.             }
  60.         }
  61.         $actions count($actions);
  62.         return $this->render('default/index.html.twig', [
  63.             'conversation' => $conversation,
  64.             'society' => $society,
  65.             'recherches' => $recherches,
  66.             'actions' => $actions,
  67.             'controller_name' => 'DefaultController',
  68.             'labels' => $labels,
  69.             'data' => $data,
  70.         ]);
  71.     }
  72.     /**
  73.      * @Route("/prospecter", name="prospecter")
  74.      */
  75.     public function prospecter(Request $requestSiren $sirenSecteurRepository $secteurRepositoryEntityManagerInterface $entityManager): Response
  76.     {
  77.         $secteurs $secteurRepository->findAll();
  78.         $index = [
  79.             "Agriculture / Peche" => [123],
  80.             "Energie / Environnement" => [567893536373839],
  81.             "Industrie Agro-alimentaire" => [1011],
  82.             "Industrie" => [12131415161718192021222324252627282930313233],
  83.             "Construction / BTP" => [414243],
  84.             "Commerce Automobile" => [45],
  85.             "Commerce de gros" => [46],
  86.             "Commerce de détail" => [479596],
  87.             "Transport" => [4948495051],
  88.             "Hôtel / Restauration" => [5556],
  89.             "Edition et Logiciels" => [58],
  90.             "Audiovisuel" => [5960],
  91.             "Telecom" => [61],
  92.             "Conseil informatique" => [62],
  93.             "Info / web / Pub" => [6373],
  94.             "Finance / Assurance" => [646566],
  95.             "Immobilier / SCI" => [68],
  96.             "Juridique / Compta" => [69],
  97.             "Conseil de gestion" => [70],
  98.             "Ingénierie / R&D" => [7172],
  99.             "Autre activité technique" => [74],
  100.             "Santé / Social" => [75868788],
  101.             "Location / Bail" => [77],
  102.             "RH / Formation" => [7885],
  103.             "Voyage / Sécurité" => [7980],
  104.             "Bâtiment / Nettoyage" => [81],
  105.             "Services entreprises" => [82],
  106.             "Autres" => [8494979899],
  107.             "Arts / Spectacles" => [90919293],
  108.         ];
  109.         //  dd($siren,$request);
  110.         return $this->render('prospecter/prospecter.html.twig', [
  111.             'secteurs' => $secteurs,
  112.             'categories' => $index,
  113.         ]);
  114.     }
  115.     /**
  116.      * @Route("/prospecter/filter", name="prospecter_filter")
  117.      */
  118.     public function prospecterFilter(Request $requestSiren $sirenSecteurRepository $secteurRepository): Response
  119.     {
  120.         $data json_decode($request->getContent(), true);
  121.         $q "periode(etatAdministratifEtablissement:A) AND etatAdministratifUniteLegale:A ";
  122.         //   $q ="";
  123.         $category "";
  124.         $effectif "";
  125.         $localisation "";
  126.         $i 0;
  127.         if (!empty($data['naf'])) {
  128.             foreach ($data['naf'] as $val) {
  129.                 $i $q .= " OR " $q .= " AND ";
  130.                 $q .= "activitePrincipaleUniteLegale:" $val;
  131.                 $i++;
  132.             }
  133.         }
  134.         if (!empty($data['category'])) {
  135.             $category " AND categorieEntreprise:" $data['category'];
  136.         }
  137.         if (!empty($data['effectif'])) {
  138.             foreach ($data['effectif'] as $key => $val) {
  139.                 $key == "0" ?
  140.                     $effectif .= " AND trancheEffectifsEtablissement:" $val
  141.                     :
  142.                     $effectif .= " OR trancheEffectifsEtablissement:" $val;
  143.             }
  144.         }
  145.         if (!empty($data['localisation'])) {
  146.             $localisation " AND codePostalEtablissement:" $data['localisation'] . "*";
  147.         }
  148.         $q .= $category $effectif;
  149.         $q .= $category $localisation;
  150.         //  dd($q,$data);
  151.         $data $siren->getSocietiesBy($q);
  152.         $recherche = new Recherche();
  153.         $date = new \DateTime('now');
  154.         $recherche->setCreatedAt($date);
  155.         $recherche->setUser($this->getUser());
  156.         $this->getDoctrine()->getManager()->persist($recherche);
  157.         $this->getDoctrine()->getManager()->flush();
  158.         //   dd($data);
  159.         $data === null $data = ["code" => "400"] : null;
  160.         $response = new Response(json_encode($data));
  161.         //  $response->headers->set('Access-Control-Allow-Origin: *');
  162.         // $response->headers->set("Access-Control-Allow-Headers: *");
  163.         return $response;
  164.     }
  165. }