src/Service/ApplicantService.php line 280

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Client\MultiSiteClient;
  4. use App\Component\Configuration\Util\Config;
  5. use App\Entity\Applicant;
  6. use App\Entity\ApplicantForm;
  7. use App\Entity\ApplicantStatus;
  8. use App\Entity\Company;
  9. use App\Entity\GdprStatement;
  10. use App\Entity\MultiMedia;
  11. use App\Entity\OptionValue;
  12. use App\Entity\Recruiter;
  13. use App\Entity\Status;
  14. use App\Entity\Vacancy;
  15. use App\Event\ApplicantEvent;
  16. use App\EventListener\FeatureFlagListener;
  17. use App\Form\ApplicantFilterType;
  18. use App\Form\Setting\ApplicantSettingType;
  19. use App\Manager\MultiMediaManager;
  20. use App\Type\DataTable\ApplicantTableType;
  21. use App\Type\DataTable\ORMApplicantTableType;
  22. use App\Util\AdminFilterUtil;
  23. use App\Util\PhoneNumberUtil;
  24. use App\Util\StringToEntityUtil;
  25. use Doctrine\Common\Collections\Criteria;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. use Flagception\Manager\FeatureManagerInterface;
  28. use JMS\Serializer\SerializerInterface;
  29. use Omines\DataTablesBundle\DataTable;
  30. use Omines\DataTablesBundle\DataTableFactory;
  31. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  32. use Symfony\Component\HttpFoundation\File\UploadedFile;
  33. use Symfony\Component\HttpFoundation\RedirectResponse;
  34. use Symfony\Component\HttpFoundation\Request;
  35. use Symfony\Component\HttpFoundation\RequestStack;
  36. use Symfony\Component\Routing\RouterInterface;
  37. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  38. use Symfony\Component\Validator\Validator\ValidatorInterface;
  39. use Twig\Environment;
  40. use Twig\Error\LoaderError;
  41. use Twig\Error\RuntimeError;
  42. use Twig\Error\SyntaxError;
  43. class ApplicantService
  44. {
  45.     public const OPEN_APPLICATION_ID 0;
  46.     private const TYPE_FILE 'file';
  47.     private const TYPE_PHONE 'phone';
  48.     private ?Request $request;
  49.     private EntityManagerInterface $entityManager;
  50.     private ValidatorInterface $validator;
  51.     private StringToEntityUtil $stringToEntityUtil;
  52.     private EventDispatcherInterface $eventDispatcher;
  53.     private MultiSiteClient $client;
  54.     private SerializerInterface $serializer;
  55.     private RouterInterface $router;
  56.     private Environment $twig;
  57.     private FeatureManagerInterface $featureManager;
  58.     private Config $config;
  59.     private AdminFilterUtil $adminFilterUtil;
  60.     private DataTableFactory $dataTableFactory;
  61.     private AuthorizationCheckerInterface $authorizationChecker;
  62.     private MultiMediaManager $multiMediaManager;
  63.     /**
  64.      * ApplicantService constructor.
  65.      */
  66.     public function __construct(
  67.         RequestStack $requestStack,
  68.         EntityManagerInterface $entityManager,
  69.         ValidatorInterface $validator,
  70.         StringToEntityUtil $stringToEntityUtil,
  71.         EventDispatcherInterface $eventDispatcher,
  72.         MultiSiteClient $multiSiteClient,
  73.         SerializerInterface $serializer,
  74.         RouterInterface $router,
  75.         Config $config,
  76.         Environment $twig,
  77.         FeatureManagerInterface $featureManager,
  78.         AdminFilterUtil $adminFilterUtil,
  79.         DataTableFactory $dataTableFactory,
  80.         AuthorizationCheckerInterface $authorizationChecker,
  81.         MultiMediaManager $multiMediaManager
  82.     ) {
  83.         $this->request $requestStack->getCurrentRequest();
  84.         $this->entityManager $entityManager;
  85.         $this->validator $validator;
  86.         $this->stringToEntityUtil $stringToEntityUtil;
  87.         $this->eventDispatcher $eventDispatcher;
  88.         $this->client $multiSiteClient;
  89.         $this->serializer $serializer;
  90.         $this->router $router;
  91.         $this->config $config;
  92.         $this->twig $twig;
  93.         $this->featureManager $featureManager;
  94.         $this->adminFilterUtil $adminFilterUtil;
  95.         $this->dataTableFactory $dataTableFactory;
  96.         $this->authorizationChecker $authorizationChecker;
  97.         $this->multiMediaManager $multiMediaManager;
  98.     }
  99.     /**
  100.      * @param string[]       $contents
  101.      * @param UploadedFile[] $files
  102.      *
  103.      * @throws \RuntimeException
  104.      * @throws \JsonException
  105.      */
  106.     public function createApplicant(array $contents, array $files): ?Applicant
  107.     {
  108.         $applicant = new Applicant();
  109.         $vacancyId = (int) $this->request->get('vacancy');
  110.         $applicantFormRepository $this->entityManager->getRepository(ApplicantForm::class);
  111.         if (self::OPEN_APPLICATION_ID !== $vacancyId) {
  112.             /** @var Vacancy $vacancy */
  113.             $vacancy $this->entityManager->getRepository(Vacancy::class)->find($vacancyId);
  114.             $applicant->setVacancy($vacancy);
  115.             $applicantForm $vacancy->getApplicantForm();
  116.         } else {
  117.             $applicantForm $applicantFormRepository->findOneBy(['openForm' => true]);
  118.         }
  119.         if (!$applicantForm) {
  120.             $applicantForm $applicantFormRepository->findOneBy(['default' => true]);
  121.         }
  122.         $formFields json_decode($applicantForm->getFields(), true512\JSON_THROW_ON_ERROR);
  123.         foreach ($formFields as $formField) {
  124.             $field $formField['name'];
  125.             if (self::TYPE_PHONE === $formField['type']) {
  126.                 $contents[$field] = PhoneNumberUtil::createPhoneNumber($contents[$field]);
  127.             }
  128.             if (isset($formField['required']) && $formField['required']) {
  129.                 if (self::TYPE_FILE !== $formField['type'] && !isset($contents[$field])) {
  130.                     throw new \RuntimeException(sprintf("Mandatory field '%s' is missing"$field));
  131.                 }
  132.                 if (self::TYPE_FILE === $formField['type'] && !\array_key_exists($field$files)) {
  133.                     throw new \RuntimeException(sprintf("Mandatory file '%s' is missing"$field));
  134.                 }
  135.             }
  136.             if (!method_exists($applicant'set'.$field)) {
  137.                 continue;
  138.             }
  139.             if (self::TYPE_FILE !== $formField['type']) {
  140.                 $applicant->{'set'.$field}($contents[$field] ?? null);
  141.             }
  142.             if (self::TYPE_FILE === $formField['type']) {
  143.                 $applicant->{'set'.$field}($files[$field] ?? null);
  144.             }
  145.         }
  146.         if (!empty($contents['utm']) && \is_array($contents['utm'])) {
  147.             $utm filter_var_array($contents['utm'], [
  148.                 'utm_campaign' => \FILTER_SANITIZE_FULL_SPECIAL_CHARS,
  149.                 'utm_source' => \FILTER_SANITIZE_FULL_SPECIAL_CHARS,
  150.                 'utm_medium' => \FILTER_SANITIZE_FULL_SPECIAL_CHARS,
  151.                 'utm_term' => \FILTER_SANITIZE_FULL_SPECIAL_CHARS,
  152.                 'utm_content' => \FILTER_SANITIZE_FULL_SPECIAL_CHARS,
  153.             ], false) ?? [];
  154.             $applicant->setUtm($utm);
  155.         }
  156.         $errors $this->validator->validate($applicant);
  157.         if ($errors->count() > 0) {
  158.             throw new \RuntimeException($errors);
  159.         }
  160.         if (($defaultStatusObject $this->config->get('site_applicant_default_status'))
  161.             && $defaultStatus $this->entityManager
  162.                 ->getRepository(Status::class)
  163.                 ->find($defaultStatusObject->getId())
  164.         ) {
  165.             $applicant->setStatus($defaultStatus);
  166.         }
  167.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_GDPR)
  168.             && !empty($gdprId = (int) $this->request->get('gdpr'))
  169.             && $gdprStatement $this->entityManager
  170.                 ->getRepository(GdprStatement::class)
  171.                 ->find($gdprId)
  172.         ) {
  173.             $applicant->setGdpr($gdprStatement);
  174.         }
  175.         $this->eventDispatcher->dispatch(
  176.             new ApplicantEvent($applicantnull),
  177.             ApplicantEvent::EVENT_PRE_PERSIST
  178.         );
  179.         $applicant->setFileName($applicant->getFileName());
  180.         $applicant->setFileSize($applicant->getFileSize());
  181.         $applicant->setFileNameMotivation($applicant->getFileNameMotivation());
  182.         $applicant->setFileSizeMotivation($applicant->getFileSizeMotivation());
  183.         $this->entityManager->persist($applicant);
  184.         $this->entityManager->flush();
  185.         $this->eventDispatcher->dispatch(
  186.             new ApplicantEvent($applicantnull),
  187.             ApplicantEvent::EVENT_POST_PERSIST
  188.         );
  189.         return $applicant;
  190.     }
  191.     public function addFilesFromRequest(Request $requestApplicant $applicant): Applicant
  192.     {
  193.         /**
  194.          * @var string       $name
  195.          * @var UploadedFile $file
  196.          */
  197.         foreach ($request->files as $name => $file) {
  198.             $setMethod 'set'.$name;
  199.             if (method_exists($applicant$setMethod)) {
  200.                 $applicant->$setMethod($file);
  201.             }
  202.         }
  203.         $this->entityManager->persist($applicant);
  204.         $this->entityManager->flush();
  205.         return $applicant;
  206.     }
  207.     /**
  208.      * @throws \JsonException
  209.      */
  210.     public function handleForm(Request $requestApplicant $applicantVacancy $vacancy): array
  211.     {
  212.         $multipart = [];
  213.         foreach ($request->files->all() as $files) {
  214.             foreach ($files as $name => $file) {
  215.                 if (empty($file['file'])) {
  216.                     continue;
  217.                 }
  218.                 $file $file['file'];
  219.                 /* @var UploadedFile $file */
  220.                 $multipart[] = [
  221.                     'name' => $name,
  222.                     'contents' => fopen($file->getRealPath(), 'r'),
  223.                     'filename' => $file->getClientOriginalName(),
  224.                 ];
  225.             }
  226.         }
  227.         foreach (json_decode($this->serializer->serialize($applicant'json'), false512\JSON_THROW_ON_ERROR) as $field => $value) {
  228.             if ('phone' === $field) {
  229.                 $value = (string) $applicant->getPhone();
  230.             }
  231.             $multipart[] = [
  232.                 'name' => $field,
  233.                 'contents' => $value,
  234.             ];
  235.         }
  236.         $response $this->client->post(
  237.             $this->router->generate('rest_applicant_create', ['vacancy' => $vacancy->getId()]),
  238.             [
  239.                 'multipart' => $multipart,
  240.             ]
  241.         );
  242.         $applicantResponse $response->getBody()->getContents();
  243.         if (empty($applicantResponse)) {
  244.             throw new \RuntimeException('Applicant could not be posted to master site');
  245.         }
  246.         return json_decode($applicantResponsetrue512\JSON_THROW_ON_ERROR);
  247.     }
  248.     public function getAsyncApplicantFormForVacancy(int $id): ApplicantForm
  249.     {
  250.         $response $this->client->get($this->router->generate('rest_vacancy_full_form', ['id' => $id]));
  251.         return $this->serializer->deserialize(
  252.             $response->getBody()->getContents(),
  253.             ApplicantForm::class,
  254.             'json'
  255.         );
  256.     }
  257.     public function getApplicantOwner(Applicant $applicant): ?Recruiter
  258.     {
  259.         $recruiter null;
  260.         if ($vacancy $applicant->getVacancy()) {
  261.             $recruiter $vacancy->getRecruiter();
  262.         }
  263.         try {
  264.             $applicantData json_decode($applicant->getData(), true512\JSON_THROW_ON_ERROR);
  265.         } catch (\JsonException) {
  266.             return $recruiter;
  267.         }
  268.         if (!$recruiter && !empty($applicantData['company'])) {
  269.             /** @var Company $company */
  270.             $company $this->entityManager->getRepository(Company::class)->find($applicantData['company']);
  271.             if ($company && !$company->getRecruiters()->isEmpty()) {
  272.                 $recruiter $company->getRecruiters()->first();
  273.             }
  274.         }
  275.         return $recruiter;
  276.     }
  277.     /**
  278.      * Generate URL for successful application with either external or CMS id.
  279.      */
  280.     public function generateSuccessRedirect(Applicant $applicant, ?Vacancy $vacancy null): RedirectResponse
  281.     {
  282.         return new RedirectResponse(
  283.             $this->generateSuccessRedirectUrl($applicant$vacancy)
  284.         );
  285.     }
  286.     public function generateSuccessRedirectUrl(Applicant $applicant, ?Vacancy $vacancy null): string
  287.     {
  288.         $parameters = [];
  289.         if ($vacancy) {
  290.             $vacancyIdForDatalayer $vacancy->getId();
  291.             if (
  292.                 $this->config->get('site_google_show_external_vacancy_id') &&
  293.                 !empty($vacancy->getExternalId())
  294.             ) {
  295.                 $vacancyIdForDatalayer $vacancy->getExternalId();
  296.             }
  297.             $parameters['id'] = $vacancyIdForDatalayer;
  298.         }
  299.         $applicantIdForDatalayer $this->config->get('site_google_show_external_applicant_id') ?
  300.             $applicant->getExternalId() : $applicant->getId();
  301.         $parameters[$this->config->get('site_google_applicant_query_name')] = $applicantIdForDatalayer;
  302.         return $this->router->generate('vacancy_apply_thanks'$parameters);
  303.     }
  304.     /**
  305.      * @throws LoaderError
  306.      * @throws RuntimeError
  307.      * @throws SyntaxError
  308.      */
  309.     public function renderECommerceScript(Request $request, ?Vacancy $vacancy): string
  310.     {
  311.         if (!$this->config->get('site_google_applicant_query_name') ||
  312.             !$request->query->has($this->config->get('site_google_applicant_query_name'))) {
  313.             // applicant query name was either not set or provided value is not available in request
  314.             return '';
  315.         }
  316.         $category null;
  317.         if ($vacancy) {
  318.             $optionValues $vacancy->getOptionValues();
  319.             $categoryOption $this->stringToEntityUtil
  320.                 ->stringToEntity($this->config->get('site_google_category_option'));
  321.             if (!empty($categoryOption)) {
  322.                 $optionValues $optionValues->filter(
  323.                     function (OptionValue $optionValue) use ($categoryOption) {
  324.                         return $optionValue->getOption() && $optionValue->getOption()->getId() === $categoryOption->getId();
  325.                     }
  326.                 );
  327.             }
  328.             $category $optionValues->first();
  329.         }
  330.         return $this->twig->render('scripts/external_e_commerce_script.html.twig', [
  331.             'applicant_id' => $request->query->get($this->config->get('site_google_applicant_query_name')),
  332.             'vacancy_id' => $vacancy $vacancy->getId() : 'OPEN_SOLLICITATIE',
  333.             'vacancy_title' => $vacancy $vacancy->getTitle() : 'Open sollicitatie',
  334.             'brand_name' => $vacancy && $vacancy->getCompany() ? $vacancy->getCompany()->getName() : '',
  335.             'category' => $category,
  336.         ]);
  337.     }
  338.     /**
  339.      * @throws LoaderError
  340.      * @throws RuntimeError
  341.      * @throws SyntaxError
  342.      */
  343.     public function renderHeadEndScriptForVacancyDetail(?Vacancy $vacancy): string
  344.     {
  345.         if (!$vacancy) {
  346.             return '';
  347.         }
  348.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_INGOEDEBANEN_ADVANCED_STATISTICS)) {
  349.             return $this->twig->render('scripts/ingoedebanen_application_end_script.html.twig', [
  350.                 'vacancy' => $vacancy,
  351.             ]);
  352.         }
  353.         return '';
  354.     }
  355.     /**
  356.      * @throws LoaderError
  357.      * @throws RuntimeError
  358.      * @throws SyntaxError
  359.      */
  360.     public function renderBodyEndScriptForVacancyDetail(): string
  361.     {
  362.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_INGOEDEBANEN_ADVANCED_STATISTICS)) {
  363.             return $this->twig->render('scripts/ingoedebanen_start_script.html.twig');
  364.         }
  365.         return '';
  366.     }
  367.     public function getDataTable(Request $request, array $query = []): DataTable
  368.     {
  369.         $email $query['email'] ?? null;
  370.         if (ApplicantTableType::class === $this->config->get('admin_applicant_table_type')) {
  371.             return $this->getArrayDataTable($request$query);
  372.         }
  373.         return $this->getORMDataTable($request$email);
  374.     }
  375.     private function getArrayDataTable(Request $request, array $query = []): DataTable
  376.     {
  377.         $criteria Criteria::create();
  378.         foreach ($query as $field => $value) {
  379.             $criteria->andWhere(Criteria::expr()->eq($field$value));
  380.         }
  381.         $applicants $this->entityManager->getRepository(Applicant::class)
  382.             ->findApplicants($criteria, ['id' => $this->config->get('site_applicant_order_dir')]);
  383.         $applicantFilters $this->adminFilterUtil->getApplicantFilters();
  384.         $applicants array_filter($applicants, function (Applicant $applicant) use ($applicantFilters) {
  385.             if (
  386.                 !empty($applicantFilters['applicantCompany']) &&
  387.                 !$this->validateCompanyOfApplicant($applicant$applicantFilters['applicantCompany'])
  388.             ) {
  389.                 return false;
  390.             }
  391.             if (\in_array(ApplicantFilterType::SHOW_DELETED_APPLICANTS$applicantFilters['filters'], true) && null !== $applicant->getDeletedAt() && $this->authorizationChecker->isGranted('view'$applicant)) {
  392.                 return true;
  393.             }
  394.             if (!$applicant->getVacancy()) {
  395.                 return \in_array(ApplicantFilterType::SHOW_OPEN_APPLICANTS$applicantFilters['filters'], true)
  396.                     && $this->authorizationChecker->isGranted('view'$applicant)
  397.                     && (
  398.                         null === $applicant->getDeletedAt()
  399.                         || \in_array(ApplicantFilterType::SHOW_DELETED_APPLICANTS$applicantFilters['filters'], true)
  400.                     );
  401.             }
  402.             if (\in_array(ApplicantFilterType::SHOW_REGULAR_APPLICANTS$applicantFilters['filters'], true) && $this->authorizationChecker->isGranted('view'$applicant)) {
  403.                 return !(null !== $applicant->getDeletedAt() && !\in_array(ApplicantFilterType::SHOW_DELETED_APPLICANTS$applicantFilters['filters'], true));
  404.             }
  405.             return false;
  406.         });
  407.         $statusApplicantIdPairs = [];
  408.         $applicantStatusses = [];
  409.         if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_ATS)) {
  410.             $applicantStatusses $this->entityManager->getRepository(ApplicantStatus::class)->findAll();
  411.             $statusApplicantIdPairs $this->entityManager->getRepository(ApplicantStatus::class)->findAllIdStatusPairs($this->adminFilterUtil->getApplicantFilters());
  412.             $statusApplicantIdPairs array_column($statusApplicantIdPairs'title''id');
  413.         }
  414.         $applicantRepo $this->entityManager->getRepository(Applicant::class);
  415.         $applicantsCount $applicantRepo->findApplicationCountsPerEmail();
  416.         $dataTableData array_map(function (Applicant $applicant) use ($applicantStatusses$statusApplicantIdPairs$applicantsCount) {
  417.             $applicationCount 0;
  418.             if ($applicant->getEmail()) {
  419.                 $applicationCount $applicantsCount[$applicant->getEmail()] ?? 0;
  420.             }
  421.             $status $applicant->getStatus() ? $applicant->getStatus()->getTitle() : null;
  422.             if (!empty($statusApplicantIdPairs[$applicant->getId()])) {
  423.                 $status $statusApplicantIdPairs[$applicant->getId()];
  424.             }
  425.             $applicantData = [
  426.                 'applicant' => $applicant,
  427.                 'id' => $applicant->getId(),
  428.                 'externalId' => $applicant->getExternalId(),
  429.                 'externalCandidateId' => $applicant->getExternalCandidateId(),
  430.                 'displayableExternalId' => $applicant->getVacancy() ? $applicant->getVacancy()->getDisplayableExternalId() : null,
  431.                 'name' => $applicant->getFullName(),
  432.                 'status' => $status,
  433.                 'email' => $applicant->getEmail(),
  434.                 'phone' => $applicant->getPhone(),
  435.                 'vacancyTitle' => $applicant->getVacancy() ? $applicant->getVacancy()->getTitle() : null,
  436.                 'vacancyDomain' => $applicant->getVacancy() && $applicant->getVacancy()->getDomain() ? $applicant->getVacancy()->getDomain()->getName() : null,
  437.                 'companyName' => $applicant->getVacancy() && $applicant->getVacancy()->getCompany() ?
  438.                     $applicant->getVacancy()->getCompany()->getName() : null,
  439.                 'appliedOn' => $applicant->getCreatedAt(),
  440.                 'applicantStatusses' => $applicantStatusses,
  441.                 'deleted' => null !== $applicant->getDeletedAt(),
  442.                 'logs' => [], // $logManager->getLastObjectTransactionLog($applicant),
  443.                 'applicationCount' => $applicationCount,
  444.             ];
  445.             if ($this->featureManager->isActive(FeatureFlagListener::FEATURE_VACANCY_KNOCKOUT_QUESTIONS)) {
  446.                 $applicantData['rejected'] = $applicant->isRejectedByKnockout() ? 'Yes' 'No';
  447.             }
  448.             return $applicantData;
  449.         }, $applicants);
  450.         return $this->dataTableFactory->createFromType(ApplicantTableType::class, ['data' => $dataTableData])
  451.             ->handleRequest($request);
  452.     }
  453.     private function validateCompanyOfApplicant(Applicant $applicantint $companyIdToCheck): bool
  454.     {
  455.         if (!$applicant->getVacancy()) {
  456.             return false;
  457.         }
  458.         if (!$applicant->getVacancy()->getCompany()) {
  459.             return false;
  460.         }
  461.         return $applicant->getVacancy()->getCompany()->getId() === $companyIdToCheck;
  462.     }
  463.     private function getORMDataTable(Request $request, ?string $email null): DataTable
  464.     {
  465.         return $this->dataTableFactory->createFromType(
  466.             ORMApplicantTableType::class,
  467.             [
  468.             'email' => $email,
  469.             'filters' => $this->adminFilterUtil->getApplicantFilters(),
  470.             'order_by' => $this->config->get('site_applicant_order_dir'),
  471.         ]
  472.         )->handleRequest($request);
  473.     }
  474.     public function getSuccessMultiMedia(?Vacancy $vacancy null, ?string $locale null): ?MultiMedia
  475.     {
  476.         $defaultMultimedia $this->config->get('applicant_success_multimedia_fallback');
  477.         if (!$vacancy) {
  478.             return $defaultMultimedia;
  479.         }
  480.         switch ($this->config->get('applicant_success_multimedia_strategy')) {
  481.             case ApplicantSettingType::MULTIMEDIA_STRATEGY_CHOICE_FALLBACK:
  482.             default:
  483.                 return $defaultMultimedia;
  484.             case ApplicantSettingType::MULTIMEDIA_STRATEGY_CHOICE_OPTION:
  485.                 if (
  486.                     !$selectedOption $this->config->get('applicant_success_multimedia_option')
  487.                 ) {
  488.                     return $defaultMultimedia;
  489.                 }
  490.                 if (!$selectedSection $this->config->get('applicant_success_multimedia_option_section')) {
  491.                     $selectedSection 'featured';
  492.                 }
  493.                 $optionValues array_filter(
  494.                     $vacancy->getOptionValues()?->toArray(),
  495.                     static fn (OptionValue $optionValue) => $optionValue->getOption()?->getId() === $selectedOption->getId()
  496.                 );
  497.                 foreach ($optionValues as $optionValue) {
  498.                     if ('featured' === $selectedSection) {
  499.                         if ($multimedia $this->multiMediaManager->getFeaturedMultiMediaByEntity($optionValue$locale)) {
  500.                             return $multimedia;
  501.                         }
  502.                         continue;
  503.                     }
  504.                     if ($multimedia $this->multiMediaManager->getMultiMediaByEntity($optionValue$selectedSection$locale)) {
  505.                         return reset($multimedia);
  506.                     }
  507.                 }
  508.                 return $defaultMultimedia;
  509.             case ApplicantSettingType::MULTIMEDIA_STRATEGY_CHOICE_COMPANY:
  510.                 if (!$company $vacancy->getCompany()) {
  511.                     return $defaultMultimedia;
  512.                 }
  513.                 if (!$selectedSection $this->config->get('applicant_success_multimedia_company_section')) {
  514.                     $selectedSection 'featured';
  515.                 }
  516.                 if ('featured' === $selectedSection && $multimedia $this->multiMediaManager->getFeaturedMultiMediaByEntity($company$locale)) {
  517.                     return $multimedia;
  518.                 }
  519.                 if ($multimedia $this->multiMediaManager->getMultiMediaByEntity($company$selectedSection$locale)) {
  520.                     return reset($multimedia);
  521.                 }
  522.                 return $defaultMultimedia;
  523.         }
  524.     }
  525. }