src/Controller/Page/CompanyController.php line 156

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Page;
  3. use App\Component\Configuration\Util\Config;
  4. use App\Decorator\VacancyDecorator;
  5. use App\Entity\Company;
  6. use App\Entity\FeedbackCompany;
  7. use App\Entity\Option;
  8. use App\Entity\OptionValue;
  9. use App\Entity\Route as RouteEntity;
  10. use App\Entity\Testimonial;
  11. use App\EventListener\FeatureFlagListener;
  12. use App\Form\Setting\CompanySettingType;
  13. use App\Manager\TagManager;
  14. use App\Renderer\Page as PageRenderer;
  15. use App\Service\CompanyService;
  16. use App\Service\SiteService;
  17. use Flagception\Manager\FeatureManagerInterface;
  18. use FOS\HttpCacheBundle\Configuration\Tag;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Twig\Error\LoaderError;
  23. use Twig\Error\RuntimeError;
  24. use Twig\Error\SyntaxError;
  25. class CompanyController extends AbstractController
  26. {
  27.     private PageRenderer $pageRenderer;
  28.     private TagManager $tagManager;
  29.     private FeatureManagerInterface $featureManager;
  30.     private CompanyService $service;
  31.     private SiteService $siteService;
  32.     private Config $config;
  33.     public function __construct(
  34.         PageRenderer $pageRenderer,
  35.         TagManager $tagManager,
  36.         FeatureManagerInterface $featureManager,
  37.         CompanyService $service,
  38.         SiteService $siteService,
  39.         Config $config
  40.     ) {
  41.         $this->pageRenderer $pageRenderer;
  42.         $this->tagManager $tagManager;
  43.         $this->featureManager $featureManager;
  44.         $this->service $service;
  45.         $this->siteService $siteService;
  46.         $this->config $config;
  47.     }
  48.     /**
  49.      * @Tag("vacancies")
  50.      * @Tag("company-detail", expression="'company-'~id")
  51.      *
  52.      * @throws LoaderError
  53.      * @throws RuntimeError
  54.      * @throws SyntaxError
  55.      * @throws \Twig_Error_Loader
  56.      * @throws \Twig_Error_Runtime
  57.      * @throws \Twig_Error_Syntax
  58.      * @throws \Exception
  59.      */
  60.     public function detailAction(
  61.         Request $request,
  62.         VacancyDecorator $vacancyDecorator
  63.     ): Response {
  64.         if (!$company $this->service->getCompanyFromRequest($request)) {
  65.             throw $this->createNotFoundException('Company is not available');
  66.         }
  67.         if (!$company->isDetailPagePublished()) {
  68.             throw $this->createNotFoundException();
  69.         }
  70.         $map null !== $request->get('map');
  71.         if (
  72.             $company->getFriendlyUrl() &&
  73.             $this->featureManager->isActive(FeatureFlagListener::FEATURE_COMPANY_FRIENDY_URL) &&
  74.             'company-'.$company->getFriendlyUrl() !== $request->get('_route')
  75.         ) {
  76.             return $this->redirectToRoute('company-'.$company->getFriendlyUrl());
  77.         }
  78.         if ($company->getDescription() && $description json_decode($company->getDescription(), true512\JSON_THROW_ON_ERROR)) {
  79.             $company->setDescription(implode(''$description));
  80.         }
  81.         $vacancyLimit $this->config->get('site_company_vacancies_on_detail_limit');
  82.         $vacancies = [];
  83.         switch ($this->config->get('site_company_vacancies_on_detail_type')) {
  84.             case CompanySettingType::DETAIL_VACANCY_TYPE_FEATURED:
  85.                 $vacancies $this->service->getActiveVacancies(
  86.                     $company,
  87.                     $vacancyLimit,
  88.                     $this->siteService->getSite(),
  89.                     null,
  90.                     $request->getLocale(),
  91.                     true
  92.                 );
  93.                 break;
  94.             case CompanySettingType::DETAIL_VACANCY_TYPE_RECENT:
  95.                 $vacancies $this->service->getActiveVacancies(
  96.                     $company,
  97.                     $vacancyLimit,
  98.                     $this->siteService->getSite(),
  99.                     null,
  100.                     $request->getLocale()
  101.                 );
  102.                 break;
  103.             case CompanySettingType::DETAIL_VACANCY_TYPE_RECENT_WITH_FILTER:
  104.                 $preFilters $this->config->get('site_company_vacancies_pre_filter');
  105.                 $vacancies $this->service->getActiveVacancies(
  106.                     $company,
  107.                     $vacancyLimit,
  108.                     $this->siteService->getSite(),
  109.                     $preFilters,
  110.                     $request->getLocale()
  111.                 );
  112.                 break;
  113.         }
  114.         $vacancyDecorator->decorate($vacancies);
  115.         $relatedTestimonials $this->tagManager->getEntitiesByRelatedTags($companyTestimonial::class, false$request->getLocale());
  116.         $route $this->getDoctrine()->getRepository(RouteEntity::class)->findOneBy(['name' => 'company_detail']);
  117.         $heroConfiguration null;
  118.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_HERO)) {
  119.             $heroConfiguration $company->getHeroConfiguration();
  120.         }
  121.         $reviews = [];
  122.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_FEEDBACK_COMPANY)) {
  123.             $reviews $this->getDoctrine()->getRepository(FeedbackCompany::class)->findOneBy(['company' => $company]);
  124.             if (!empty($reviews) && \count($reviews->getReviews()) > 4) {
  125.                 $reviews->setReviews(\array_slice($reviews->getReviews(), -44));
  126.             }
  127.         }
  128.         return $this->pageRenderer
  129.             ->withEntity($company)
  130.             ->renderPage(
  131.                 '{company}',
  132.                 '@default/pages/company_detail.html.twig',
  133.                 [
  134.                     'company' => $company,
  135.                     'map' => $map,
  136.                     'vacancies' => $vacancies,
  137.                     'companyVacancies' => $vacancies,
  138.                     'companyVacanciesTotalCount' => $company->getPublishedVacancyCount(),
  139.                     'relatedTestimonials' => $relatedTestimonials,
  140.                     'overviewCountData' => $this->getOverviewOptionValues($company),
  141.                     'reviews' => $reviews,
  142.                 ],
  143.                 [$company->getCanonicalUrl()],
  144.                 [
  145.                     'metaTitle' => $company->getMetaTitle(),
  146.                     'metaDescription' => $company->getMetaDescription(),
  147.                 ],
  148.                 null,
  149.                 $route,
  150.                 $heroConfiguration
  151.             );
  152.     }
  153.     private function getOverviewOptionValues(Company $company): array
  154.     {
  155.         if (!$this->config->get('site_company_overview_option') instanceof Option) {
  156.             return [];
  157.         }
  158.         $optionValueRepository $this->getDoctrine()->getRepository(OptionValue::class);
  159.         $overviewOptionValues $optionValueRepository->findBy(
  160.             ['option' => $this->config->get('site_company_overview_option')],
  161.             ['value' => 'asc']
  162.         );
  163.         if (empty($overviewOptionValues)) {
  164.             return [];
  165.         }
  166.         $overviewCountData $optionValueRepository->findOptionsWithVacancyCountForCompanyOption(
  167.             [$company->getId()], $this->config->get('site_company_overview_option')
  168.         )[$company->getId()] ?? [];
  169.         foreach ($overviewOptionValues as $optionValue) {
  170.             $count 0;
  171.             foreach ($overviewCountData as $countData) {
  172.                 if ($countData['id'] === $optionValue->getId()) {
  173.                     $count $countData['vacancy_count'];
  174.                 }
  175.             }
  176.             $optionValue->setVacancyCount($count);
  177.         }
  178.         return $overviewOptionValues;
  179.     }
  180. }