<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\RefereeRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
/**
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
#[ORM\Entity(repositoryClass: RefereeRepository::class)]
class Referee implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'string', length: 255)]
private $firstname;
#[ORM\Column(type: 'string', length: 255)]
private $lastname;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $avatar;
#[ORM\Column(type: 'date', nullable: true)]
private $birthday;
#[ORM\Column(type: 'boolean')]
private $gender;
#[ORM\Column(type: 'string', length: 255)]
private $phone1;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $phone2;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $kyorugiNumber;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $poomsaeNumber;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $kyorugiClass;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $poomsaeClass;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $kyorugiIRCard;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $poomsaeIRCard;
#[ORM\Column(type: 'datetime_immutable')]
private $createdAt;
#[ORM\ManyToOne(targetEntity: Country::class, inversedBy: 'referees')]
private $country;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\OneToMany(mappedBy: 'referee', targetEntity: Attribution::class)]
private $attributions;
#[ORM\Column(type: 'boolean')]
private $active;
#[ORM\ManyToOne(targetEntity: Country::class, inversedBy: 'refereessecond')]
private $secondcountry;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->attributions = new ArrayCollection();
}
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);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function addRole(string $role): self
{
$this->roles[] = $role;
$this->roles = array_unique($this->roles);
return $this;
}
public function isAdmin(): bool
{
return in_array("ROLE_ADMIN", $this->roles);
}
public function isReferee(): bool
{
return in_array("ROLE_REFEREE", $this->roles);
}
/**
* @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 getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
public function getAge()
{
if (null === $this->getBirthday()) {
return NULL;
} else {
$now = new \DateTime('now');
$age = $this->getBirthday();
$difference = $now->diff($age);
return $difference->format('%y years');
}
}
public function getBirthday(): ?\DateTimeInterface
{
return $this->birthday;
}
public function setBirthday(?\DateTimeInterface $birthday): self
{
$this->birthday = $birthday;
return $this;
}
public function getGender(): ?bool
{
return $this->gender;
}
public function setGender(bool $gender): self
{
$this->gender = $gender;
return $this;
}
public function getPhone1(): ?string
{
return $this->phone1;
}
public function setPhone1(string $phone1): self
{
$this->phone1 = $phone1;
return $this;
}
public function getPhone2(): ?string
{
return $this->phone2;
}
public function setPhone2(?string $phone2): self
{
$this->phone2 = $phone2;
return $this;
}
public function getKyorugiNumber(): ?string
{
return $this->kyorugiNumber;
}
public function setKyorugiNumber(?string $kyorugiNumber): self
{
$this->kyorugiNumber = $kyorugiNumber;
return $this;
}
public function getPoomsaeNumber(): ?string
{
return $this->poomsaeNumber;
}
public function setPoomsaeNumber(?string $poomsaeNumber): self
{
$this->poomsaeNumber = $poomsaeNumber;
return $this;
}
public function getKyorugiClass(): ?string
{
return $this->kyorugiClass;
}
public function setKyorugiClass(?string $kyorugiClass): self
{
$this->kyorugiClass = $kyorugiClass;
return $this;
}
public function getPoomsaeClass(): ?string
{
return $this->poomsaeClass;
}
public function setPoomsaeClass(?string $poomsaeClass): self
{
$this->poomsaeClass = $poomsaeClass;
return $this;
}
public function getKyorugiIRCard(): ?string
{
return $this->kyorugiIRCard;
}
public function setKyorugiIRCard(?string $kyorugiIRCard): self
{
$this->kyorugiIRCard = $kyorugiIRCard;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCountry(): ?Country
{
return $this->country;
}
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection|Attribution[]
*/
public function getAttributions(): Collection
{
return $this->attributions;
}
public function addAttribution(Attribution $attribution): self
{
if (!$this->attributions->contains($attribution)) {
$this->attributions[] = $attribution;
$attribution->setReferee($this);
}
return $this;
}
public function removeAttribution(Attribution $attribution): self
{
if ($this->attributions->removeElement($attribution)) {
// set the owning side to null (unless already changed)
if ($attribution->getReferee() === $this) {
$attribution->setReferee(null);
}
}
return $this;
}
public function __toString()
{
return $this->firstname.' '.$this->lastname;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getSecondcountry(): ?Country
{
return $this->secondcountry;
}
public function setSecondcountry(?Country $secondcountry): self
{
$this->secondcountry = $secondcountry;
return $this;
}
public function getPoomsaeIRCard(): ?string
{
return $this->poomsaeIRCard;
}
public function setPoomsaeIRCard(?string $poomsaeIRCard): self
{
$this->poomsaeIRCard = $poomsaeIRCard;
return $this;
}
}