feat: automatic assignment of matching job profiles when adding license

This commit is contained in:
Björn Fromme
2024-07-09 15:09:12 +02:00
parent de5117c200
commit 2ff4b7d007
2 changed files with 33 additions and 0 deletions
@@ -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);
+13
View File
@@ -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()
;
}
}