<?php
namespace App\Entity;
use App\Entity\Appointment\Appointment;
use App\Entity\Company\Company;
use App\Entity\Customer\Customer;
use App\Entity\Event\EventUser;
use App\Entity\Invoice\Invoice;
use App\Entity\Order\Cart;
use App\Entity\Order\Order;
use App\Entity\UserInformation\UserInformation;
use App\Entity\User\Wish;
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;
#[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]
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: 'boolean')]
private $isVerified = false;
#[ORM\Column(length: 255)]
private ?string $userName = null;
#[ORM\Column(length: 20, nullable: true)]
private ?string $telephone = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Comment::class)]
private Collection $comments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Order::class)]
private Collection $orders;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: EventUser::class)]
private Collection $events;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Appointment::class)]
private Collection $appointments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Cart::class)]
private Collection $carts;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserInformation::class)]
private Collection $userInformation;
#[ORM\ManyToMany(targetEntity: Company::class, inversedBy: 'users')]
#[ORM\JoinTable(name: 'user_company')]
private Collection $companies;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Wish::class)]
private Collection $wishes;
#[ORM\OneToOne(inversedBy: 'user')]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Customer $customer = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Invoice::class)]
private Collection $invoices;
public function __toString()
{
return $this->email;
}
public function __construct()
{
$this->comments = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->events = new ArrayCollection();
$this->appointments = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->userInformation = new ArrayCollection();
$this->companies = new ArrayCollection();
$this->wishes = new ArrayCollection();
$this->invoices = 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;
}
/**
* @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 isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getUserName(): ?string
{
return $this->userName;
}
public function setUserName(string $userName): self
{
$this->userName = $userName;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
/**
* @return Collection<int, Comment>
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments->add($comment);
$comment->setUser($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getUser() === $this) {
$comment->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, EventUser>
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(EventUser $event): static
{
if (!$this->events->contains($event)) {
$this->events->add($event);
$event->setUser($this);
}
return $this;
}
public function removeEvent(EventUser $event): static
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getUser() === $this) {
$event->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Appointment>
*/
public function getAppointments(): Collection
{
return $this->appointments;
}
public function addAppointment(Appointment $appointment): static
{
if (!$this->appointments->contains($appointment)) {
$this->appointments->add($appointment);
$appointment->setUser($this);
}
return $this;
}
public function removeAppointment(Appointment $appointment): static
{
if ($this->appointments->removeElement($appointment)) {
// set the owning side to null (unless already changed)
if ($appointment->getUser() === $this) {
$appointment->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(Cart $cart): static
{
if (!$this->carts->contains($cart)) {
$this->carts->add($cart);
$cart->setUser($this);
}
return $this;
}
public function removeCart(Cart $cart): static
{
if ($this->carts->removeElement($cart)) {
// set the owning side to null (unless already changed)
if ($cart->getUser() === $this) {
$cart->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, UserInformation>
*/
public function getUserInformation(): Collection
{
return $this->userInformation;
}
public function addUserInformation(UserInformation $userInformation): static
{
if (!$this->userInformation->contains($userInformation)) {
$this->userInformation->add($userInformation);
$userInformation->setUser($this);
}
return $this;
}
public function removeUserInformation(UserInformation $userInformation): static
{
if ($this->userInformation->removeElement($userInformation)) {
// set the owning side to null (unless already changed)
if ($userInformation->getUser() === $this) {
$userInformation->setUser(null);
}
}
return $this;
}
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
$company->addUser($this);
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->removeElement($company)) {
$company->removeUser($this);
}
return $this;
}
/**
* @return Collection<int, Wish>
*/
public function getWishes(): Collection
{
return $this->wishes;
}
public function addWish(Wish $wish): static
{
if (!$this->wishes->contains($wish)) {
$this->wishes->add($wish);
$wish->setUser($this);
}
return $this;
}
public function removeWish(Wish $wish): static
{
if ($this->wishes->removeElement($wish)) {
// set the owning side to null (unless already changed)
if ($wish->getUser() === $this) {
$wish->setUser(null);
}
}
return $this;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): static
{
$this->customer = $customer;
return $this;
}
/**
* @return Collection<int, Invoice>
*/
public function getInvoices(): Collection
{
return $this->invoices;
}
public function addInvoice(Invoice $invoice): static
{
if (!$this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
$invoice->setUser($this);
}
return $this;
}
public function removeInvoice(Invoice $invoice): static
{
if ($this->invoices->removeElement($invoice)) {
// set the owning side to null (unless already changed)
if ($invoice->getUser() === $this) {
$invoice->setUser(null);
}
}
return $this;
}
}