feat: rework automatic job profile assignment
This commit is contained in:
@@ -118,4 +118,37 @@ class JobProfile implements BlameableEntityInterface, TimestampableEntityInterfa
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isQualified(Teamer $teamer): bool
|
||||
{
|
||||
// Check licenses
|
||||
$qualifiedByLicenses = true;
|
||||
if (0 < $this->requiredTrainings->count()) {
|
||||
$teamerLicenseTypes = $teamer->getLicenses()->map(function (License $license) {
|
||||
return $license->getType();
|
||||
})->toArray();
|
||||
|
||||
foreach ($this->requiredLicenses as $requiredLicense) {
|
||||
if (false === in_array($requiredLicense, $teamerLicenseTypes)) {
|
||||
$qualifiedByLicenses = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check trainings
|
||||
$qualifiedByTrainings = true;
|
||||
if (0 < $this->requiredTrainings->count()) {
|
||||
$teamerTrainings = $teamer->getTrainingAttendances()->map(function (TrainingAttendance $trainingAttendance) {
|
||||
return $trainingAttendance->getTraining();
|
||||
});
|
||||
|
||||
foreach ($this->requiredTrainings as $requiredTraining) {
|
||||
if (false === $teamerTrainings->contains($requiredTraining)) {
|
||||
$qualifiedByTrainings = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $qualifiedByLicenses && $qualifiedByTrainings;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user