src/Controller/BusinessContactsController.php line 33

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\BusinessContacts;
  4. use App\Form\BusinessContactsType;
  5. use App\Form\ImportType;
  6. use App\Repository\BusinessContactsRepository;
  7. use App\Repository\BusinessTypesRepository;
  8. use App\Services\ImportBusinessContactsService;
  9. use App\Services\CompanyDetailsService;
  10. use App\Services\CountBusinessContactsService;
  11. use App\Services\PhoneAnalyzer;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use JeroenDesloovere\VCard\VCard;
  14. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  15. use PhpOffice\PhpSpreadsheet\Writer\Csv;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  18. use Symfony\Component\HttpFoundation\File\Exception\FileException;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  22. use Symfony\Component\HttpFoundation\StreamedResponse;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\String\Slugger\SluggerInterface;
  25. /**
  26.  * @Route("/businesscontacts")
  27.  */
  28. class BusinessContactsController extends AbstractController
  29. {
  30.     /**
  31.      * @Route("/index", name="business_contacts_index", methods={"GET"})
  32.      */
  33.     public function index(BusinessContactsRepository $businessContactsRepositoryBusinessTypesRepository $businessTypesRepositoryCountBusinessContactsService $countBusinessContactsServicePhoneAnalyzer $phoneAnalyzer): Response
  34.     {
  35.         $business_contacts $businessContactsRepository->findAll();
  36. //        $business_contacts = $businessContactsRepository->findBy([
  37. //            'status' => 'Approved'
  38. //        ]);
  39.         foreach ($business_contacts as $business_contact) {
  40.         $business_contact->phoneAnalysis = [
  41.             'mobile' => $business_contact->getMobile() ? $phoneAnalyzer->analyze($business_contact->getMobile()) : null,
  42.             'landline' => $business_contact->getLandline() ? $phoneAnalyzer->analyze($business_contact->getLandline()) : null,
  43.         ];
  44.     }
  45.         if ($this->isGranted('ROLE_ADMIN')) {
  46.             $business_contacts $businessContactsRepository->findAll();
  47.         }
  48.         $business_types $businessTypesRepository->findBy([], ['ranking' => 'ASC']);
  49.         return $this->render('business_contacts/index.html.twig', [
  50.             'business_contacts' => $business_contacts,
  51.             'business_types' => $business_types,
  52.             'countBusinessContactsService' => $countBusinessContactsService,
  53.             'list_or_map' => 'list',
  54.             'admin_check' => 'No'
  55.         ]);
  56.     }
  57.     /**
  58.      * @Route("/index_admin_check", name="business_contacts_index_admin_check", methods={"GET"})
  59.      */
  60.     public function indexAdmin_Check(BusinessContactsRepository $businessContactsRepositoryBusinessTypesRepository $businessTypesRepositoryCountBusinessContactsService $countBusinessContactsService): Response
  61.     {
  62.         $business_contacts $businessContactsRepository->findAll();
  63.         $business_types $businessTypesRepository->findBy([], ['ranking' => 'ASC']);
  64.         return $this->render('business_contacts/index_admin_check.html.twig', [
  65.             'business_contacts' => $business_contacts,
  66.             'business_types' => $business_types,
  67.             'countBusinessContactsService' => $countBusinessContactsService,
  68.             'list_or_map' => 'list',
  69.             'admin_check' => 'Yes'
  70.         ]);
  71.     }
  72.     /**
  73.      * @Route("/map/{subset}", name="business_contacts_map", methods={"GET"})
  74.      */
  75.     public function map(Request $requeststring $subsetBusinessContactsRepository $businessContactsRepositoryBusinessTypesRepository $businessTypesRepositoryCountBusinessContactsService $countBusinessContacts): Response
  76.     {
  77.         if ($subset == 'All') {
  78.             $business_contacts $businessContactsRepository->findBy([
  79.                 'status' => 'Approved'
  80.             ]);
  81.         }
  82.         if ($subset != 'All') {
  83.             $business_type $businessTypesRepository->findOneBy(['businessType' => $subset]);
  84.             $business_contacts $businessContactsRepository->findBy([
  85.                 'status' => 'Approved',
  86.                 'businessType' => $business_type
  87.             ]);
  88.         }
  89.         $latitude_total 0;
  90.         $longitude_total 0;
  91.         $count 0;
  92.         $latitude_max = -100;
  93.         $latitude_min = +100;
  94.         $longitude_max = -100;
  95.         $longitude_min = +100;
  96.         foreach ($business_contacts as $business_contact) {
  97.             if ($business_contact->getLocationLatitude() != or $business_contact->getLocationLatitude() != null) {
  98.                 $count $count 1;
  99.                 $latitude_total $latitude_total $business_contact->getLocationLatitude();
  100.                 $longitude_total $longitude_total $business_contact->getLocationLongitude();
  101.                 if ($business_contact->getLocationLatitude() > $latitude_max) {
  102.                     $latitude_max $business_contact->getLocationLatitude();
  103.                 }
  104.                 if ($business_contact->getLocationLatitude() < $latitude_min) {
  105.                     $latitude_min $business_contact->getLocationLatitude();
  106.                 }
  107.                 if ($business_contact->getLocationLongitude() > $longitude_max) {
  108.                     $longitude_max $business_contact->getLocationLongitude();
  109.                 }
  110.                 if ($business_contact->getLocationLongitude() < $longitude_min) {
  111.                     $longitude_min $business_contact->getLocationLongitude();
  112.                 }
  113.             }
  114.         }
  115.         if ($count == 0) {
  116.             $latitude_average 'No data';
  117.             $longitude_average 'No data';
  118.         }
  119.         if ($count >= 1) {
  120.             $latitude_average $latitude_total $count;
  121.             $longitude_average $longitude_total $count;
  122.         }
  123.         if ($count 2) {
  124.             $latitude_range "TBD";
  125.             $longitude_range "TBD";
  126.         }
  127.         if ($count 1) {
  128.             $latitude_range $latitude_max $latitude_min;
  129.             $longitude_range $longitude_max $longitude_min;
  130.         }
  131.         $business_types $businessTypesRepository->findBy([], ['ranking' => 'ASC']);
  132.         return $this->render('business_contacts/map_of_business_contacts.html.twig', [
  133.             'business_contacts' => $business_contacts,
  134.             'business_types' => $business_types,
  135.             'subset' => $subset,
  136.             'latitude_max' => $latitude_max,
  137.             'latitude_min' => $latitude_min,
  138.             'latitude_average' => $latitude_average,
  139.             'latitude_range' => $latitude_range,
  140.             'longitude_max' => $longitude_max,
  141.             'longitude_min' => $longitude_min,
  142.             'longitude_average' => $longitude_average,
  143.             'longitude_range' => $longitude_range,
  144.             'count' => $count,
  145.             'list_or_map' => 'map',
  146.             'admin_check' => 'No'
  147.         ]);
  148.     }
  149.     /**
  150.      * @Route("/new/{business_type}", name="business_contacts_new", methods={"GET", "POST"})
  151.      */
  152.     public function new(Request $requeststring $business_typeBusinessContactsRepository $businessContactsRepositoryBusinessTypesRepository $businessTypesRepositoryCompanyDetailsService $companyDetailsEntityManagerInterface $entityManager): Response
  153.     {
  154.         $business_type $businessTypesRepository->find($business_type);
  155.         $default_country $companyDetails->getCompanyDetails()->getCompanyAddressCountry();
  156.         $businessContact = new BusinessContacts();
  157.         $businessContact->setBusinessType($business_type);
  158.         $businessContact->setAddressCountry($default_country);
  159.         $form $this->createForm(BusinessContactsType::class, $businessContact);
  160.         $form->handleRequest($request);
  161.         if ($form->isSubmitted() && $form->isValid()) {
  162.             $photo $form['photo']->getData();
  163.             if ($photo) {
  164.                 $uniqueId uniqid(); // Generates a unique ID
  165.                 $uniqueId3digits substr($uniqueId103); // Extracts the first 3 digits
  166.                 $files_name = [];
  167.                 $photo_directory $this->getParameter('business_contacts_photos_directory');
  168.                 $fileName pathinfo($photo->getClientOriginalName(), PATHINFO_FILENAME);
  169.                 $file_extension $photo->guessExtension();
  170.                 $newFileName $businessContact->getCompany() . "_" $uniqueId3digits "." $file_extension;
  171.                 $photo->move($photo_directory$newFileName);
  172.                 $businessContact->setPhoto($newFileName);
  173.             }
  174.             $file $form['files']->getData();
  175.             if ($file) {
  176.                 $file_name = [];
  177.                 $file_directory $this->getParameter('business_contacts_attachments_directory');
  178.                 $fileName pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  179.                 $file_extension $file->guessExtension();
  180.                 $newFileName $fileName "." $file_extension;
  181.                 $file->move($file_directory$newFileName);
  182.                 $businessContact->setFiles($newFileName);
  183.             }
  184.             $businessContactsRepository->add($businessContacttrue);
  185.             $firstName $businessContact->getFirstName();
  186.             $lastName $businessContact->getLastName();
  187.             $entityManager->persist($businessContact);
  188.             $entityManager->flush();
  189.             return $this->redirectToRoute('business_contacts_index', [], Response::HTTP_SEE_OTHER);
  190.         }
  191.         return $this->renderForm('business_contacts/new.html.twig', [
  192.             'business_contact' => $businessContact,
  193.             'form' => $form,
  194.         ]);
  195.     }
  196.     /**
  197.      * @Route("/suggestion", name="business_contacts_suggestion", methods={"GET", "POST"})
  198.      */
  199.     public function suggestion(Request $requestBusinessContactsRepository $businessContactsRepository): Response
  200.     {
  201.         $businessContact = new BusinessContacts();
  202.         $form $this->createForm(BusinessContactsType::class, $businessContact);
  203.         $form->handleRequest($request);
  204.         if ($form->isSubmitted() && $form->isValid()) {
  205.             $businessContactsRepository->add($businessContacttrue);
  206.             $businessContact->setStatus('Pending');
  207.             return $this->redirectToRoute('business_contacts_index', [], Response::HTTP_SEE_OTHER);
  208.         }
  209.         return $this->renderForm('business_contacts/new.html.twig', [
  210.             'business_contact' => $businessContact,
  211.             'form' => $form,
  212.         ]);
  213.     }
  214.     /**
  215.      * @Route("/show/{id}", name="business_contacts_show", methods={"GET"})
  216.      */
  217.     public function show(BusinessContacts $businessContact): Response
  218.     {
  219.         return $this->render('business_contacts/show.html.twig', [
  220.             'business_contact' => $businessContact,
  221.         ]);
  222.     }
  223.     /**
  224.      * @Route("/edit/{id}", name="business_contacts_edit", methods={"GET", "POST"})
  225.      */
  226.     public function edit(Request $requestBusinessContacts $businessContactBusinessContactsRepository $businessContactsRepository): Response
  227.     {
  228.         $form $this->createForm(BusinessContactsType::class, $businessContact);
  229.         $form->handleRequest($request);
  230.         if ($form->isSubmitted() && $form->isValid()) {
  231.             $photo $form['photo']->getData();
  232.             if ($photo) {
  233.                 $files_name = [];
  234.                 $photo_directory $this->getParameter('business_contacts_photos_directory');
  235.                 $fileName pathinfo($photo->getClientOriginalName(), PATHINFO_FILENAME);
  236.                 $file_extension $photo->guessExtension();
  237.                 if ($businessContact->getFirstName() == '') {
  238.                     $newFileName $businessContact->getCompany() . "." $file_extension;
  239.                 } else {
  240.                     $newFileName $businessContact->getCompany() . "_" $businessContact->getFirstName() . "_" $businessContact->getLastName() . "." $file_extension;
  241.                 }
  242.                 $photo->move($photo_directory$newFileName);
  243.                 $businessContact->setPhoto($newFileName);
  244.             }
  245.             $file $form['files']->getData();
  246.             if ($file) {
  247.                 $file_name = [];
  248.                 $file_directory $this->getParameter('business_contacts_attachments_directory');
  249.                 $fileName pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
  250.                 $file_extension $file->guessExtension();
  251.                 $newFileName $fileName "." $file_extension;
  252.                 $file->move($file_directory$newFileName);
  253.                 $businessContact->setFiles($newFileName);
  254.             }
  255.             $businessContactsRepository->add($businessContacttrue);
  256.             return $this->redirectToRoute('business_contacts_index', [], Response::HTTP_SEE_OTHER);
  257.         }
  258.         return $this->renderForm('business_contacts/edit.html.twig', [
  259.             'business_contact' => $businessContact,
  260.             'form' => $form,
  261.         ]);
  262.     }
  263.     /**
  264.      * @Route("/delete/{id}", name="business_contacts_delete", methods={"POST"})
  265.      */
  266.     public function delete(Request $requestBusinessContacts $businessContactBusinessContactsRepository $businessContactsRepositoryEntityManagerInterface $entityManager): Response
  267.     {
  268.         $referer $request->headers->get('referer');
  269.         $file_name $businessContact->getFiles();
  270.         if ($file_name) {
  271.             $file $this->getParameter('business_contacts_attachments_directory') . $file_name;
  272.             if (file_exists($file)) {
  273.                 unlink($file);
  274.             }
  275.             $businessContact->setFiles('');
  276.             $entityManager->flush();
  277.         }
  278.         $photo_file_name $businessContact->getPhoto();
  279.         if ($photo_file_name) {
  280.             $photo_file_name $this->getParameter('business_contacts_photos_directory') . $photo_file_name;
  281.             if (file_exists($photo_file_name)) {
  282.                 unlink($photo_file_name);
  283.             }
  284.             $businessContact->setPhoto('');
  285.             $entityManager->flush();
  286.         }
  287.         if ($this->isCsrfTokenValid('delete' $businessContact->getId(), $request->request->get('_token'))) {
  288.             $businessContactsRepository->remove($businessContacttrue);
  289.         }
  290.         return $this->redirect($referer);
  291.     }
  292.     /**
  293.      * @Route("/delete_all", name="business_contacts_delete_all")
  294.      */
  295.     public function deleteAllBusinessContacts(BusinessContactsRepository $businessContactsRepositoryEntityManagerInterface $entityManager): Response
  296.     {
  297.         $business_contacts $businessContactsRepository->findAll();
  298.         foreach ($business_contacts as $business_contact) {
  299.             $entityManager->remove($business_contact);
  300.             $entityManager->flush();
  301.         }
  302.         return $this->redirectToRoute('business_contacts_index', [], Response::HTTP_SEE_OTHER);
  303.     }
  304.     /**
  305.      * @Route("/delete_photo_file/{id}", name="business_contact_delete_photo_file", methods={"POST", "GET"})
  306.      */
  307.     public function deleteBusinessContactPhotoFile(int $idRequest $requestBusinessContacts $businessContactEntityManagerInterface $entityManager)
  308.     {
  309.         $referer $request->headers->get('referer');
  310.         $photo_file_name $businessContact->getPhoto();
  311.         if ($photo_file_name) {
  312.             $photo_file_name $this->getParameter('business_contacts_photos_directory') . "/" $photo_file_name;
  313.             if (file_exists($photo_file_name)) {
  314.                 unlink($photo_file_name);
  315.             }
  316.             $businessContact->setPhoto('');
  317.             $entityManager->flush();
  318.         }
  319.         return $this->redirect($referer);
  320.     }
  321.     /**
  322.      * @Route("/delete_attachment_file/{id}", name="business_contact_delete_attachment_file", methods={"POST", "GET"})
  323.      */
  324.     public function deleteBusinessContactAttachmentFile(int $idRequest $requestBusinessContacts $businessContactEntityManagerInterface $entityManager)
  325.     {
  326.         $referer $request->headers->get('referer');
  327.         $file_name $businessContact->getFiles();
  328.         if ($file_name) {
  329.             $file $this->getParameter('business_contacts_attachments_directory') . "/" $file_name;
  330.             if (file_exists($file)) {
  331.                 unlink($file);
  332.             }
  333.             $businessContact->setFiles('');
  334.             $entityManager->flush();
  335.         }
  336.         return $this->redirect($referer);
  337.     }
  338.     /**
  339.      * @Route ("/view/photo/{id}", name="view_business_contact_photo")
  340.      */
  341.     public function viewBusinessContactPhoto(Request $request$idBusinessContactsRepository $businessContactsRepository)
  342.     {
  343.         $business_contact $businessContactsRepository->find($id);
  344.         return $this->render('business_contacts/view_photo.html.twig', ['business_contact' => $business_contact]);
  345.     }
  346.     /**
  347.      * @Route ("/export/business_contacts", name="business_contacts_export" )
  348.      */
  349.     public function businessContactsExport(BusinessContactsRepository $businessContactsRepository)
  350.     {
  351.         $data = [];
  352.         $exported_date = new \DateTime('now');
  353.         $exported_date_formatted $exported_date->format('d-M-Y');
  354.         $fileName 'business_contacts_export_' $exported_date_formatted '.csv';
  355.         $count 0;
  356.         $business_contact_list $businessContactsRepository->findAll();
  357.         foreach ($business_contact_list as $business_contact) {
  358.             $concatenatedNotes "Exported on: " $exported_date_formatted;
  359.             $data[] = [
  360.                 "BusinessContacts",
  361.                 $business_contact->getStatus(),
  362.                 $business_contact->getBusinessOrPerson(),
  363.                 $business_contact->getBusinessType()->getBusinessType(),
  364.                 $business_contact->getCompany(),
  365.                 $business_contact->getFirstName(),
  366.                 $business_contact->getLastName(),
  367.                 $business_contact->getWebsite(),
  368.                 $business_contact->getEmail(),
  369.                 $business_contact->getLandline(),
  370.                 $business_contact->getMobile(),
  371.                 $business_contact->getAddressStreet(),
  372.                 $business_contact->getAddressCity(),
  373.                 $business_contact->getAddressCounty(),
  374.                 $business_contact->getAddressPostCode(),
  375.                 $business_contact->getAddressCountry(),
  376.                 $business_contact->getLocationLongitude(),
  377.                 $business_contact->getLocationLatitude(),
  378.                 $business_contact->getNotes()
  379.             ];
  380.         }
  381.         $spreadsheet = new Spreadsheet();
  382.         $sheet $spreadsheet->getActiveSheet();
  383.         $sheet->setTitle('Business Contacts');
  384.         $sheet->getCell('A1')->setValue('Entity');
  385.         $sheet->getCell('B1')->setValue('Status');
  386.         $sheet->getCell('C1')->setValue('Business Or Person');
  387.         $sheet->getCell('D1')->setValue('Business Type');
  388.         $sheet->getCell('E1')->setValue('Company');
  389.         $sheet->getCell('F1')->setValue('First Name');
  390.         $sheet->getCell('G1')->setValue('Last Name');
  391.         $sheet->getCell('H1')->setValue('Web Page');
  392.         $sheet->getCell('I1')->setValue('E-mail');
  393.         $sheet->getCell('J1')->setValue('Business Phone');
  394.         $sheet->getCell('K1')->setValue('Mobile Phone');
  395.         $sheet->getCell('L1')->setValue('Business Street');
  396.         $sheet->getCell('M1')->setValue('Business City');
  397.         $sheet->getCell('N1')->setValue('Business County');
  398.         $sheet->getCell('O1')->setValue('Business Postal Code');
  399.         $sheet->getCell('P1')->setValue('Business Country/Region');
  400.         $sheet->getCell('Q1')->setValue('Location Longitude');
  401.         $sheet->getCell('R1')->setValue('Location Latitude');
  402.         $sheet->fromArray($datanull'A2'true);
  403.         $total_rows $sheet->getHighestRow();
  404.         for ($i 2$i <= $total_rows$i++) {
  405.             $cell "L" $i;
  406.             $sheet->getCell($cell)->getHyperlink()->setUrl("https://google.com");
  407.         }
  408.         $writer = new Csv($spreadsheet);
  409.         $response = new StreamedResponse(function () use ($writer) {
  410.             $writer->save('php://output');
  411.         });
  412.         $response->headers->set('Content-Type''application/vnd.ms-excel');
  413.         $response->headers->set('Content-Disposition'sprintf('attachment;filename="%s"'$fileName));
  414.         $response->headers->set('Cache-Control''max-age=0');
  415.         return $response;
  416.     }
  417.     /**
  418.      * @Route ("/export/business_contacts_outlook", name="business_contacts_export_for_outlook" )
  419.      */
  420.     public function businessContactsExportForOutlook(BusinessContactsRepository $businessContactsRepository)
  421.     {
  422.         $data = [];
  423.         $exported_date = new \DateTime('now');
  424.         $exported_date_formatted $exported_date->format('d-M-Y');
  425.         $fileName 'business_contacts_export_for_outlook_' $exported_date_formatted '.csv';
  426.         $count 0;
  427.         $business_contact_list $businessContactsRepository->findAll();
  428.         foreach ($business_contact_list as $business_contact) {
  429.             $concatenatedNotes "Exported on: " $exported_date_formatted;
  430.             $data[] = [
  431.                 $business_contact->getStatus(),
  432.                 $business_contact->getBusinessOrPerson(),
  433.                 $business_contact->getBusinessType()->getBusinessType(),
  434.                 $business_contact->getCompany(),
  435.                 $business_contact->getFirstName(),
  436.                 $business_contact->getLastName(),
  437.                 $business_contact->getWebsite(),
  438.                 $business_contact->getEmail(),
  439.                 $business_contact->getLandline(),
  440.                 $business_contact->getMobile(),
  441.                 $business_contact->getAddressStreet(),
  442.                 $business_contact->getAddressCity(),
  443.                 $business_contact->getAddressCounty(),
  444.                 $business_contact->getAddressPostCode(),
  445.                 $business_contact->getAddressCountry(),
  446.                 $business_contact->getLocationLongitude(),
  447.                 $business_contact->getLocationLatitude(),
  448.                 $concatenatedNotes,
  449.                 $business_contact->getId()
  450.             ];
  451.         }
  452.         $spreadsheet = new Spreadsheet();
  453.         $sheet $spreadsheet->getActiveSheet();
  454.         $sheet->setTitle('Business Contacts');
  455.         $sheet->getCell('A1')->setValue('Status');
  456.         $sheet->getCell('B1')->setValue('Business Or Person');
  457.         $sheet->getCell('C1')->setValue('Business Type');
  458.         $sheet->getCell('D1')->setValue('Company');
  459.         $sheet->getCell('E1')->setValue('First Name');
  460.         $sheet->getCell('F1')->setValue('Last Name');
  461.         $sheet->getCell('G1')->setValue('Web Page');
  462.         $sheet->getCell('H1')->setValue('E-mail');
  463.         $sheet->getCell('I1')->setValue('Business Phone');
  464.         $sheet->getCell('J1')->setValue('Mobile Phone');
  465.         $sheet->getCell('K1')->setValue('Business Street');
  466.         $sheet->getCell('L1')->setValue('Business City');
  467.         $sheet->getCell('M1')->setValue('Business County');
  468.         $sheet->getCell('N1')->setValue('Business Postal Code');
  469.         $sheet->getCell('O1')->setValue('Business Country/Region');
  470.         $sheet->getCell('P1')->setValue('Location Longitude');
  471.         $sheet->getCell('Q1')->setValue('Location Latitude');
  472.         $sheet->getCell('R1')->setValue('Notes');
  473.         $sheet->getCell('S1')->setValue('Id');
  474.         $sheet->fromArray($datanull'A2'true);
  475.         $total_rows $sheet->getHighestRow();
  476.         for ($i 2$i <= $total_rows$i++) {
  477.             $cell "L" $i;
  478.             $sheet->getCell($cell)->getHyperlink()->setUrl("https://google.com");
  479.         }
  480.         $writer = new Csv($spreadsheet);
  481.         $response = new StreamedResponse(function () use ($writer) {
  482.             $writer->save('php://output');
  483.         });
  484.         $response->headers->set('Content-Type''application/vnd.ms-excel');
  485.         $response->headers->set('Content-Disposition'sprintf('attachment;filename="%s"'$fileName));
  486.         $response->headers->set('Cache-Control''max-age=0');
  487.         return $response;
  488.     }
  489.     /**
  490.      * @Route ("/import", name="business_contacts_import" )
  491.      */
  492.     public function businessContactsImport(Request $requestSluggerInterface $sluggerBusinessContactsRepository $businessContactsRepositoryImportBusinessContactsService $businessContactsImportService): Response
  493.     {
  494.         $form $this->createForm(ImportType::class);
  495.         $form->handleRequest($request);
  496.         if ($form->isSubmitted() && $form->isValid()) {
  497.             $importFile $form->get('File')->getData();
  498.             if ($importFile) {
  499.                 $originalFilename pathinfo($importFile->getClientOriginalName(), PATHINFO_FILENAME);
  500.                 $safeFilename $slugger->slug($originalFilename);
  501.                 $newFilename $safeFilename '.' 'csv';
  502.                 try {
  503.                     $importFile->move(
  504.                         $this->getParameter('business_contacts_import_directory'),
  505.                         $newFilename
  506.                     );
  507.                 } catch (FileException $e) {
  508.                     die('Import failed');
  509.                 }
  510.                 $businessContactsImportService->importBusinessContacts($newFilename);
  511.                 return $this->redirectToRoute('business_contacts_index');
  512.             }
  513.         }
  514.         return $this->render('home/import.html.twig', [
  515.             'form' => $form->createView(),
  516.             'heading' => 'Business Contacts Import',
  517.         ]);
  518.     }
  519.     /**
  520.      * @Route("/create/Vcard/{id}", name="create_vcard")
  521.      */
  522.     public function createVcard(int $idBusinessContactsRepository $businessContactsRepository)
  523.     {
  524.         $business_contact $businessContactsRepository->find($id);
  525.         $vcard = new VCard();
  526.         $businessOrPerson $business_contact->getBusinessOrPerson();
  527.         $business_type $business_contact->getBusinessType()->getBusinessType();
  528.         $firstName $business_contact->getFirstName();
  529.         $lastName $business_contact->getLastName();
  530.         $mobile $business_contact->getMobile();
  531.         $landline $business_contact->getLandline();
  532.         $company $business_contact->getCompany();
  533.         $website $business_contact->getWebsite();
  534.         $addressStreet $business_contact->getAddressStreet();
  535.         $addressCity $business_contact->getAddressCity();
  536.         $addressPostCode $business_contact->getAddressPostcode();
  537.         $addressCountry $business_contact->getAddressCountry();
  538.         $longitude $business_contact->getLocationLongitude();
  539.         $latitude $business_contact->getLocationLatitude();
  540.         $notes $business_contact->getNotes();
  541.         if ($businessOrPerson "Business") {
  542.             $firstNameCard $company;
  543.             $lastNameCard $business_type;
  544.             $companyCard = [];
  545.         }
  546.         if ($businessOrPerson "Person") {
  547.             $firstNameCard $firstName;
  548.             $lastNameCard $lastName;
  549.             $companyCard $company;
  550.         }
  551.         $vcard->addName($lastNameCard$firstNameCard);
  552.         $vcard->addEmail($business_contact->getEmail())
  553.             ->addPhoneNumber($landline'work')
  554.             ->addPhoneNumber($mobile'mobile')
  555.             ->addCompany($companyCard)
  556.             ->addURL($website)
  557.             ->addNote($notes)
  558.             ->addAddress($name ''$extended ''$street $addressStreet$city $addressCity$region ''$zip $addressPostCode$country $addressCountry$type 'WORK;POSTAL');
  559.         $vcard->download();
  560.         return new Response(null);
  561.     }
  562.     /**
  563.      * @Route("/gps/GoogleMap/show/{id}", name="show_location_google_maps", methods={"GET"})
  564.      */
  565.     public function showMap(int $idBusinessContactsRepository $businessContactsRepository): Response
  566.     {
  567.         $business_contact $businessContactsRepository->find($id);
  568.         $longitude $business_contact->getLocationLongitude();
  569.         $latitude $business_contact->getLocationLatitude();
  570.         return $this->render('business_contacts/gpsGoogleMaps.html.twig', [
  571.             'latitude' => $latitude,
  572.             'longitude' => $longitude,
  573.             'business_contact' => $business_contact,
  574.             'admin_check' => 'No'
  575.         ]);
  576.     }
  577.     /**
  578.      * @Route("/update/location", name="update_business_contact_location", methods={"POST"})
  579.      */
  580.     public function updateLocation(BusinessContactsRepository $businessContactsRepositoryEntityManagerInterface $manager): Response
  581.     {
  582.         $id $_POST['id'];
  583.         $latitude $_POST['latitude'];
  584.         $longitude $_POST['longitude'];
  585.         $gps $latitude ',' $longitude;
  586.         $business_contact $businessContactsRepository->find($id);
  587.         $business_contact->setLocationLongitude($longitude)
  588.             ->setLocationLatitude($latitude);
  589.         $manager->flush();
  590.         return new Response(null);
  591.     }
  592.     /**
  593.      * @Route("/gps_location_clear/{id}", name="business_contact_clear_gps_location")
  594.      */
  595.     public
  596.     function clearGPSLocation(Request $requestBusinessContacts $businessContactsEntityManagerInterface $entityManager)
  597.     {
  598.         $referer $request->headers->get('referer');
  599.         $businessContacts->setLocationLongitude(null);
  600.         $businessContacts->setLocationLatitude(null);
  601.         $entityManager->flush();
  602.         return $this->redirect($referer);
  603.     }
  604.     /**
  605.      * @Route("/show_attachment/{id}", name="business_contact_show_attachment")
  606.      */
  607.     public function showAttachmentBusinessContact(int $idBusinessContactsRepository $businessContactsRepository)
  608.     {
  609.         $business_contact $businessContactsRepository->find($id);
  610.         $filename $business_contact->getFiles();
  611.         $filepath $this->getParameter('business_contacts_attachments_directory') . "/" $filename;
  612.         if (file_exists($filepath)) {
  613.             $response = new BinaryFileResponse($filepath);
  614.             $response->setContentDisposition(
  615.                 ResponseHeaderBag::DISPOSITION_INLINE//use ResponseHeaderBag::DISPOSITION_ATTACHMENT to save as an attachment
  616.                 $filename
  617.             );
  618.             return $response;
  619.         } else {
  620.             return new Response("file does not exist");
  621.         }
  622.     }
  623. }