*/ 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 */ 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 */ 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; } }