<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use App\Repository\BusinessInformationRepository;
use App\Repository\BannerRepository;
use App\Repository\LogoPARepository;
use App\Repository\BlogRepository;
use App\Repository\BusinessCategoriesRepository;
use App\Entity\Company;
use App\Repository\CompanyRepository;
use App\Form\CompanyType;
use Doctrine\Persistence\ManagerRegistry as PersistenceManagerRegistry;
//use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityManagerInterface;
class MainController extends AbstractController
{
#[Route('/', name: 'app_main')]
public function index(Request $request, BusinessInformationRepository $repository, BlogRepository $blog_repository, LogoPARepository $logo_repository, BannerRepository $banner_repository, PaginatorInterface $paginator): Response
{
//show banner
$banner= $banner_repository->findBy( ['active' => true]);
//client a la une
$business=$paginator->paginate($repository->findBy(
['alaune' => true]
),
$request->query->getInt('page', 1),
20);
//Logo Page d'Accueil
$logo= $logo_repository->findBy( ['active' => true]);
//Blog Page d'Accueil
$blog= $blog_repository->findBy( ['active' => true]);
return $this->render('main/index.html.twig',[
"business"=>$business,
"banners"=>$banner,
"logos"=>$logo,
"blogs"=>$blog,
]);
}
// Fonction ajouter entreprise
#[Route('/ajouter', name: 'ajouter')]
public function ajouter(Request $request, PersistenceManagerRegistry $doctrine) :Response
{
$em = $doctrine->getManager();
$company=new Company();
//$email=$company->getEmail();
$form = $this->createForm(CompanyType::class, $company);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$em->persist($company);
$em->flush();
// send mail
$this->addFlash('success', 'Ajout avec succes');
return $this->redirectToRoute('ajouter');
}
return $this->render('main/ajouter_entreprise.html.twig',[
'company'=>$company,
'form'=>$form->createView()
]);
}
//SHOW CUSTMER DETAIL
#[Route('/c/{id}-{slug}', name: 'customer.show')]
public function show($id, $slug,Request $request, BusinessInformationRepository $repository) :Response
{
$business = $repository->find($id);
return $this->render('main/showcustomerdetail.html.twig',[
'business' => $business ,
]);
}
//Recherche par secteur d'activité
#[Route('/s/{id}-{slug}', name: 'customer.secteur')]
public function SecteurActivity(PaginatorInterface $paginator, Request $request,$id,$slug, BusinessCategoriesRepository $businesscat) :Response
{
$group_id=$id;
switch ($group_id) {
case 3:
$secteur = "Administration";
$banner_v='LAITERIE -safi.jpg';
break;
case 4:
$secteur = "Agroalimentaire";
$banner_v='LAITERIE -safi.jpg';
break;
case 5:
$secteur = "Chimie, Petrochimie";
$banner_v='LAITERIE -safi.jpg';
break;
case 6:
$secteur = "Commerce";
$banner_v='geramelec.jpg';
break;
case 7:
$secteur = "Construction";
$banner_v='ARRAYANE_PROMOTION.jpg';
break;
case 8:
$secteur = "Formation, Enseignement";
$banner_v='formation_dle.jpg';
break;
case 9:
$secteur = "Fournitures, Equipements";
$banner_v='GRS-ALGERIE.jpg';
break;
case 10:
$secteur = "Import/Export";
$banner_v='besthouse.jpg';
break;
case 11:
$secteur = "Impression, Edition";
$banner_v='impression_ipm.jpg';
break;
case 12:
$secteur = "Industrie de production";
$banner_v='LAITERIE -safi.jpg';
break;
case 13:
$secteur = "Santé";
$banner_v='sante_laboratoire_hematologie.jpg';
break;
case 14:
$secteur = "Service";
$banner_v='MAGHREB_PROSPECTION.jpg';
break;
case 15:
$secteur = "Tourisme";
$banner_v='tourisme_elboustane.jpg';
break;
case 16:
$secteur = "Transport";
$banner_v='FRICTION.jpg';
break;
case 17:
$secteur = "Sport, Artisanat & Loisirs";
$banner_v='LAITERIE -safi.jpg';
break;
case 18:
$secteur = "Elevage, aviculture et horticulture";
$banner_v='elevage_bouhadra.jpg';
break;
}
//$repository = $this->getDoctrine()->getRepository(BusinessCategories::class);
// $product = $this->repository->findByMarque($marque);
//pagin
$business=$paginator->paginate($businesscat->findBy(
['group_id' => $group_id],
['statut' => 'DESC']
),
$request->query->getInt('page', 1),
11);
// dump($business);
return $this->render('main/showcustomersecteur.html.twig',[
"business"=>$business,
"secteur"=>$secteur,
"banner"=>$banner_v,
] );
}
// Liste client de la rubriques
#[Route('/detail/{id}-{slug}', name: 'customer.detail.rubrique')]
public function BusinessDetailRubrique(PaginatorInterface $paginator, Request $request, $id,$slug, BusinessInformationRepository $repository ) :Response
{
$category=$id;
$category = (string)$id;
//$banner=$bv;
// dd($banner);
// echo $category;
// $business = $this->repository->findCategory($category);
// $repository = $this->getDoctrine()->getRepository(BusinessInformation::class);
/* $business=$paginator->paginate($repository->findBy(
['categories' => $category] ),
$request->query->getInt('page', 1),
9);
*/
$business=$paginator->paginate($repository->findCategory($category),
$request->query->getInt('page', 1),
9);
// dump($business);
return $this->render('main/showcustomers.html.twig',[
"business"=>$business
// "bannerv"=>$banner
] );
// return new Response( '<html><body>Lucky number: '.$category.'</body></html>' );
}
//Static Routes
#[Route('/qui-sommes-nous', name: 'app_about')]
public function about(): Response
{
return $this->render('main/about.html.twig');
}
#[Route('/nos-offres', name: 'app_nos_offres')]
public function offre(): Response
{
return $this->render('main/offre.html.twig');
}
#[Route('/appel-offres', name: 'app_appel_offres')]
public function appel(): Response
{
return $this->render('main/appel_offre.html.twig');
}
#[Route('/tout-secteur', name: 'app_secteur')]
public function secteur(): Response
{
return $this->render('main/secteurs.html.twig');
}
#[Route('/blogs', name: 'app_blogs')]
public function blog(BlogRepository $blog_repository): Response
{
$blog=$blog_repository->findAll();
return $this->render('main/blogs.html.twig',
[
"blogs"=>$blog
]);
}
}