228 lines
6.4 KiB
PHP
228 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Entity\Traits\BlameableEntity;
|
|
use App\Entity\Traits\SoftDeletableEntity;
|
|
use App\Entity\Traits\TimestampableEntity;
|
|
use App\Repository\JobProfileRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[ORM\Entity(repositoryClass: JobProfileRepository::class)]
|
|
class JobProfile implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
|
|
{
|
|
use BlameableEntity;
|
|
use TimestampableEntity;
|
|
use SoftDeletableEntity;
|
|
|
|
public const CATEGORY_GUIDE = 'guide';
|
|
public const CATEGORY_COURSE_SKI = 'course_ski';
|
|
public const CATEGORY_COURSE_SKI_BEGINNER = 'course_ski_beginner';
|
|
public const CATEGORY_COURSE_SKI_ADVANCED = 'course_ski_advanced';
|
|
public const CATEGORY_COURSE_BOARD = 'course_board';
|
|
public const CATEGORY_COURSE_BOARD_BEGINNER = 'course_board_beginner';
|
|
public const CATEGORY_COURSE_BOARD_ADVANCED = 'course_board_advanced';
|
|
public const CATEGORY_SERVICE = 'service';
|
|
public const CATEGORY_EVENT_TEAM = 'event_team';
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function getCategories(): array
|
|
{
|
|
return [
|
|
self::CATEGORY_GUIDE => 'Reiseleitung',
|
|
self::CATEGORY_COURSE_SKI => 'Kursleitung Ski',
|
|
self::CATEGORY_COURSE_SKI_BEGINNER => 'Kursleitung Ski Anfänger:innen',
|
|
self::CATEGORY_COURSE_SKI_ADVANCED => 'Kursleitung Ski fortgeschritten',
|
|
self::CATEGORY_COURSE_BOARD => 'Kursleitung Board',
|
|
self::CATEGORY_COURSE_BOARD_BEGINNER => 'Kursleitung Board Anfänger:innen',
|
|
self::CATEGORY_COURSE_BOARD_ADVANCED => 'Kursleitung Board fortgeschritten',
|
|
self::CATEGORY_SERVICE => 'Serviceteamer:in',
|
|
self::CATEGORY_EVENT_TEAM => 'Eventteamer:in',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
public static function getCategoryValues(): array
|
|
{
|
|
return array_keys(self::getCategories());
|
|
}
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Assert\NotBlank(message: 'Bitte gib die Bezeichnung an')]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
#[Assert\NotBlank(message: 'Bitte wähle die Kategorie')]
|
|
#[Assert\Choice(callback: [self::class, 'getCategoryValues'], message: 'Die Kategorie ist ungültig')]
|
|
private ?string $category = null;
|
|
|
|
#[ORM\Column(type: Types::JSON)]
|
|
private array $requiredLicenses = [];
|
|
|
|
#[ORM\ManyToMany(targetEntity: Training::class)]
|
|
private Collection $requiredTrainings;
|
|
|
|
#[ORM\ManyToOne]
|
|
#[ORM\JoinColumn(onDelete: 'SET NULL')]
|
|
#[Assert\NotNull(message: 'Bitte ordne eine Feedback-Vorlage zu')]
|
|
private ?FeedbackSet $feedbackSet = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?string $costUnit = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->uuid = Uuid::v4();
|
|
$this->requiredTrainings = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUuid(): string
|
|
{
|
|
return $this->uuid;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCategory(): ?string
|
|
{
|
|
return $this->category;
|
|
}
|
|
|
|
public function setCategory(?string $category): static
|
|
{
|
|
$this->category = $category;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCategoryLabel(): ?string
|
|
{
|
|
return self::getCategories()[$this->category] ?? null;
|
|
}
|
|
|
|
public function getRequiredLicenses(): array
|
|
{
|
|
return $this->requiredLicenses;
|
|
}
|
|
|
|
public function setRequiredLicenses(array $requiredLicenses): static
|
|
{
|
|
$this->requiredLicenses = $requiredLicenses;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Training>
|
|
*/
|
|
public function getRequiredTrainings(): Collection
|
|
{
|
|
return $this->requiredTrainings;
|
|
}
|
|
|
|
public function addRequiredTraining(Training $requiredTraining): static
|
|
{
|
|
if (!$this->requiredTrainings->contains($requiredTraining)) {
|
|
$this->requiredTrainings->add($requiredTraining);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeRequiredTraining(Training $requiredTraining): static
|
|
{
|
|
$this->requiredTrainings->removeElement($requiredTraining);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getFeedbackSet(): ?FeedbackSet
|
|
{
|
|
return $this->feedbackSet;
|
|
}
|
|
|
|
public function setFeedbackSet(?FeedbackSet $feedbackSet): static
|
|
{
|
|
$this->feedbackSet = $feedbackSet;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCostUnit(): ?string
|
|
{
|
|
return $this->costUnit;
|
|
}
|
|
|
|
public function setCostUnit(?string $costUnit): static
|
|
{
|
|
$this->costUnit = $costUnit;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isQualified(Teamer $teamer): bool
|
|
{
|
|
// Check licenses
|
|
$qualifiedByLicenses = true;
|
|
if (0 < count($this->requiredLicenses)) {
|
|
$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;
|
|
}
|
|
}
|