src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[ORM\Table(name'`user`')]
  13. #[UniqueEntity(fields: ['email'], message'Il existe déjà un compte associé à cet E-mail')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id null
  20.     #[ORM\Column(length180uniquetrue)]
  21.     private ?string $email null;
  22.     #[ORM\Column]
  23.     private array $roles = [];
  24.     /**
  25.      * @var string The hashed password
  26.      */
  27.     #[ORM\Column]
  28.     private ?string $password null;
  29.     #[ORM\Column(length100)]
  30.     private ?string $firstname null;
  31.     #[ORM\Column(length100)]
  32.     private ?string $lastname null;
  33.     #[ORM\Column(length12)]
  34.     private ?string $phone null;
  35.     #[ORM\Column(length150)]
  36.     private ?string $company null;
  37.     #[ORM\Column(length5)]
  38.     private ?string $zipcode null;
  39.     #[ORM\Column(length150)]
  40.     private ?string $city null;
  41.     #[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
  42.     private ?\DateTimeImmutable $created_at null;
  43.     #[ORM\OneToMany(mappedBy'user'targetEntityAnswer::class)]
  44.     private Collection $answers;
  45.     #[ORM\OneToMany(mappedBy'user'targetEntityComment::class)]
  46.     private Collection $comments;
  47.     #[ORM\OneToMany(mappedBy'user'targetEntityPayment::class)]
  48.     private Collection $payments;
  49.     #[ORM\OneToMany(mappedBy'user'targetEntityTicket::class)]
  50.     private Collection $tickets;
  51.     #[ORM\OneToMany(mappedBy'user'targetEntityPost::class)]
  52.     private Collection $posts;
  53.     #[ORM\Column(nullabletrue)]
  54.     private ?bool $is_app_acces null;
  55.     #[ORM\Column(nullabletrue)]
  56.     private ?bool $is_ticket_open null;
  57.     #[ORM\Column(nullabletrue)]
  58.     private ?bool $is_logged null;
  59.     #[ORM\Column(nullabletrue)]
  60.     private ?int $nb_tickets null;
  61.     #[ORM\Column(nullabletrue)]
  62.     private ?int $nb_answers null;
  63.     #[ORM\Column(nullabletrue)]
  64.     private ?int $nb_payments null;
  65.     #[ORM\Column(nullabletrue)]
  66.     private ?int $nb_posts null;
  67.     #[ORM\Column(nullabletrue)]
  68.     private ?int $nb_comments null;
  69.     #[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
  70.     private ?\DateTimeImmutable $last_login_at null;
  71.     public function __construct()
  72.     {     
  73.         $this->created_at = new \DateTimeImmutable();  
  74.         $this->answers = new ArrayCollection();
  75.         $this->comments = new ArrayCollection();
  76.         $this->payments = new ArrayCollection();
  77.         $this->tickets = new ArrayCollection();
  78.         $this->posts = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getEmail(): ?string
  85.     {
  86.         return $this->email;
  87.     }
  88.     public function setEmail(string $email): self
  89.     {
  90.         $this->email $email;
  91.         return $this;
  92.     }
  93.     /**
  94.      * A visual identifier that represents this user.
  95.      *
  96.      * @see UserInterface
  97.      */
  98.     public function getUserIdentifier(): string
  99.     {
  100.         return (string) $this->email;
  101.     }
  102.     /**
  103.      * @see UserInterface
  104.      */
  105.     public function getRoles(): array
  106.     {
  107.         $roles $this->roles;
  108.         // guarantee every user at least has ROLE_USER
  109.         $roles[] = 'ROLE_USER';
  110.         return array_unique($roles);
  111.     }
  112.     public function setRoles(array $roles): self
  113.     {
  114.         $this->roles $roles;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @see PasswordAuthenticatedUserInterface
  119.      */
  120.     public function getPassword(): string
  121.     {
  122.         return $this->password;
  123.     }
  124.     public function setPassword(string $password): self
  125.     {
  126.         $this->password $password;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @see UserInterface
  131.      */
  132.     public function eraseCredentials()
  133.     {
  134.         // If you store any temporary, sensitive data on the user, clear it here
  135.         // $this->plainPassword = null;
  136.     }
  137.     public function getFirstname(): ?string
  138.     {
  139.         return $this->firstname;
  140.     }
  141.     public function setFirstname(string $firstname): self
  142.     {
  143.         $this->firstname $firstname;
  144.         return $this;
  145.     }
  146.     public function getLastname(): ?string
  147.     {
  148.         return $this->lastname;
  149.     }
  150.     public function setLastname(string $lastname): self
  151.     {
  152.         $this->lastname $lastname;
  153.         return $this;
  154.     }
  155.     
  156.     public function getPhone(): ?string
  157.     {
  158.         return $this->phone;
  159.     }
  160.     public function setPhone(string $phone): self
  161.     {
  162.         $this->phone $phone;
  163.         return $this;
  164.     }
  165.     public function getCompany(): ?string
  166.     {
  167.         return $this->company;
  168.     }
  169.     public function setCompany(string $company): self
  170.     {
  171.         $this->company $company;
  172.         return $this;
  173.     }
  174.     public function getZipcode(): ?string
  175.     {
  176.         return $this->zipcode;
  177.     }
  178.     public function setZipcode(string $zipcode): self
  179.     {
  180.         $this->zipcode $zipcode;
  181.         return $this;
  182.     }
  183.     public function getCity(): ?string
  184.     {
  185.         return $this->city;
  186.     }
  187.     public function setCity(string $city): self
  188.     {
  189.         $this->city $city;
  190.         return $this;
  191.     }
  192.     public function getCreatedAt(): ?\DateTimeImmutable
  193.     {
  194.         return $this->created_at;
  195.     }
  196.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  197.     {
  198.         $this->created_at $created_at;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return Collection<int, Answer>
  203.      */
  204.     public function getAnswers(): Collection
  205.     {
  206.         return $this->answers;
  207.     }
  208.     public function addAnswer(Answer $answer): self
  209.     {
  210.         if (!$this->answers->contains($answer)) {
  211.             $this->answers->add($answer);
  212.             $answer->setUser($this);
  213.         }
  214.         return $this;
  215.     }
  216.     public function removeAnswer(Answer $answer): self
  217.     {
  218.         if ($this->answers->removeElement($answer)) {
  219.             // set the owning side to null (unless already changed)
  220.             if ($answer->getUser() === $this) {
  221.                 $answer->setUser(null);
  222.             }
  223.         }
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection<int, Comment>
  228.      */
  229.     public function getComments(): Collection
  230.     {
  231.         return $this->comments;
  232.     }
  233.     public function addComment(Comment $comment): self
  234.     {
  235.         if (!$this->comments->contains($comment)) {
  236.             $this->comments->add($comment);
  237.             $comment->setUser($this);
  238.         }
  239.         return $this;
  240.     }
  241.     public function removeComment(Comment $comment): self
  242.     {
  243.         if ($this->comments->removeElement($comment)) {
  244.             // set the owning side to null (unless already changed)
  245.             if ($comment->getUser() === $this) {
  246.                 $comment->setUser(null);
  247.             }
  248.         }
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection<int, Payment>
  253.      */
  254.     public function getPayments(): Collection
  255.     {
  256.         return $this->payments;
  257.     }
  258.     public function addPayment(Payment $payment): self
  259.     {
  260.         if (!$this->payments->contains($payment)) {
  261.             $this->payments->add($payment);
  262.             $payment->setUser($this);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removePayment(Payment $payment): self
  267.     {
  268.         if ($this->payments->removeElement($payment)) {
  269.             // set the owning side to null (unless already changed)
  270.             if ($payment->getUser() === $this) {
  271.                 $payment->setUser(null);
  272.             }
  273.         }
  274.         return $this;
  275.     }
  276.     /**
  277.      * @return Collection<int, Ticket>
  278.      */
  279.     public function getTickets(): Collection
  280.     {
  281.         return $this->tickets;
  282.     }
  283.     public function addTicket(Ticket $ticket): self
  284.     {
  285.         if (!$this->tickets->contains($ticket)) {
  286.             $this->tickets->add($ticket);
  287.             $ticket->setUser($this);
  288.         }
  289.         return $this;
  290.     }
  291.     public function removeTicket(Ticket $ticket): self
  292.     {
  293.         if ($this->tickets->removeElement($ticket)) {
  294.             // set the owning side to null (unless already changed)
  295.             if ($ticket->getUser() === $this) {
  296.                 $ticket->setUser(null);
  297.             }
  298.         }
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return Collection<int, Post>
  303.      */
  304.     public function getPosts(): Collection
  305.     {
  306.         return $this->posts;
  307.     }
  308.     public function addPost(Post $post): self
  309.     {
  310.         if (!$this->posts->contains($post)) {
  311.             $this->posts->add($post);
  312.             $post->setUser($this);
  313.         }
  314.         return $this;
  315.     }
  316.     public function removePost(Post $post): self
  317.     {
  318.         if ($this->posts->removeElement($post)) {
  319.             // set the owning side to null (unless already changed)
  320.             if ($post->getUser() === $this) {
  321.                 $post->setUser(null);
  322.             }
  323.         }
  324.         return $this;
  325.     }
  326.     public function isIsAppAcces(): ?bool
  327.     {
  328.         return $this->is_app_acces;
  329.     }
  330.     public function setIsAppAcces(?bool $is_app_acces): self
  331.     {
  332.         $this->is_app_acces $is_app_acces;
  333.         return $this;
  334.     }
  335.     public function isIsTicketOpen(): ?bool
  336.     {
  337.         return $this->is_ticket_open;
  338.     }
  339.     public function setIsTicketOpen(?bool $is_ticket_open): self
  340.     {
  341.         $this->is_ticket_open $is_ticket_open;
  342.         return $this;
  343.     }
  344.     public function isIsLogged(): ?bool
  345.     {
  346.         return $this->is_logged;
  347.     }
  348.     public function setIsLogged(?bool $is_logged): self
  349.     {
  350.         $this->is_logged $is_logged;
  351.         return $this;
  352.     }
  353.     public function getLastLoginAt(): ?\DateTimeImmutable
  354.     {
  355.         return $this->last_login_at;
  356.     }
  357.     public function setLastLoginAt(\DateTimeImmutable $last_login_at): self
  358.     {
  359.         $this->last_login_at $last_login_at;
  360.         return $this;
  361.     }
  362.     
  363.     public function getNbTickets(): ?int
  364.     {
  365.         return $this->nb_tickets;
  366.     }
  367.     public function setNbTickets(?int $nb_tickets): self
  368.     {
  369.         $this->nb_tickets $nb_tickets;
  370.         return $this;
  371.     }
  372.     public function getNbAnswers(): ?int
  373.     {
  374.         return $this->nb_answers;
  375.     }
  376.     public function setNbAnswers(?int $nb_answers): self
  377.     {
  378.         $this->nb_answers $nb_answers;
  379.         return $this;
  380.     }
  381.     public function getNbPayments(): ?int
  382.     {
  383.         return $this->nb_payments;
  384.     }
  385.     public function setNbPayments(?int $nb_payments): self
  386.     {
  387.         $this->nb_payments $nb_payments;
  388.         return $this;
  389.     }
  390.     public function getNbComments(): ?int
  391.     {
  392.         return $this->nb_comments;
  393.     }
  394.     public function setNbComments(?int $nb_comments): self
  395.     {
  396.         $this->nb_comments $nb_comments;
  397.         return $this;
  398.     }
  399.     public function getNbPosts(): ?int
  400.     {
  401.         return $this->nb_posts;
  402.     }
  403.     public function setNbPosts(?int $nb_posts): self
  404.     {
  405.         $this->nb_posts $nb_posts;
  406.         return $this;
  407.     }
  408. }