<?php
namespace App\DTO\JobCandidate;
use App\Constant\Common;
use AutoMapperPlus\AutoMapperPlusBundle\AutoMapperConfiguratorInterface;
use AutoMapperPlus\Configuration\AutoMapperConfigInterface;
use App\Service\BaseService;
use Symfony\Contracts\Translation\TranslatorInterface;
class JobCandidateMapper extends BaseService implements AutoMapperConfiguratorInterface
{
public function configure(AutoMapperConfigInterface $config): void
{
$mapping = $config->registerMapping('App\Entity\JobCandidate', 'App\DTO\JobCandidate\JobCandidateOutput')
->forMember('status', function (\App\Entity\JobCandidate $jobCandidate) {
$status = $jobCandidate->getStatus();
if (!$status) return null;
return array_values(array_filter($this->jobCandidateService->listStatusCandidate(), function ($item) use ($status) {
return $item['id'] == $status;
}))[0];
})
->forMember('studyLevel', function (\App\Entity\JobCandidate $jobCandidate) {
$studyLevel = $jobCandidate->getStudyLevel();
if (!$studyLevel) return null;
return [
'id' => $studyLevel->getId(),
'name' => $studyLevel->getName()
];
})
->forMember('offer', function (\App\Entity\JobCandidate $jobCandidate) {
$offer = $jobCandidate->getOffer();
if (!$offer) return null;
return [
'id' => $offer->getId(),
'code' => $offer->getCode(),
'offerTitle' => $offer->getOfferTitle(),
'companyName' => $offer->getCompanyName(),
'offerType' => $offer->getOfferType(),
'contractName' => $offer->getContract()->getNameDisplay()
];
})
->forMember('gender', function (\App\Entity\JobCandidate $jobCandidate) {
return $jobCandidate->getGender() ? 1 : 0;
})
->forMember('fileCvUrl', function (\App\Entity\JobCandidate $offer) {
if (!$offer->getFileCv()) return null;
return $this->uploadsStorage->publicUrl($offer->getFileCv());
})
->forMember('fileCoverUrl', function (\App\Entity\JobCandidate $offer) {
if (!$offer->getFileCover()) return null;
return $this->uploadsStorage->publicUrl($offer->getFileCover());
});
$config->registerMapping('App\Entity\JobCandidate', 'App\DTO\JobCandidate\JobCandidateOutputEmail')
->copyFromMapping($mapping);
}
}