feat: automatic assignment of matching job profiles when adding license
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Controller\Teamer\Profile\License;
|
||||
|
||||
use App\Entity\JobProfile;
|
||||
use App\Entity\License;
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\LicenseType;
|
||||
@@ -47,6 +49,7 @@ class AddController extends AbstractController
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
$teamer->addLicense($license);
|
||||
$this->assignJobProfiles($license, $teamer);
|
||||
|
||||
$this->entityManager->persist($license);
|
||||
$this->entityManager->flush();
|
||||
@@ -66,6 +69,23 @@ class AddController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function assignJobProfiles(License $license, Teamer $teamer): void
|
||||
{
|
||||
if (false === in_array($license->getType(), [License::TYPE_SKI, License::TYPE_SNOWBOARD])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$matchingJobProfiles = $this
|
||||
->entityManager
|
||||
->getRepository(JobProfile::class)
|
||||
->findByLicenseType($license->getType())
|
||||
;
|
||||
|
||||
foreach ($matchingJobProfiles as $matchingJobProfile) {
|
||||
$teamer->addJobProfile($matchingJobProfile);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateCertificate(User $user, License $license, UploadSessionDto $uploadSession): void
|
||||
{
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_CERTIFICATE);
|
||||
|
||||
@@ -34,4 +34,17 @@ class JobProfileRepository extends ServiceEntityRepository
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findByLicenseType(string $licenseType): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('job_profile');
|
||||
|
||||
return $qb
|
||||
->where($qb->expr()->like('job_profile.requiredLicenses', ':licenseType'))
|
||||
->orderBy('job_profile.name', 'ASC')
|
||||
->setParameter('licenseType', '%'.$licenseType.'%')
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user