<?php
namespace App\Entity;
use App\Repository\TraineeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TraineeRepository::class)]
class Trainee extends User
{
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $birthDate = null;
#[ORM\Column(type: 'string', length: 255)]
private $country;
#[ORM\OneToMany(targetEntity: SportTrainee::class, mappedBy: 'trainee')]
private $sports;
#[ORM\OneToMany(targetEntity: Alert::class, mappedBy: 'trainee')]
private $alerts;
#[ORM\ManyToMany(targetEntity: Course::class, inversedBy: 'traineesFavorites')]
private $favorites;
#[ORM\OneToMany(targetEntity: Booking::class, mappedBy: 'trainee')]
private $bookings;
#[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'traineesFavorites')]
private $proFavorites;
#[ORM\OneToMany(mappedBy: 'trainee', targetEntity: Note::class)]
private Collection $notes;
public function __construct()
{
parent::__construct();
$this->sports = new ArrayCollection();
$this->alerts = new ArrayCollection();
$this->favorites = new ArrayCollection();
$this->bookings = new ArrayCollection();
$this->proFavorites = new ArrayCollection();
$this->notes = new ArrayCollection();
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeInterface $birthDate): static
{
$this->birthDate = $birthDate;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
/**
* @return Collection|SportTrainee[]
*/
public function getSports(): Collection
{
return $this->sports;
}
public function addSport(SportTrainee $sport): self
{
if (!$this->sports->contains($sport)) {
$this->sports[] = $sport;
$sport->setTrainee($this);
}
return $this;
}
public function removeSport(SportTrainee $sport): self
{
if ($this->sports->removeElement($sport)) {
// set the owning side to null (unless already changed)
if ($sport->getTrainee() === $this) {
$sport->setTrainee(null);
}
}
return $this;
}
/**
* @return Collection|Alert[]
*/
public function getAlerts(): Collection
{
return $this->alerts;
}
public function addAlert(Alert $alert): self
{
if (!$this->alerts->contains($alert)) {
$this->alerts[] = $alert;
$alert->setTrainee($this);
}
return $this;
}
public function removeAlert(Alert $alert): self
{
if ($this->alerts->removeElement($alert)) {
// set the owning side to null (unless already changed)
if ($alert->getTrainee() === $this) {
$alert->setTrainee(null);
}
}
return $this;
}
/**
* @return Collection|Course[]
*/
public function getFavorites(): Collection
{
return $this->favorites;
}
public function addFavorite(Course $favorite): self
{
if (!$this->favorites->contains($favorite)) {
$this->favorites[] = $favorite;
}
return $this;
}
public function removeFavorite(Course $favorite): self
{
$this->favorites->removeElement($favorite);
return $this;
}
// Check course favorite
public function isCourseFavorite(Course $course)
{
if($course->getTraineesFavorites()->contains($this))
{
return true;
}
}
/**
* @return Collection|Booking[]
*/
public function getBookings(): Collection
{
return $this->bookings;
}
public function addBooking(Booking $booking): self
{
if (!$this->bookings->contains($booking)) {
$this->bookings[] = $booking;
$booking->setTrainee($this);
}
return $this;
}
public function removeBooking(Booking $booking): self
{
if ($this->bookings->removeElement($booking)) {
// set the owning side to null (unless already changed)
if ($booking->getTrainee() === $this) {
$booking->setTrainee(null);
}
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getProFavorites(): Collection
{
return $this->proFavorites;
}
public function addProFavorite(User $proFavorite): self
{
if (!$this->proFavorites->contains($proFavorite)) {
$this->proFavorites[] = $proFavorite;
}
return $this;
}
public function removeProFavorite(User $proFavorite): self
{
$this->proFavorites->removeElement($proFavorite);
return $this;
}
// Check pro favorite
public function isProFavorite(User $user)
{
if($user->getTraineesFavorites()->contains($this))
{
return true;
}
}
/**
* @return Collection<int, Note>
*/
public function getNotes(): Collection
{
return $this->notes;
}
public function addNote(Note $note): static
{
if (!$this->notes->contains($note)) {
$this->notes->add($note);
$note->setTrainee($this);
}
return $this;
}
public function removeNote(Note $note): static
{
if ($this->notes->removeElement($note)) {
// set the owning side to null (unless already changed)
if ($note->getTrainee() === $this) {
$note->setTrainee(null);
}
}
return $this;
}
}