<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Assert\Email(
message: 'Die E-Mail {{ value }} ist keine gültige E-Mail.',
)]
#[ORM\Column(type: 'string', length: 180, unique: true, nullable: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string', nullable: true)]
private $password;
#[ORM\Column(type: 'string', length: 255)]
private $firstName;
#[ORM\Column(type: 'string', length: 255)]
private $lastName;
#[ORM\Column(type: 'string', length: 255)]
private $street;
#[ORM\Column(type: 'integer')]
private $postCode;
#[ORM\Column(type: 'string', length: 255)]
private $city;
#[ORM\Column(type: 'string', length: 255)]
private $country;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $phoneNumber;
#[ORM\Column(type: 'integer')]
private $gender;
#[ORM\Column(type: 'date')]
private $birthDate;
#[ORM\Column(type: 'string', length: 22, nullable: true)]
private $iban;
#[ORM\Column(type: 'string', length: 11, nullable: true)]
private $bic;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $bank;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $accountOwner;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: SkiUser::class)]
private $SkiClubUser;
#[ORM\Column(type: 'integer', nullable: true)]
private $skiClubId;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Booking::class)]
private $booking;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: BookingUser::class)]
private $bookingUser;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: SendMessages::class)]
private $sendMessage;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subUser')]
private $MainUser;
#[ORM\OneToMany(mappedBy: 'MainUser', targetEntity: self::class)]
private $subUser;
#[ORM\OneToMany(mappedBy: 'supervisor', targetEntity: Trip::class)]
private $supervisor;
#[ORM\OneToMany(mappedBy: 'recreationLeader', targetEntity: Trip::class)]
private $recreationLeader;
#[ORM\ManyToMany(targetEntity: Trip::class, inversedBy: 'users')]
private $SupervisorTrip;
public function __construct()
{
$this->SkiClubUser = new ArrayCollection();
$this->booking = new ArrayCollection();
$this->bookingUser = new ArrayCollection();
$this->sendMessage = new ArrayCollection();
$this->subUser = new ArrayCollection();
$this->supervisor = new ArrayCollection();
$this->recreationLeader = new ArrayCollection();
$this->SupervisorTrip = new ArrayCollection();
}
public function __toString()
{
return $this->getFirstName() . ' ' . $this->getLastName();
}
public function nameString()
{
return $this->getFirstName() . ' ' . $this->getLastName();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @see UserInterface
*/
public function getHighestRole(): string
{
// jeder Nutzer kann nur eine Rolle haben daher [0]
return $this->getRoles()[0];
}
/**
* @see UserInterface
*/
public function getHighestRoleName(): string
{
if ($this->getHighestRole() == 'ROLE_USER') {
return 'Standardnutzer';
}
return ucfirst(strtolower(substr($this->getHighestRole(), 5)));
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(string $street): self
{
$this->street = $street;
return $this;
}
public function getPostCode(): ?int
{
return $this->postCode;
}
public function setPostCode(int $postCode): self
{
$this->postCode = $postCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getGender(): ?int
{
return $this->gender;
}
public function setGender(int $gender): self
{
$this->gender = $gender;
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(\DateTimeInterface $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
public function getIban(): ?string
{
return $this->iban;
}
public function setIban(string $iban): self
{
$this->iban = $iban;
return $this;
}
public function getBic(): ?string
{
return $this->bic;
}
public function setBic(?string $bic): self
{
$this->bic = $bic;
return $this;
}
public function getBank(): ?string
{
return $this->bank;
}
public function setBank(string $bank): self
{
$this->bank = $bank;
return $this;
}
public function getAccountOwner(): ?string
{
return $this->accountOwner;
}
public function setAccountOwner(string $accountOwner): self
{
$this->accountOwner = $accountOwner;
return $this;
}
/**
* @return Collection<int, SkiUser>
*/
public function getSkiClubUser(): Collection
{
return $this->SkiClubUser;
}
public function addSkiClubUser(SkiUser $skiClubUser): self
{
if (!$this->SkiClubUser->contains($skiClubUser)) {
$this->SkiClubUser[] = $skiClubUser;
$skiClubUser->setUser($this);
}
return $this;
}
public function removeSkiClubUser(SkiUser $skiClubUser): self
{
if ($this->SkiClubUser->removeElement($skiClubUser)) {
// set the owning side to null (unless already changed)
if ($skiClubUser->getUser() === $this) {
$skiClubUser->setUser(null);
}
}
return $this;
}
public function getSkiClubId(): ?int
{
return $this->skiClubId;
}
public function setSkiClubId(?int $skiClubId): self
{
$this->skiClubId = $skiClubId;
return $this;
}
public function getIsVerified(): ?bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection<int, Booking>
*/
public function getBooking(): Collection
{
return $this->booking;
}
public function addBooking(Booking $booking): self
{
if (!$this->booking->contains($booking)) {
$this->booking[] = $booking;
$booking->setUser($this);
}
return $this;
}
public function removeBooking(Booking $booking): self
{
if ($this->booking->removeElement($booking)) {
// set the owning side to null (unless already changed)
if ($booking->getUser() === $this) {
$booking->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, BookingUser>
*/
public function getBookingUser(): Collection
{
return $this->bookingUser;
}
public function addBookingUser(BookingUser $bookingUser): self
{
if (!$this->bookingUser->contains($bookingUser)) {
$this->bookingUser[] = $bookingUser;
$bookingUser->setUser($this);
}
return $this;
}
public function removeBookingUser(BookingUser $bookingUser): self
{
if ($this->bookingUser->removeElement($bookingUser)) {
// set the owning side to null (unless already changed)
if ($bookingUser->getUser() === $this) {
$bookingUser->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, SendMessages>
*/
public function getSendMessage(): Collection
{
return $this->sendMessage;
}
public function addSendMassage(SendMessages $sendMessage): self
{
if (!$this->sendMessage->contains($sendMessage)) {
$this->sendMessage[] = $sendMessage;
$sendMessage->setUser($this);
}
return $this;
}
public function removeSendMessage(SendMessages $sendMessage): self
{
if ($this->sendMessage->removeElement($sendMessage)) {
// set the owning side to null (unless already changed)
if ($sendMessage->getUser() === $this) {
$sendMessage->setUser(null);
}
}
return $this;
}
public function getMainUser(): ?self
{
return $this->MainUser;
}
public function setMainUser(?self $MainUser): self
{
$this->MainUser = $MainUser;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getSubUser(): Collection
{
return $this->subUser;
}
public function addSubUser(self $subUser): self
{
if (!$this->subUser->contains($subUser)) {
$this->subUser[] = $subUser;
$subUser->setMainUser($this);
}
return $this;
}
public function removeSubUser(self $subUser): self
{
if ($this->subUser->removeElement($subUser)) {
// set the owning side to null (unless already changed)
if ($subUser->getMainUser() === $this) {
$subUser->setMainUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Trip>
*/
public function getSupervisor(): Collection
{
return $this->supervisor;
}
public function addSupervisor(Trip $supervisor): self
{
if (!$this->supervisor->contains($supervisor)) {
$this->supervisor[] = $supervisor;
$supervisor->setSupervisor($this);
}
return $this;
}
public function removeSupervisor(Trip $supervisor): self
{
if ($this->supervisor->removeElement($supervisor)) {
// set the owning side to null (unless already changed)
if ($supervisor->getSupervisor() === $this) {
$supervisor->setSupervisor(null);
}
}
return $this;
}
/**
* @return Collection<int, Trip>
*/
public function getRecreationLeader(): Collection
{
return $this->recreationLeader;
}
public function addRecreationLeader(Trip $recreationLeader): self
{
if (!$this->recreationLeader->contains($recreationLeader)) {
$this->recreationLeader[] = $recreationLeader;
$recreationLeader->setRecreationLeader($this);
}
return $this;
}
public function removeRecreationLeader(Trip $recreationLeader): self
{
if ($this->recreationLeader->removeElement($recreationLeader)) {
// set the owning side to null (unless already changed)
if ($recreationLeader->getRecreationLeader() === $this) {
$recreationLeader->setRecreationLeader(null);
}
}
return $this;
}
/**
* @return Collection<int, Trip>
*/
public function getSupervisorTrip(): Collection
{
return $this->SupervisorTrip;
}
public function addSupervisorTrip(Trip $supervisorTrip): self
{
if (!$this->SupervisorTrip->contains($supervisorTrip)) {
$this->SupervisorTrip[] = $supervisorTrip;
}
return $this;
}
public function removeSupervisorTrip(Trip $supervisorTrip): self
{
$this->SupervisorTrip->removeElement($supervisorTrip);
return $this;
}
}