<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(type: Types::DATE_MUTABLE)]
private ?\DateTimeInterface $birthday = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column]
private ?int $phone = null;
#[ORM\Column(length: 10)]
private ?string $gender = null;
#[ORM\Column(length: 255)]
private ?string $address = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $postalCode = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $country = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $state = null;
#[ORM\Column(nullable: true)]
private ?bool $blocked = null;
#[ORM\Column(length: 65, nullable: true)]
private ?string $token = null;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: Company::class)]
private Collection $companies;
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: BusTicket::class)]
private Collection $busTickets;
public function __construct()
{
$this->companies = new ArrayCollection();
$this->busTickets = new ArrayCollection();
}
public function setSpecialId(int $id): ?self
{
$this->id = $id;
return $this;
}
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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): 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;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getBirthday(): ?\DateTimeInterface
{
return $this->birthday;
}
public function setBirthday(\DateTimeInterface $birthday): self
{
$this->birthday = $birthday;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPhone(): ?int
{
return $this->phone;
}
public function setPhone(int $phone): self
{
$this->phone = $phone;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
public function isBlocked(): ?bool
{
return $this->blocked;
}
public function setBlocked(?bool $blocked): self
{
$this->blocked = $blocked;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->setCreatedBy($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
// set the owning side to null (unless already changed)
if ($company->getCreatedBy() === $this) {
$company->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, BusTicket>
*/
public function getBusTickets(): Collection
{
return $this->busTickets;
}
public function addBusTicket(BusTicket $busTicket): static
{
if (!$this->busTickets->contains($busTicket)) {
$this->busTickets->add($busTicket);
$busTicket->setCreatedBy($this);
}
return $this;
}
public function removeBusTicket(BusTicket $busTicket): static
{
if ($this->busTickets->removeElement($busTicket)) {
// set the owning side to null (unless already changed)
if ($busTicket->getCreatedBy() === $this) {
$busTicket->setCreatedBy(null);
}
}
return $this;
}
}