src/Controller/Front/CompanyController.php line 85

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Company;
  4. use App\Entity\PlanningCompany;
  5. use App\Repository\AvisRepository;
  6. use App\Repository\CommandRepository;
  7. use App\Repository\CompanyRepository;
  8. use App\Repository\ProductRepository;
  9. use Knp\Component\Pager\PaginatorInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class CompanyController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/prestataires/recherche/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_company_search")
  19.      */
  20.     public function searchCompanyFilter(int $pageRequest $requestCompanyRepository $companyRepositoryPaginatorInterface $paginatorSessionInterface $session)
  21.     {
  22.         if ($request->isMethod('POST')) {
  23.             if ($request->get('department_filter') || $request->get('category_filter')) {
  24.                 $parameters = [
  25.                     'department' => $request->get('department_filter') !== '' $request->get('department_filter') : null,
  26.                     'category' => $request->get('category_filter') !== '' $request->get('category_filter') : null,
  27.                     'date_evt' => $request->get('date_filter') !== '' $request->get('date_filter') : null,
  28.                 ];
  29.                 $session->set('department_company'$request->get('department_filter'));
  30.                 $session->set('category_company'$request->get('category_filter'));
  31.                 $session->set('date_evt'$request->get('date_filter'));
  32.                 $companies $companyRepository->searchCompany($parameters);
  33.                 $n_companies = [];
  34.                 // on filtre sur les prestataires qui sont disponibles a la date souhaitee
  35.                 foreach ($companies as $compagny){
  36.                     $dtDispo true;
  37.                     /** @var Company $compagny */
  38.                     foreach ($compagny->getPlanningCompanies() as $planningCompany){
  39.                         /** @var PlanningCompany $planningCompany */
  40.                         if ($planningCompany->getAtDate()->format("d/m/Y") == $parameters["date_evt"]){
  41.                             $dtDispo false;
  42.                             continue;
  43.                         }
  44.                     }
  45.                     if ($dtDispo) {
  46.                         $n_companies[] = $compagny;
  47.                     }
  48.                 }
  49.                 $pagination $paginator->paginate(
  50.                     $n_companies,
  51.                     $page/*page number*/
  52.                     15 /*limit per page*/
  53.                 );
  54.                 return $this->render('front/company/list.html.twig', [
  55.                     'companies' => $pagination,
  56.                     'countCompanies' => count($n_companies)
  57.                 ]);
  58.             }
  59.         }
  60.         $session->remove('department');
  61.         $session->remove('date_evt');
  62.         $session->remove('min_price');
  63.         $session->remove('max_price');
  64.         $session->remove('category');
  65.         return $this->redirectToRoute('front_company_list');
  66.     }
  67.     /**
  68.      * @Route("/prestataires/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_company_list")
  69.      */
  70.     public function list(int $pageCompanyRepository $companyRepositoryPaginatorInterface $paginator)
  71.     {
  72.         // $companies = $companyRepository->findBy(['isConfirmed' => true, 'isValidDocument' => true]);
  73.         $companies $companyRepository->getCompaniesprodActif();
  74.         $pagination $paginator->paginate(
  75.             $companies,
  76.             $page/*page number*/
  77.             /*limit per page*/
  78.         );
  79.         return $this->render('front/company/list.html.twig', [
  80.             'companies' => $pagination,
  81.             'countCompanies' => count($companies)
  82.         ]);
  83.     }
  84.     /**
  85.      * @Route("/prestataire/{id}/{companySlug}/{page}", defaults={"page"=1}, requirements={"page"="\d+"}, name="front_company_single")
  86.      */
  87.     public function single(int $pageCompany $companyAvisRepository $avisRepositoryPaginatorInterface $paginatorCommandRepository $commandRepositoryProductRepository $productRepository)
  88.     {
  89.         $commands $commandRepository->getCommandsByCompany($company);
  90.         $lastProducts $productRepository->getAllProductsByCompany($company);
  91.         $allAvis $avisRepository->getAvisByCompany($company);
  92.         $pagination $paginator->paginate(
  93.             $allAvis,
  94.             $page/*page number*/
  95.             20 /*limit per page*/
  96.         );
  97.         $globalNote = ['totalNote' => 0'count' => 0];
  98.         $qualityService = ['totalNote' => 0'count' => 0];
  99.         $fiablity = ['totalNote' => 0'count' => 0];
  100.         $price = ['totalNote' => 0'count' => 0];
  101.         $speed = ['totalNote' => 0'count' => 0];
  102.         $conformDescription = ['totalNote' => 0'count' => 0];
  103.         $communication = ['totalNote' => 0'count' => 0];
  104.         foreach ($allAvis as $avis) {
  105.             $globalNote['totalNote'] = $globalNote['totalNote'] + $avis->getGlobalNote();
  106.             $globalNote['count'] = $globalNote['count'] + 1;
  107.             $qualityService['totalNote'] = $qualityService['totalNote'] + $avis->getServiceQuality();
  108.             $qualityService['count'] = $qualityService['count'] + 1;
  109.             $fiablity['totalNote'] = $fiablity['totalNote'] + $avis->getFiability();
  110.             $fiablity['count'] = $fiablity['count'] + 1;
  111.             $price['totalNote'] = $price['totalNote'] + $avis->getPrice();
  112.             $price['count'] = $price['count'] + 1;
  113.             $speed['totalNote'] = $speed['totalNote'] + $avis->getSpeed();
  114.             $speed['count'] = $speed['count'] + 1;
  115.             $conformDescription['totalNote'] = $conformDescription['totalNote'] + $avis->getConformDescription();
  116.             $conformDescription['count'] = $conformDescription['count'] + 1;
  117.             $communication['totalNote'] = $communication['totalNote'] + $avis->getCommunication();
  118.             $communication['count'] = $communication['count'] + 1;
  119.         }
  120.         return $this->render('front/company/single.html.twig', [
  121.             'company' => $company,
  122.             'countCommands' => count($commands),
  123.             'lastProducts' => $lastProducts,
  124.             'avis' => $pagination,
  125.             'notes' => [
  126.                 'globalNote' => $globalNote,
  127.                 'qualityService' => $qualityService,
  128.                 'price' => $price,
  129.                 'speed' => $speed,
  130.                 'conformDescription' => $conformDescription,
  131.                 'communication' => $communication,
  132.                 'fiability' => $fiablity
  133.             ]
  134.         ]);
  135.     }
  136. }