<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Category;
use App\Entity\Product;
use App\Entity\WebsiteCustomizations;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\Connection;
use App\Entity\Pages;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Form\ContactType;
use App\Entity\Contact;
use Nzo\UrlEncryptorBundle\Encryptor\Encryptor;
class FrontEndController extends AbstractController
{
private $encryptor;
public function __construct(Encryptor $encryptor)
{
$this->encryptor = $encryptor;
}
#[Route('/', name: 'app_home')]
public function index(ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
$entityManager = $doctrine->getManager();
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
//Softwares list
$soft_list = $doctrine->getRepository(Product::class);
$allCatSoft = $soft_list->findBy(
['id' => 'ASC']
);
$conn = $entityManager->getConnection();
$sql = '
SELECT * FROM product
ORDER BY id DESC LIMIT 5
';
$stmt = $conn->prepare($sql);
$resultSet = $stmt->executeQuery();
$allCatSoft = $resultSet->fetchAllAssociative();
// dd($allCatSoft);
//Homepage Content
$page = $doctrine->getRepository(Pages::class);
$page_content = $page->findOneBy(
['id'=> 3]
);
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
return $this->render('front_end/index.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=>$allCatSoft,
'page_content'=>$page_content,
'menus'=>$menus,
'user'=>$user
]);
}
#[Route('/downloadlist/{id}',name: 'file_download')]
public function showPost(string $id, ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
$id = $this->encryptor->decrypt($id);
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Softwares list
$soft_list = $doctrine->getRepository(Product::class);
$allCatSoft = $soft_list->findBy(
['category' => $id]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
return $this->render('front_end/viewfiles.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=> $allCatSoft,
'menus'=>$menus,
'user'=>$user
]);
}
#[Route('/download/{id}',name: 'download_file')]
public function downloadFileAction(string $id, ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
$id = $this->encryptor->decrypt($id);
//Softwares list
$soft_list = $doctrine->getRepository(Product::class);
$allCatSoft = $soft_list->find(
['id' => $id]
);
$response = new BinaryFileResponse('uploads/files/'.$allCatSoft->getFileToDownload());
// $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,'pdf.pdf');
return $response;
}
#[Route('/account', name: 'email_verify')]
public function accountVerify(ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
$user = $this->getUser();
return $this->render('front_end/accountverify.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'menus'=>$menus,
'user'=>$user
]);
}
#[Route('/search', name: 'search_result')]
public function search(Connection $connection, ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
$searChSoft = "%".$_POST['q']."%";
$allCatSoft = $connection->fetchAllAssociative("SELECT * FROM product where name like '".$searChSoft."' ");
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
return $this->render('front_end/search.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=>$allCatSoft,
'query'=>$_POST['q'],
'menus'=>$menus,
'user'=>$user
]);
}
#[Route('/page/{id}',name: 'view_page')]
public function ViewPage(string $id, ManagerRegistry $doctrine, Request $request): Response
{
$user = $this->getUser();
$id = $this->encryptor->decrypt($id);
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
//Softwares list
$soft_list = $doctrine->getRepository(Product::class);
$allCatSoft = $soft_list->findAll(
['id' => 'DESC']
);
//Homepage Content
$page = $doctrine->getRepository(Pages::class);
$page_content = $page->findOneBy(
['id'=> $id]
);
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
$contact = new Contact();
$user = $this->getUser();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $doctrine->getManager();
$entityManager->persist($contact);
$entityManager->flush();
$this->addFlash(
'notice',
'Message Sent Successfully.'
);
return $this->redirect($request->request->get('referer'));
}
return $this->render('front_end/page.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=>$allCatSoft,
'page_content'=>$page_content,
'menus'=>$menus,
'user'=>$user,
'form'=>$form->createView(),
]);
}
#[Route('/package',name: 'view_package')]
public function ViewPackage( ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
//Softwares list
$soft_list = $doctrine->getRepository(Product::class);
$allCatSoft = $soft_list->findAll(
['id' => 'DESC']
);
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
if(empty($user)){
$this->addFlash('loginError', 'To Subscribe You must register or login and complete payments to download.');
return $this->render('login/index.html.twig', [
'error' => "",
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=>$allCatSoft,
'menus'=>$menus,
'last_username' => '',
'redirect'=>'/package',
]);
}else{
return $this->render('front_end/subscribe.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=>$allCatSoft,
'menus'=>$menus,
'user'=>$user,
'stripe_key' => $_ENV["STRIPE_KEY"]
]);
}
}
#[Route('/detail/{id}',name: 'detail')]
public function SoftwareDetails(string $id, ManagerRegistry $doctrine): Response
{
$user = $this->getUser();
$id = $this->encryptor->decrypt($id);
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
//Softwares list
$soft_list = $doctrine->getRepository(Product::class);
$allCatSoft = $soft_list->findOneBy(
['id'=> $id ]
);
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
return $this->render('front_end/detail.html.twig', [
'allCat' => $allCat,
'web_settings'=> $web_settings,
'allCatSoft'=>$allCatSoft,
'menus'=>$menus,
'user'=>$user
]);
}
#[Route('/autocomplete',name: 'autocomplete')]
public function SearchAuto(Connection $connection,Request $request, ManagerRegistry $doctrine): JsonResponse
{
$searChSoft = "%".$request->get('keyword')."%";
$allCatSoft = $connection->fetchAllAssociative("SELECT name FROM product where name like '".$searChSoft."' ");
return $this->json($allCatSoft);
}
#[Route('/contact',name: 'contact')]
public function Contact(Request $request,ManagerRegistry $doctrine): Response
{
$contact = new Contact();
$user = $this->getUser();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $doctrine->getManager();
$entityManager->persist($contact);
$entityManager->flush();
$this->addFlash(
'notice',
'Message Sent Successfully.'
);
return $this->redirectToRoute('contact');
}
//Menus
$page_menus = $doctrine->getRepository(Pages::class);
$menus = $page_menus->findBy(
['is_active'=> 1]
);
if(count($menus) < 1){
$menus = array();
}
//Categories List
$cat_list = $doctrine->getRepository(Category::class);
$allCat = $cat_list->findBy(
['is_active' => 1]
);
//Website Settings List
$WebsiteCustomizations = $doctrine->getRepository(WebsiteCustomizations::class);
$web_settings = $WebsiteCustomizations->findAll();
return $this->render('front_end/contact.html.twig', [
'user' => $user,
'form' => $form->createView(),
'allCat' => $allCat,
'web_settings'=> $web_settings,
'menus'=>$menus
]);
}
}