<?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\Component\Validator\Constraints as Assert;
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)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'], message: 'Il existe déjà un compte associé à cet E-mail')]
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(length: 100)]
private ?string $firstname = null;
#[ORM\Column(length: 100)]
private ?string $lastname = null;
#[ORM\Column(length: 12)]
private ?string $phone = null;
#[ORM\Column(length: 150)]
private ?string $company = null;
#[ORM\Column(length: 5)]
private ?string $zipcode = null;
#[ORM\Column(length: 150)]
private ?string $city = null;
#[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
private ?\DateTimeImmutable $created_at = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Answer::class)]
private Collection $answers;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Comment::class)]
private Collection $comments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Payment::class)]
private Collection $payments;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Ticket::class)]
private Collection $tickets;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Post::class)]
private Collection $posts;
#[ORM\Column(nullable: true)]
private ?bool $is_app_acces = null;
#[ORM\Column(nullable: true)]
private ?bool $is_ticket_open = null;
#[ORM\Column(nullable: true)]
private ?bool $is_logged = null;
#[ORM\Column(nullable: true)]
private ?int $nb_tickets = null;
#[ORM\Column(nullable: true)]
private ?int $nb_answers = null;
#[ORM\Column(nullable: true)]
private ?int $nb_payments = null;
#[ORM\Column(nullable: true)]
private ?int $nb_posts = null;
#[ORM\Column(nullable: true)]
private ?int $nb_comments = null;
#[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
private ?\DateTimeImmutable $last_login_at = null;
public function __construct()
{
$this->created_at = new \DateTimeImmutable();
$this->answers = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->posts = 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 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 getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(string $company): self
{
$this->company = $company;
return $this;
}
public function getZipcode(): ?string
{
return $this->zipcode;
}
public function setZipcode(string $zipcode): self
{
$this->zipcode = $zipcode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
/**
* @return Collection<int, Answer>
*/
public function getAnswers(): Collection
{
return $this->answers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers->add($answer);
$answer->setUser($this);
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
if ($this->answers->removeElement($answer)) {
// set the owning side to null (unless already changed)
if ($answer->getUser() === $this) {
$answer->setUser(null);
}
}
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, Payment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments->add($payment);
$payment->setUser($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->removeElement($payment)) {
// set the owning side to null (unless already changed)
if ($payment->getUser() === $this) {
$payment->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Ticket>
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): self
{
if (!$this->tickets->contains($ticket)) {
$this->tickets->add($ticket);
$ticket->setUser($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): self
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getUser() === $this) {
$ticket->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->setUser($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getUser() === $this) {
$post->setUser(null);
}
}
return $this;
}
public function isIsAppAcces(): ?bool
{
return $this->is_app_acces;
}
public function setIsAppAcces(?bool $is_app_acces): self
{
$this->is_app_acces = $is_app_acces;
return $this;
}
public function isIsTicketOpen(): ?bool
{
return $this->is_ticket_open;
}
public function setIsTicketOpen(?bool $is_ticket_open): self
{
$this->is_ticket_open = $is_ticket_open;
return $this;
}
public function isIsLogged(): ?bool
{
return $this->is_logged;
}
public function setIsLogged(?bool $is_logged): self
{
$this->is_logged = $is_logged;
return $this;
}
public function getLastLoginAt(): ?\DateTimeImmutable
{
return $this->last_login_at;
}
public function setLastLoginAt(\DateTimeImmutable $last_login_at): self
{
$this->last_login_at = $last_login_at;
return $this;
}
public function getNbTickets(): ?int
{
return $this->nb_tickets;
}
public function setNbTickets(?int $nb_tickets): self
{
$this->nb_tickets = $nb_tickets;
return $this;
}
public function getNbAnswers(): ?int
{
return $this->nb_answers;
}
public function setNbAnswers(?int $nb_answers): self
{
$this->nb_answers = $nb_answers;
return $this;
}
public function getNbPayments(): ?int
{
return $this->nb_payments;
}
public function setNbPayments(?int $nb_payments): self
{
$this->nb_payments = $nb_payments;
return $this;
}
public function getNbComments(): ?int
{
return $this->nb_comments;
}
public function setNbComments(?int $nb_comments): self
{
$this->nb_comments = $nb_comments;
return $this;
}
public function getNbPosts(): ?int
{
return $this->nb_posts;
}
public function setNbPosts(?int $nb_posts): self
{
$this->nb_posts = $nb_posts;
return $this;
}
}