src/Controller/Page/CompaniesController.php line 89

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Page;
  3. use App\Component\Configuration\Util\Config;
  4. use App\Component\FeedbackCompany\Util\FeedbackCompanyUtil;
  5. use App\Entity\Company;
  6. use App\Entity\CompanyAttributeValue;
  7. use App\Entity\Option;
  8. use App\Entity\OptionValue;
  9. use App\EventListener\FeatureFlagListener;
  10. use App\Renderer\Page as PageRenderer;
  11. use App\Service\CompanyService;
  12. use App\Service\SiteService;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Exception;
  15. use Flagception\Manager\FeatureManagerInterface;
  16. use FOS\HttpCacheBundle\Configuration\Tag;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Twig\Error\LoaderError;
  22. use Twig\Error\RuntimeError;
  23. use Twig\Error\SyntaxError;
  24. #[Route(path'/companies')]
  25. class CompaniesController extends AbstractController
  26. {
  27.     public function __construct(
  28.         private readonly PageRenderer $pageRenderer,
  29.         private readonly SiteService $siteService,
  30.         private readonly CompanyService $companyService,
  31.         private readonly FeatureManagerInterface $featureManager,
  32.         private readonly Config $config,
  33.         private readonly FeedbackCompanyUtil $feedbackCompanyUtil,
  34.         private readonly EntityManagerInterface $entityManager,
  35.     ) {
  36.     }
  37.     /**
  38.      * @Tag({"pages", "company-overview"})
  39.      *
  40.      * @throws LoaderError
  41.      * @throws RuntimeError
  42.      * @throws SyntaxError
  43.      */
  44.     #[Route(path'/'name'companies')]
  45.     public function indexAction(Request $request): Response
  46.     {
  47.         $map null !== $request->get('map');
  48.         $companyRepository $this->entityManager->getRepository(Company::class);
  49.         if (true === $this->config->get('site_company_hidden_when_detail_disabled')) {
  50.             $companies $companyRepository->findBy(['detailPage' => true]);
  51.         } else {
  52.             $companies $companyRepository->findAll();
  53.         }
  54.         $companyAttributeValues $this->getDoctrine()->getRepository(CompanyAttributeValue::class)->findAll();
  55.         array_walk($companies, static fn (Company $company) => $company->setAttributes(array_values(array_filter(
  56.             $companyAttributeValues,
  57.             static fn (CompanyAttributeValue $value) => $value->getSubject()->getId() === $company->getId()
  58.         )))
  59.         );
  60.         $overviewVacancyCounts = [];
  61.         if ($this->config->get('site_company_overview_option') instanceof Option) {
  62.             $overviewVacancyCounts $this->getDoctrine()->getRepository(OptionValue::class)
  63.                 ->findOptionsWithVacancyCountForCompanyOption(
  64.                     array_map(static fn (Company $company) => $company->getId(), $companies),
  65.                     $this->config->get('site_company_overview_option')
  66.                 );
  67.         }
  68.         $reviewSummary = [];
  69.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_FEEDBACK_COMPANY)) {
  70.             $reviewSummary $this->feedbackCompanyUtil->fetchAllById();
  71.         }
  72.         return $this->pageRenderer
  73.             ->renderPage(
  74.                 '{companies}',
  75.                 '@default/pages/company_overview.html.twig',
  76.                 [
  77.                     'companies' => $companies,
  78.                     'map' => $map,
  79.                     'mapStyle' => $this->config->get('site_company_map_style'),
  80.                     'overviewVacancyCounts' => $overviewVacancyCounts,
  81.                     'reviewSummary' => $reviewSummary,
  82.                 ]
  83.             )
  84.         ;
  85.     }
  86.     /**
  87.      * @Tag("companies")
  88.      */
  89.     #[Route(path'/companies_slider_overview'name'companies_slider_overview')]
  90.     public function sliderOverviewAction(Request $request): Response
  91.     {
  92.         $limit $request->get('limit'24);
  93.         $site $this->siteService->getSite();
  94.         $sort $this->config->get('site_company_slider_snippet_sort');
  95.         if (Company::SORT_VACANCY_COUNT === $sort) {
  96.             $companies $this->companyService->findCompaniesOrderedByVacancyCount(
  97.                 $limit,
  98.                 $site,
  99.                 $request->getLocale()
  100.             );
  101.         } else {
  102.             $companies $this->getDoctrine()->getRepository(Company::class)
  103.                 ->findBy([], ['name' => 'asc'], $limit);
  104.         }
  105.         $overviewVacancyCounts = [];
  106.         if ($this->config->get('site_company_overview_option') instanceof Option) {
  107.             $overviewVacancyCounts $this->getDoctrine()->getRepository(OptionValue::class)
  108.                 ->findOptionsWithVacancyCountForCompanyOption(
  109.                     array_map(static fn (Company $company) => $company->getId(), $companies),
  110.                     $this->config->get('site_company_overview_option')
  111.                 );
  112.         }
  113.         $reviewSummary = [];
  114.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_FEEDBACK_COMPANY)) {
  115.             $reviewSummary $this->feedbackCompanyUtil->fetchAllById();
  116.         }
  117.         $template '@default/pages/company_slider_overview.html.twig';
  118.         if ($templateName $request->get('template')) {
  119.             $template sprintf('@default/pages/%s.html.twig'$templateName);
  120.         }
  121.         return $this->render($template, [
  122.             'companies' => $companies,
  123.             'overviewVacancyCounts' => $overviewVacancyCounts,
  124.             'reviewSummary' => $reviewSummary,
  125.         ]);
  126.     }
  127.     /**
  128.      * @Tag("companies")
  129.      */
  130.     #[Route(path'/featured_grid'name'company_featured_grid')]
  131.     public function topCompanySnippet(Request $request): Response
  132.     {
  133.         $site null;
  134.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_CHILD_SITE)) {
  135.             $site $request->getHost();
  136.         }
  137.         if ($request->get('site')) {
  138.             $site $request->get('site');
  139.         }
  140.         try {
  141.             $companies $this->companyService->getTopCompanies(
  142.                 $request->get('limit'4),
  143.                 $site
  144.             );
  145.         } catch (Exception) {
  146.             $companies = [];
  147.         }
  148.         return $this->render(
  149.             '@default/pages/company_featured_grid.html.twig',
  150.             ['companies' => $companies]
  151.         );
  152.     }
  153. }