src/Entity/User.php line 16

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. #[ORM\Table(name'`user`')]
  12. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length180uniquetrue)]
  20.     private ?string $email null;
  21.     #[ORM\Column]
  22.     private array $roles = [];
  23.     /**
  24.      * @var string The hashed password
  25.      */
  26.     #[ORM\Column]
  27.     private ?string $password null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $photo null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $nom null;
  32.     #[ORM\Column(length255nullabletrue)]
  33.     private ?string $prenom null;
  34.     #[ORM\Column(length255nullabletrue)]
  35.     private ?string $tel null;
  36.     #[ORM\Column(length255nullabletrue)]
  37.     private ?string $adresse null;
  38.     #[ORM\Column(length255nullabletrue)]
  39.     private ?string $username null;
  40.     #[ORM\OneToMany(mappedBy'user'targetEntityContact::class, cascade: ['remove''persist'])]
  41.     private Collection $contacts;
  42.     #[ORM\OneToMany(mappedBy'user'targetEntityCaisse::class)]
  43.     private Collection $caisses;
  44.     public function __construct()
  45.     {
  46.         $this->contacts = new ArrayCollection();
  47.         $this->caisses = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getEmail(): ?string
  54.     {
  55.         return $this->email;
  56.     }
  57.     public function setEmail(string $email): static
  58.     {
  59.         $this->email $email;
  60.         return $this;
  61.     }
  62.     /**
  63.      * A visual identifier that represents this user.
  64.      *
  65.      * @see UserInterface
  66.      */
  67.     public function getUserIdentifier(): string
  68.     {
  69.         return (string) $this->email;
  70.     }
  71.     /**
  72.      * @see UserInterface
  73.      */
  74.     public function getRoles(): array
  75.     {
  76.         $roles $this->roles;
  77.         // guarantee every user at least has ROLE_USER
  78.         $roles[] = 'ROLE_USER';
  79.         return array_unique($roles);
  80.     }
  81.     public function setRoles(array $roles): static
  82.     {
  83.         $this->roles $roles;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @see PasswordAuthenticatedUserInterface
  88.      */
  89.     public function getPassword(): string
  90.     {
  91.         return $this->password;
  92.     }
  93.     public function setPassword(string $password): static
  94.     {
  95.         $this->password $password;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @see UserInterface
  100.      */
  101.     public function eraseCredentials(): void
  102.     {
  103.         // If you store any temporary, sensitive data on the user, clear it here
  104.         // $this->plainPassword = null;
  105.     }
  106.     public function getPhoto(): ?string
  107.     {
  108.         return $this->photo;
  109.     }
  110.     public function setPhoto(?string $photo): static
  111.     {
  112.         $this->photo $photo;
  113.         return $this;
  114.     }
  115.     public function getNom(): ?string
  116.     {
  117.         return $this->nom;
  118.     }
  119.     public function setNom(?string $nom): static
  120.     {
  121.         $this->nom $nom;
  122.         return $this;
  123.     }
  124.     public function getPrenom(): ?string
  125.     {
  126.         return $this->prenom;
  127.     }
  128.     public function setPrenom(?string $prenom): static
  129.     {
  130.         $this->prenom $prenom;
  131.         return $this;
  132.     }
  133.     public function getTel(): ?string
  134.     {
  135.         return $this->tel;
  136.     }
  137.     public function setTel(?string $tel): static
  138.     {
  139.         $this->tel $tel;
  140.         return $this;
  141.     }
  142.     public function getAdresse(): ?string
  143.     {
  144.         return $this->adresse;
  145.     }
  146.     public function setAdresse(?string $adresse): static
  147.     {
  148.         $this->adresse $adresse;
  149.         return $this;
  150.     }
  151.     public function getUsername(): ?string
  152.     {
  153.         return $this->username;
  154.     }
  155.     public function setUsername(?string $username): static
  156.     {
  157.         $this->username $username;
  158.         return $this;
  159.     }
  160.     /**
  161.      * @return Collection<int, Contact>
  162.      */
  163.     public function getContacts(): Collection
  164.     {
  165.         return $this->contacts;
  166.     }
  167.     public function addContact(Contact $contact): static
  168.     {
  169.         if (!$this->contacts->contains($contact)) {
  170.             $this->contacts->add($contact);
  171.             $contact->setUser($this);
  172.         }
  173.         return $this;
  174.     }
  175.     public function removeContact(Contact $contact): static
  176.     {
  177.         if ($this->contacts->removeElement($contact)) {
  178.             // set the owning side to null (unless already changed)
  179.             if ($contact->getUser() === $this) {
  180.                 $contact->setUser(null);
  181.             }
  182.         }
  183.         return $this;
  184.     }
  185.     /**
  186.      * @return Collection<int, Caisse>
  187.      */
  188.     public function getCaisses(): Collection
  189.     {
  190.         return $this->caisses;
  191.     }
  192.     public function addCaiss(Caisse $caiss): static
  193.     {
  194.         if (!$this->caisses->contains($caiss)) {
  195.             $this->caisses->add($caiss);
  196.             $caiss->setUser($this);
  197.         }
  198.         return $this;
  199.     }
  200.     public function removeCaiss(Caisse $caiss): static
  201.     {
  202.         if ($this->caisses->removeElement($caiss)) {
  203.             // set the owning side to null (unless already changed)
  204.             if ($caiss->getUser() === $this) {
  205.                 $caiss->setUser(null);
  206.             }
  207.         }
  208.         return $this;
  209.     }
  210. }