feat: rework automatic job profile assignment
This commit is contained in:
@@ -2,11 +2,10 @@
|
||||
|
||||
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\Event\LicenseAddedEvent;
|
||||
use App\Form\LicenseType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Model\UploadSessionDto;
|
||||
@@ -18,12 +17,14 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class AddController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
@@ -49,11 +50,12 @@ class AddController extends AbstractController
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
$teamer->addLicense($license);
|
||||
$this->assignJobProfiles($license, $teamer);
|
||||
|
||||
$this->entityManager->persist($license);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->eventDispatcher->dispatch(new LicenseAddedEvent($license), LicenseAddedEvent::NAME);
|
||||
|
||||
$this->addFlash('success', 'Die Lizenz wurde hinzugefügt.');
|
||||
$this->logger->info('Add license', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
@@ -69,23 +71,6 @@ 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);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Controller\Teamer\Profile\License;
|
||||
|
||||
use App\Entity\License;
|
||||
use App\Event\LicenseDeletedEvent;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -11,11 +12,13 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
@@ -30,6 +33,8 @@ class DeleteController extends AbstractController
|
||||
$this->entityManager->remove($license);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->eventDispatcher->dispatch(new LicenseDeletedEvent($license), LicenseDeletedEvent::NAME);
|
||||
|
||||
$this->addFlash('success', 'Die Lizenz wurde gelöscht.');
|
||||
$this->logger->info('Delete license', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Controller\Teamer\Profile;
|
||||
|
||||
use App\Entity\JobProfile;
|
||||
use App\Entity\User;
|
||||
use App\Form\TeamerJobProfileType;
|
||||
use App\Repository\JobProfileRepository;
|
||||
@@ -35,28 +34,7 @@ class SkillsController extends AbstractController
|
||||
$selectableJobProfiles = [];
|
||||
|
||||
foreach ($jobProfiles as $profile) {
|
||||
/** @var JobProfile $profile */
|
||||
$requiredTrainingsSatisfied = false;
|
||||
if (0 === $profile->getRequiredTrainings()->count()) {
|
||||
$requiredTrainingsSatisfied = true;
|
||||
}
|
||||
foreach ($profile->getRequiredTrainings() as $training) {
|
||||
if (null !== $teamer->getTrainingAttendance($training)) {
|
||||
$requiredTrainingsSatisfied = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$requiredLicensesSatisfied = false;
|
||||
if (0 === count($profile->getRequiredLicenses())) {
|
||||
$requiredLicensesSatisfied = true;
|
||||
}
|
||||
foreach ($profile->getRequiredLicenses() as $license) {
|
||||
if (null !== $teamer->getLicenseOfType($license)) {
|
||||
$requiredLicensesSatisfied = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$selectableJobProfiles[$profile->getId()] = $requiredTrainingsSatisfied && $requiredLicensesSatisfied;
|
||||
$selectableJobProfiles[$profile->getId()] = $profile->isQualified($teamer);
|
||||
}
|
||||
|
||||
$form = $this->createForm(TeamerJobProfileType::class, $teamer, [
|
||||
|
||||
Reference in New Issue
Block a user