src/Controller/FrontEndController.php line 231

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use App\Entity\Category;
  8. use App\Entity\Product;
  9. use App\Entity\WebsiteCustomizations;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  12. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  13. use Doctrine\DBAL\Connection;
  14. use App\Entity\Pages;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use App\Form\ContactType;
  17. use App\Entity\Contact;
  18. use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;
  19. class FrontEndController extends AbstractController
  20. {
  21.     private $encryptor;
  22.     public function __construct(Encryptor $encryptor)
  23.     {
  24.         $this->encryptor $encryptor;
  25.     }
  26.     
  27.     #[Route('/'name'app_home')]
  28.     public function index(ManagerRegistry $doctrine): Response
  29.     {
  30.         $user $this->getUser();
  31.         //Categories List
  32.         $cat_list $doctrine->getRepository(Category::class);
  33.         $allCat $cat_list->findBy(
  34.             ['is_active' => 1]
  35.         );
  36.         $entityManager $doctrine->getManager();
  37.         //Website Settings List
  38.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  39.         $web_settings $WebsiteCustomizations->findAll();
  40.          //Softwares list
  41.          $soft_list $doctrine->getRepository(Product::class);
  42.          $allCatSoft $soft_list->findBy(
  43.              ['id' => 'ASC']
  44.          );
  45.          $conn $entityManager->getConnection(); 
  46.          $sql '
  47.          SELECT * FROM product 
  48.          ORDER BY id DESC LIMIT 5
  49.          ';
  50.         $stmt $conn->prepare($sql);
  51.         $resultSet $stmt->executeQuery();
  52.         $allCatSoft $resultSet->fetchAllAssociative();
  53.         // dd($allCatSoft);
  54.         //Homepage Content
  55.           $page $doctrine->getRepository(Pages::class);
  56.           $page_content $page->findOneBy(
  57.               ['id'=> 3]
  58.           );
  59.           //Menus
  60.           $page_menus $doctrine->getRepository(Pages::class);
  61.           $menus $page_menus->findBy(
  62.               ['is_active'=> 1]
  63.           );
  64.           if(count($menus) < 1){
  65.             $menus = array();
  66.           }
  67.         return $this->render('front_end/index.html.twig', [
  68.             'allCat' => $allCat,
  69.             'web_settings'=> $web_settings,
  70.             'allCatSoft'=>$allCatSoft,
  71.             'page_content'=>$page_content,
  72.             'menus'=>$menus,
  73.             'user'=>$user
  74.         ]);
  75.     }
  76.     #[Route('/downloadlist/{id}',name'file_download')]
  77.     public function showPost(string $idManagerRegistry $doctrine): Response
  78.     {
  79.         $user $this->getUser();
  80.         $id $this->encryptor->decrypt($id);
  81.         //Categories List
  82.         $cat_list $doctrine->getRepository(Category::class);
  83.         $allCat $cat_list->findBy(
  84.             ['is_active' => 1]
  85.         );
  86.         //Softwares list
  87.         $soft_list $doctrine->getRepository(Product::class);
  88.         $allCatSoft $soft_list->findBy(
  89.             ['category' => $id]
  90.         );
  91.         //Website Settings List
  92.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  93.         $web_settings $WebsiteCustomizations->findAll();
  94.         
  95.           //Menus
  96.           $page_menus $doctrine->getRepository(Pages::class);
  97.           $menus $page_menus->findBy(
  98.               ['is_active'=> 1]
  99.           );
  100.           if(count($menus) < 1){
  101.             $menus = array();
  102.           }
  103.         return $this->render('front_end/viewfiles.html.twig', [
  104.             'allCat' => $allCat,
  105.             'web_settings'=> $web_settings,
  106.             'allCatSoft'=> $allCatSoft,
  107.             'menus'=>$menus,
  108.             'user'=>$user
  109.         ]);
  110.     }
  111.     #[Route('/download/{id}',name'download_file')]
  112.     public function downloadFileAction(string $idManagerRegistry $doctrine): Response
  113.     {
  114.         $user $this->getUser();
  115.         $id $this->encryptor->decrypt($id);
  116.         //Softwares list
  117.         $soft_list $doctrine->getRepository(Product::class);
  118.         $allCatSoft $soft_list->find(
  119.             ['id' => $id]
  120.         );
  121.         $response = new BinaryFileResponse('uploads/files/'.$allCatSoft->getFileToDownload());
  122.        // $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,'pdf.pdf');
  123.         return $response;
  124.     }
  125.     #[Route('/account'name'email_verify')]
  126.     public function accountVerify(ManagerRegistry $doctrine): Response
  127.     {
  128.         $user $this->getUser();
  129.           //Categories List
  130.           $cat_list $doctrine->getRepository(Category::class);
  131.           $allCat $cat_list->findBy(
  132.               ['is_active' => 1]
  133.           );
  134.   
  135.           //Website Settings List
  136.           $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  137.           $web_settings $WebsiteCustomizations->findAll();
  138.           
  139.           //Menus
  140.           $page_menus $doctrine->getRepository(Pages::class);
  141.           $menus $page_menus->findBy(
  142.               ['is_active'=> 1]
  143.           );
  144.           if(count($menus) < 1){
  145.             $menus = array();
  146.           }
  147.         $user $this->getUser();
  148.         return $this->render('front_end/accountverify.html.twig', [
  149.             'allCat' => $allCat,
  150.             'web_settings'=> $web_settings,
  151.             'menus'=>$menus,
  152.             'user'=>$user
  153.         ]);
  154.     }
  155.     #[Route('/search'name'search_result')]
  156.     public function search(Connection $connectionManagerRegistry $doctrine): Response
  157.     {
  158.         $user $this->getUser();
  159.         //Categories List
  160.          $cat_list $doctrine->getRepository(Category::class);
  161.          $allCat $cat_list->findBy(
  162.              ['is_active' => 1]
  163.          );
  164.         //Website Settings List
  165.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  166.         $web_settings $WebsiteCustomizations->findAll();
  167.         $searChSoft "%".$_POST['q']."%";
  168.         $allCatSoft $connection->fetchAllAssociative("SELECT * FROM product where name like '".$searChSoft."' ");
  169.         
  170.           //Menus
  171.           $page_menus $doctrine->getRepository(Pages::class);
  172.           $menus $page_menus->findBy(
  173.               ['is_active'=> 1]
  174.           );
  175.           if(count($menus) < 1){
  176.             $menus = array();
  177.           }
  178.         
  179.         return $this->render('front_end/search.html.twig', [
  180.             'allCat' => $allCat,
  181.             'web_settings'=> $web_settings,
  182.             'allCatSoft'=>$allCatSoft,
  183.             'query'=>$_POST['q'],
  184.             'menus'=>$menus,
  185.             'user'=>$user
  186.         ]);
  187.     }
  188.     #[Route('/page/{id}',name'view_page')]
  189.     public function ViewPage(string $idManagerRegistry $doctrineRequest $request): Response
  190.     {   
  191.         $user $this->getUser();
  192.         $id $this->encryptor->decrypt($id);
  193.         //Categories List
  194.         $cat_list $doctrine->getRepository(Category::class);
  195.         $allCat $cat_list->findBy(
  196.             ['is_active' => 1]
  197.         );
  198.         //Website Settings List
  199.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  200.         $web_settings $WebsiteCustomizations->findAll();
  201.          //Softwares list
  202.          $soft_list $doctrine->getRepository(Product::class);
  203.          $allCatSoft $soft_list->findAll(
  204.              ['id' => 'DESC']
  205.          );
  206.           //Homepage Content
  207.           $page $doctrine->getRepository(Pages::class);
  208.           $page_content $page->findOneBy(
  209.               ['id'=> $id]
  210.           );
  211.           
  212.           //Menus
  213.           $page_menus $doctrine->getRepository(Pages::class);
  214.           $menus $page_menus->findBy(
  215.               ['is_active'=> 1]
  216.           );
  217.           if(count($menus) < 1){
  218.             $menus = array();
  219.           }
  220.           $contact = new Contact();
  221.           $user $this->getUser();
  222.   
  223.           $form $this->createForm(ContactType::class, $contact);  
  224.           $form->handleRequest($request);
  225.         if ($form->isSubmitted() && $form->isValid()) {
  226.             $entityManager $doctrine->getManager();
  227.             $entityManager->persist($contact);
  228.             $entityManager->flush();
  229.             $this->addFlash(
  230.                 'notice',
  231.                 'Message Sent Successfully.'
  232.             );
  233.             return $this->redirect($request->request->get('referer'));
  234.         }
  235.         return $this->render('front_end/page.html.twig', [
  236.             'allCat' => $allCat,
  237.             'web_settings'=> $web_settings,
  238.             'allCatSoft'=>$allCatSoft,
  239.             'page_content'=>$page_content,
  240.             'menus'=>$menus,
  241.             'user'=>$user,
  242.             'form'=>$form->createView(),
  243.         ]);
  244.     }
  245.     #[Route('/package',name'view_package')]
  246.     public function ViewPackageManagerRegistry $doctrine): Response
  247.     {   
  248.         $user $this->getUser();
  249.         //Categories List
  250.         $cat_list $doctrine->getRepository(Category::class);
  251.         $allCat $cat_list->findBy(
  252.             ['is_active' => 1]
  253.         );
  254.         //Website Settings List
  255.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  256.         $web_settings $WebsiteCustomizations->findAll();
  257.          //Softwares list
  258.          $soft_list $doctrine->getRepository(Product::class);
  259.          $allCatSoft $soft_list->findAll(
  260.              ['id' => 'DESC']
  261.          );
  262.          
  263.           //Menus
  264.           $page_menus $doctrine->getRepository(Pages::class);
  265.           $menus $page_menus->findBy(
  266.               ['is_active'=> 1]
  267.           );
  268.           if(count($menus) < 1){
  269.             $menus = array();
  270.           }
  271.         if(empty($user)){
  272.             $this->addFlash('loginError''To Subscribe You must register or login and complete payments to download.');
  273.             return $this->render('login/index.html.twig', [
  274.                 'error'         => "",
  275.                 'allCat' => $allCat,
  276.                 'web_settings'=> $web_settings,
  277.                 'allCatSoft'=>$allCatSoft,
  278.                 'menus'=>$menus,
  279.                 'last_username' => '',
  280.                 'redirect'=>'/package',
  281.             ]);
  282.         }else{  
  283.             return $this->render('front_end/subscribe.html.twig', [
  284.                 'allCat' => $allCat,
  285.                 'web_settings'=> $web_settings,
  286.                 'allCatSoft'=>$allCatSoft,
  287.                 'menus'=>$menus,
  288.                 'user'=>$user,
  289.                 'stripe_key' => $_ENV["STRIPE_KEY"]
  290.             ]);
  291.         }
  292.     }
  293.     
  294.     #[Route('/detail/{id}',name'detail')]
  295.     public function SoftwareDetails(string $idManagerRegistry $doctrine): Response
  296.     {   
  297.         $user $this->getUser();
  298.         $id $this->encryptor->decrypt($id);
  299.         //Categories List
  300.         $cat_list $doctrine->getRepository(Category::class);
  301.         $allCat $cat_list->findBy(
  302.             ['is_active' => 1]
  303.         );
  304.         //Website Settings List
  305.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  306.         $web_settings $WebsiteCustomizations->findAll();
  307.          //Softwares list
  308.          $soft_list $doctrine->getRepository(Product::class);
  309.          $allCatSoft $soft_list->findOneBy(
  310.             ['id'=> $id ]
  311.          );
  312.           
  313.           //Menus
  314.           $page_menus $doctrine->getRepository(Pages::class);
  315.           $menus $page_menus->findBy(
  316.               ['is_active'=> 1]
  317.           );
  318.           if(count($menus) < 1){
  319.             $menus = array();
  320.           }
  321.         return $this->render('front_end/detail.html.twig', [
  322.             'allCat' => $allCat,
  323.             'web_settings'=> $web_settings,
  324.             'allCatSoft'=>$allCatSoft,
  325.             'menus'=>$menus,
  326.             'user'=>$user
  327.         ]);
  328.     }
  329.     #[Route('/autocomplete',name'autocomplete')]
  330.     public function SearchAuto(Connection $connection,Request $requestManagerRegistry $doctrine): JsonResponse
  331.     {   
  332.         $searChSoft "%".$request->get('keyword')."%";
  333.         $allCatSoft $connection->fetchAllAssociative("SELECT name FROM product where name like '".$searChSoft."' ");
  334.         return $this->json($allCatSoft);
  335.     }
  336.     #[Route('/contact',name'contact')]
  337.     public function Contact(Request $request,ManagerRegistry $doctrine): Response
  338.     {
  339.         $contact = new Contact();
  340.         $user $this->getUser();
  341.         $form $this->createForm(ContactType::class, $contact);
  342.         $form->handleRequest($request);
  343.         if ($form->isSubmitted() && $form->isValid()) {
  344.             $entityManager $doctrine->getManager();
  345.             $entityManager->persist($contact);
  346.             $entityManager->flush();
  347.             $this->addFlash(
  348.                 'notice',
  349.                 'Message Sent Successfully.'
  350.             );
  351.             return $this->redirectToRoute('contact');
  352.         }
  353.         //Menus
  354.         $page_menus $doctrine->getRepository(Pages::class);
  355.         $menus $page_menus->findBy(
  356.             ['is_active'=> 1]
  357.         );
  358.         if(count($menus) < 1){
  359.           $menus = array();
  360.         }
  361.         //Categories List
  362.         $cat_list $doctrine->getRepository(Category::class);
  363.         $allCat $cat_list->findBy(
  364.             ['is_active' => 1]
  365.         );
  366.         //Website Settings List
  367.         $WebsiteCustomizations $doctrine->getRepository(WebsiteCustomizations::class);
  368.         $web_settings $WebsiteCustomizations->findAll();
  369.         return $this->render('front_end/contact.html.twig', [
  370.             'user' => $user,
  371.             'form' => $form->createView(),
  372.             'allCat' => $allCat,
  373.             'web_settings'=> $web_settings,
  374.             'menus'=>$menus
  375.         ]);
  376.     }
  377.     
  378. }