src/Controller/CompanyController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Company;
  4. use App\Form\CompanyType;
  5. use App\Repository\CompanyRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/company")
  12.  */
  13. class CompanyController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/", name="app_company_index", methods={"GET"})
  17.      */
  18.     public function index(CompanyRepository $companyRepository): Response
  19.     {
  20.         return $this->render('company/index.html.twig', [
  21.         'companies' => $companyRepository->findBy(['status' => 1]),
  22.     ]);
  23.     }
  24.     /**
  25.      * @Route("/new", name="app_company_new", methods={"GET", "POST"})
  26.      */
  27.     public function new(Request $requestCompanyRepository $companyRepository): Response
  28.     {
  29.         $company = new Company();
  30.         $form $this->createForm(CompanyType::class, $company);
  31.         $form->handleRequest($request);
  32.         if ($form->isSubmitted() && $form->isValid()) {
  33.             $companyRepository->add($companytrue);
  34.             return $this->redirectToRoute('app_company_index', [], Response::HTTP_SEE_OTHER);
  35.         }
  36.         return $this->renderForm('company/new.html.twig', [
  37.             'company' => $company,
  38.             'form' => $form,
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("/{id}", name="app_company_show", methods={"GET"})
  43.      */
  44.     public function show(Company $company): Response
  45.     {
  46.         return $this->render('company/show.html.twig', [
  47.             'company' => $company,
  48.         ]);
  49.     }
  50.     /**
  51.      * @Route("/{id}/edit", name="app_company_edit", methods={"GET", "POST"})
  52.      */
  53.     public function edit(Request $requestCompany $companyCompanyRepository $companyRepository): Response
  54.     {
  55.         $form $this->createForm(CompanyType::class, $company);
  56.         $form->handleRequest($request);
  57.         if ($form->isSubmitted() && $form->isValid()) {
  58.             $companyRepository->add($companytrue);
  59.             return $this->redirectToRoute('app_company_index', [], Response::HTTP_SEE_OTHER);
  60.         }
  61.         return $this->renderForm('company/edit.html.twig', [
  62.             'company' => $company,
  63.             'form' => $form,
  64.         ]);
  65.     }
  66.     /**
  67.      * @Route("/{id}", name="app_company_delete", methods={"POST"})
  68.      */
  69.     public function delete(Request $requestCompany $companyCompanyRepository $companyRepository): Response
  70.     {
  71.         if ($this->isCsrfTokenValid('delete'.$company->getId(), $request->request->get('_token'))) {
  72.             $companyRepository->remove($companytrue);
  73.         }
  74.         return $this->redirectToRoute('app_company_index', [], Response::HTTP_SEE_OTHER);
  75.     }
  76.     /**
  77.      * @Route("/category/{categorySlug}", name="company_by_category")
  78.      */
  79.     public function byCategory(string $categorySlugCompanyRepository $companyRepository): Response
  80.     {
  81.         // Déslugifier (ex: "electronics-and-electrical" â†’ "Electronics & Electrical")
  82.         $categoryName str_replace(['-''_'], [' '' '], $categorySlug);
  83.         $companies $companyRepository->findBy([
  84.             'industry' => $categoryName,
  85.             'status' => 1
  86.         ]);
  87.         return $this->render('company/category.html.twig', [
  88.             'companies' => $companies,
  89.         ]);
  90.     }
  91. }