src/Entity/User.php line 15

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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'Il existe déjà un compte avec cet email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     const IS_VERIFIED 1;
  15.     const IS_NOT_VERIFIED 0;
  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(length255)]
  30.     private ?string $firstName null;
  31.     #[ORM\Column(length255)]
  32.     private ?string $lastName null;
  33.     #[ORM\Column(length255)]
  34.     private ?string $phone null;
  35.     #[ORM\Column(length255)]
  36.     private ?string $address null;
  37.     #[ORM\Column(length255)]
  38.     private ?string $postalCode null;
  39.     #[ORM\Column(length255)]
  40.     private ?string $city null;
  41.     #[ORM\Column(length255)]
  42.     private ?string $company null;
  43.     #[ORM\Column]
  44.     private ?\DateTimeImmutable $addedAt null;
  45.     #[ORM\Column(nullabletrue)]
  46.     private ?\DateTimeImmutable $updateAt null;
  47.     #[ORM\Column]
  48.     private ?int $isActive 1;
  49.     #[ORM\OneToMany(mappedBy'user'targetEntityProject::class, orphanRemovaltrue)]
  50.     private Collection $projects;
  51.     #[ORM\Column(type'boolean')]
  52.     private $isVerified false;
  53.     // User entity
  54.     #[ORM\OneToMany(mappedBy'user'targetEntityAccountingDocument::class, orphanRemovaltrue)]
  55.     private Collection $accounting_document;
  56.     #[ORM\OneToMany(mappedBy'user'targetEntityChat::class, orphanRemovaltrue)]
  57.     private Collection $chat;
  58.     #[ORM\OneToMany(mappedBy'user'targetEntityTicket::class, orphanRemovaltrue)]
  59.     private Collection $ticket;
  60.     public function __construct()
  61.     {
  62.         $this->setAddedAt(new \DateTimeImmutable());
  63.         $this->projects = new ArrayCollection();
  64.         $this->accounting_document = new ArrayCollection();
  65.         $this->chat = new ArrayCollection();
  66.         $this->ticket = new ArrayCollection();
  67.     }
  68.     public function __toString(): string
  69.     {
  70.         return $this->firstName;
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getEmail(): ?string
  77.     {
  78.         return $this->email;
  79.     }
  80.     public function setEmail(string $email): self
  81.     {
  82.         $this->email $email;
  83.         return $this;
  84.     }
  85.     /**
  86.      * A visual identifier that represents this user.
  87.      *
  88.      * @see UserInterface
  89.      */
  90.     public function getUserIdentifier(): string
  91.     {
  92.         return (string) $this->email;
  93.     }
  94.     /**
  95.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  96.      */
  97.     public function getUsername(): string
  98.     {
  99.         return (string) $this->email;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function getRoles(): array
  105.     {
  106.         $roles $this->roles;
  107.         // guarantee every user at least has ROLE_USER
  108.         $roles[] = 'ROLE_USER';
  109.         return array_unique($roles);
  110.     }
  111.     public function setRoles(array $roles): self
  112.     {
  113.         $this->roles $roles;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @see PasswordAuthenticatedUserInterface
  118.      */
  119.     public function getPassword(): string
  120.     {
  121.         return $this->password;
  122.     }
  123.     public function setPassword(string $password): self
  124.     {
  125.         $this->password $password;
  126.         return $this;
  127.     }
  128.     /**
  129.      * Returning a salt is only needed, if you are not using a modern
  130.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  131.      *
  132.      * @see UserInterface
  133.      */
  134.     public function getSalt(): ?string
  135.     {
  136.         return null;
  137.     }
  138.     /**
  139.      * @see UserInterface
  140.      */
  141.     public function eraseCredentials()
  142.     {
  143.         // If you store any temporary, sensitive data on the user, clear it here
  144.         // $this->plainPassword = null;
  145.     }
  146.     public function getFirstName(): ?string
  147.     {
  148.         return $this->firstName;
  149.     }
  150.     public function setFirstName(string $firstName): self
  151.     {
  152.         $this->firstName $firstName;
  153.         return $this;
  154.     }
  155.     public function getLastName(): ?string
  156.     {
  157.         return $this->lastName;
  158.     }
  159.     public function setLastName(string $lastName): self
  160.     {
  161.         $this->lastName $lastName;
  162.         return $this;
  163.     }
  164.     public function getPhone(): ?string
  165.     {
  166.         return $this->phone;
  167.     }
  168.     public function setPhone(string $phone): self
  169.     {
  170.         $this->phone $phone;
  171.         return $this;
  172.     }
  173.     public function getAddress(): ?string
  174.     {
  175.         return $this->address;
  176.     }
  177.     public function setAddress(string $address): self
  178.     {
  179.         $this->address $address;
  180.         return $this;
  181.     }
  182.     public function getPostalCode(): ?string
  183.     {
  184.         return $this->postalCode;
  185.     }
  186.     public function setPostalCode(string $postalCode): self
  187.     {
  188.         $this->postalCode $postalCode;
  189.         return $this;
  190.     }
  191.     public function getCity(): ?string
  192.     {
  193.         return $this->city;
  194.     }
  195.     public function setCity(string $city): self
  196.     {
  197.         $this->city $city;
  198.         return $this;
  199.     }
  200.     public function getCompany(): ?string
  201.     {
  202.         return $this->company;
  203.     }
  204.     public function setCompany(string $company): self
  205.     {
  206.         $this->company $company;
  207.         return $this;
  208.     }
  209.     public function getAddedAt(): ?\DateTimeImmutable
  210.     {
  211.         return $this->addedAt;
  212.     }
  213.     public function setAddedAt(\DateTimeImmutable $addedAt): self
  214.     {
  215.         $this->addedAt $addedAt;
  216.         return $this;
  217.     }
  218.     public function getUpdateAt(): ?\DateTimeImmutable
  219.     {
  220.         return $this->updateAt;
  221.     }
  222.     public function setUpdateAt(?\DateTimeImmutable $updateAt): self
  223.     {
  224.         $this->updateAt $updateAt;
  225.         return $this;
  226.     }
  227.     public function getIsActive(): ?int
  228.     {
  229.         return $this->isActive;
  230.     }
  231.     public function setIsActive(int $isActive): self
  232.     {
  233.         $this->isActive $isActive;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection<int, Project>
  238.      */
  239.     public function getProjects(): Collection
  240.     {
  241.         return $this->projects;
  242.     }
  243.     public function addProject(Project $project): self
  244.     {
  245.         if (!$this->projects->contains($project)) {
  246.             $this->projects->add($project);
  247.             $project->setUser($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeProject(Project $project): self
  252.     {
  253.         if ($this->projects->removeElement($project)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($project->getUser() === $this) {
  256.                 $project->setUser(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     public function isVerified(): bool
  262.     {
  263.         return $this->isVerified;
  264.     }
  265.     public function setIsVerified(bool $isVerified): self
  266.     {
  267.         $this->isVerified $isVerified;
  268.         return $this;
  269.     }
  270.     public function getAccountingDocument(): ?AccountingDocument
  271.     {
  272.         return $this->accountingDocument;
  273.     }
  274.     public function setAccountingDocument(?AccountingDocument $accountingDocument): self
  275.     {
  276.         // unset the owning side of the relation if necessary
  277.         if ($accountingDocument === null && $this->accountingDocument !== null) {
  278.             $this->accountingDocument->setUser(null);
  279.         }
  280.         // set the owning side of the relation if necessary
  281.         if ($accountingDocument !== null && $accountingDocument->getUser() !== $this) {
  282.             $accountingDocument->setUser($this);
  283.         }
  284.         $this->accountingDocument $accountingDocument;
  285.         return $this;
  286.     }
  287.     public function addAccountingDocument(AccountingDocument $accountingDocument): self
  288.     {
  289.         if (!$this->accounting_document->contains($accountingDocument)) {
  290.             $this->accounting_document->add($accountingDocument);
  291.             $accountingDocument->setUser($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeAccountingDocument(AccountingDocument $accountingDocument): self
  296.     {
  297.         if ($this->accounting_document->removeElement($accountingDocument)) {
  298.             // set the owning side to null (unless already changed)
  299.             if ($accountingDocument->getUser() === $this) {
  300.                 $accountingDocument->setUser(null);
  301.             }
  302.         }
  303.         return $this;
  304.     }
  305.     public function getIdentity(): string
  306.     {
  307.         return $this->lastName ' ' $this->firstName;
  308.     }
  309.     /**
  310.      * @return Collection<int, Chat>
  311.      */
  312.     public function getChat(): Collection
  313.     {
  314.         return $this->chat;
  315.     }
  316.     public function addChat(Chat $chat): self
  317.     {
  318.         if (!$this->chat->contains($chat)) {
  319.             $this->chat->add($chat);
  320.             $chat->setUser($this);
  321.         }
  322.         return $this;
  323.     }
  324.     public function removeChat(Chat $chat): self
  325.     {
  326.         if ($this->chat->removeElement($chat)) {
  327.             // set the owning side to null (unless already changed)
  328.             if ($chat->getUser() === $this) {
  329.                 $chat->setUser(null);
  330.             }
  331.         }
  332.         return $this;
  333.     }
  334.     /**
  335.      * @return Collection<int, Ticket>
  336.      */
  337.     public function getTicket(): Collection
  338.     {
  339.         return $this->ticket;
  340.     }
  341.     public function addTicket(Ticket $ticket): self
  342.     {
  343.         if (!$this->ticket->contains($ticket)) {
  344.             $this->ticket->add($ticket);
  345.             $ticket->setUser($this);
  346.         }
  347.         return $this;
  348.     }
  349.     public function removeTicket(Ticket $ticket): self
  350.     {
  351.         if ($this->ticket->removeElement($ticket)) {
  352.             // set the owning side to null (unless already changed)
  353.             if ($ticket->getUser() === $this) {
  354.                 $ticket->setUser(null);
  355.             }
  356.         }
  357.         return $this;
  358.     }
  359. }