src/DTO/JobCandidate/JobCandidateMapper.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\DTO\JobCandidate;
  3. use App\Constant\Common;
  4. use AutoMapperPlus\AutoMapperPlusBundle\AutoMapperConfiguratorInterface;
  5. use AutoMapperPlus\Configuration\AutoMapperConfigInterface;
  6. use App\Service\BaseService;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. class JobCandidateMapper extends BaseService implements AutoMapperConfiguratorInterface
  9. {
  10.     public function configure(AutoMapperConfigInterface $config): void
  11.     {
  12.         $mapping = $config->registerMapping('App\Entity\JobCandidate', 'App\DTO\JobCandidate\JobCandidateOutput')
  13.             ->forMember('status', function (\App\Entity\JobCandidate $jobCandidate) {
  14.                 $status = $jobCandidate->getStatus();
  15.                 if (!$status) return null;
  16.                 return array_values(array_filter($this->jobCandidateService->listStatusCandidate(), function ($item) use ($status) {
  17.                     return $item['id'] == $status;
  18.                 }))[0];
  19.             })
  20.             ->forMember('studyLevel', function (\App\Entity\JobCandidate $jobCandidate) {
  21.                 $studyLevel = $jobCandidate->getStudyLevel();
  22.                 if (!$studyLevel) return null;
  23.                 return  [
  24.                     'id'   => $studyLevel->getId(),
  25.                     'name' => $studyLevel->getName()
  26.                 ];
  27.             })
  28.             ->forMember('offer', function (\App\Entity\JobCandidate $jobCandidate) {
  29.                 $offer = $jobCandidate->getOffer();
  30.                 if (!$offer) return null;
  31.                 return  [
  32.                     'id'          => $offer->getId(),
  33.                     'code'        => $offer->getCode(),
  34.                     'offerTitle'  => $offer->getOfferTitle(),
  35.                     'companyName' => $offer->getCompanyName(),
  36.                     'offerType'   => $offer->getOfferType(),
  37.                     'contractName' => $offer->getContract()->getNameDisplay()
  38.                 ];
  39.             })
  40.             ->forMember('gender', function (\App\Entity\JobCandidate $jobCandidate) {
  41.                 return $jobCandidate->getGender() ? 1 : 0;
  42.             })
  43.             ->forMember('fileCvUrl', function (\App\Entity\JobCandidate $offer) {
  44.                 if (!$offer->getFileCv()) return null;
  45.                 return $this->uploadsStorage->publicUrl($offer->getFileCv());
  46.             })
  47.             ->forMember('fileCoverUrl', function (\App\Entity\JobCandidate $offer) {
  48.                 if (!$offer->getFileCover()) return null;
  49.                 return $this->uploadsStorage->publicUrl($offer->getFileCover());
  50.             });
  51.         $config->registerMapping('App\Entity\JobCandidate', 'App\DTO\JobCandidate\JobCandidateOutputEmail')
  52.             ->copyFromMapping($mapping);
  53.     }
  54. }