src/Entity/User.php line 14

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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. class User implements UserInterfacePasswordAuthenticatedUserInterface
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length180uniquetrue)]
  18.     private ?string $email null;
  19.     #[ORM\Column]
  20.     private array $roles = [];
  21.     /**
  22.      * @var string The hashed password
  23.      */
  24.     #[ORM\Column]
  25.     private ?string $password null;
  26.     #[ORM\Column(length255)]
  27.     private ?string $firstname null;
  28.     #[ORM\Column(length255)]
  29.     private ?string $lastname null;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $profilePicture null;
  32.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  33.     private ?\DateTimeInterface $createdAt null;
  34.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  35.     private ?\DateTimeInterface $updatedAt null;
  36.     #[ORM\OneToMany(mappedBy'user'targetEntityAddress::class, orphanRemovaltrue)]
  37.     private Collection $addresses;
  38.     #[ORM\OneToMany(mappedBy'user'targetEntityBookAd::class, orphanRemovaltrue)]
  39.     private Collection $bookAds;
  40.     #[ORM\OneToOne(mappedBy'user'cascade: ['persist''remove'])]
  41.     private ?Basket $basket null;
  42.     public function __construct()
  43.     {
  44.         $this->addresses = new ArrayCollection();
  45.         $this->bookAds = new ArrayCollection();
  46.         // correction du 06/04
  47.         // on attache un panier vide à l'utilisateur
  48.         // (parce que symfony le fait pas tout seul, comme la relation est construite comme pouvant être null)
  49.         $this->setBasket(new Basket());
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getEmail(): ?string
  56.     {
  57.         return $this->email;
  58.     }
  59.     public function setEmail(string $email): self
  60.     {
  61.         $this->email $email;
  62.         return $this;
  63.     }
  64.     /**
  65.      * A visual identifier that represents this user.
  66.      *
  67.      * @see UserInterface
  68.      */
  69.     public function getUserIdentifier(): string
  70.     {
  71.         return (string) $this->email;
  72.     }
  73.     /**
  74.      * @see UserInterface
  75.      */
  76.     public function getRoles(): array
  77.     {
  78.         $roles $this->roles;
  79.         // guarantee every user at least has ROLE_USER
  80.         $roles[] = 'ROLE_USER';
  81.         return array_unique($roles);
  82.     }
  83.     public function setRoles(array $roles): self
  84.     {
  85.         $this->roles $roles;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @see PasswordAuthenticatedUserInterface
  90.      */
  91.     public function getPassword(): string
  92.     {
  93.         return $this->password;
  94.     }
  95.     public function setPassword(string $password): self
  96.     {
  97.         $this->password $password;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @see UserInterface
  102.      */
  103.     public function eraseCredentials()
  104.     {
  105.         // If you store any temporary, sensitive data on the user, clear it here
  106.         // $this->plainPassword = null;
  107.     }
  108.     public function getFirstname(): ?string
  109.     {
  110.         return $this->firstname;
  111.     }
  112.     public function setFirstname(string $firstname): self
  113.     {
  114.         $this->firstname $firstname;
  115.         return $this;
  116.     }
  117.     public function getLastname(): ?string
  118.     {
  119.         return $this->lastname;
  120.     }
  121.     public function setLastname(string $lastname): self
  122.     {
  123.         $this->lastname $lastname;
  124.         return $this;
  125.     }
  126.     public function getProfilePicture(): ?string
  127.     {
  128.         return $this->profilePicture;
  129.     }
  130.     public function setProfilePicture(?string $profilePicture): self
  131.     {
  132.         $this->profilePicture $profilePicture;
  133.         return $this;
  134.     }
  135.     public function getCreatedAt(): ?\DateTimeInterface
  136.     {
  137.         return $this->createdAt;
  138.     }
  139.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  140.     {
  141.         $this->createdAt $createdAt;
  142.         return $this;
  143.     }
  144.     public function getUpdatedAt(): ?\DateTimeInterface
  145.     {
  146.         return $this->updatedAt;
  147.     }
  148.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  149.     {
  150.         $this->updatedAt $updatedAt;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return Collection<int, Address>
  155.      */
  156.     public function getAddresses(): Collection
  157.     {
  158.         return $this->addresses;
  159.     }
  160.     public function addAddress(Address $address): self
  161.     {
  162.         if (!$this->addresses->contains($address)) {
  163.             $this->addresses->add($address);
  164.             $address->setUser($this);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeAddress(Address $address): self
  169.     {
  170.         if ($this->addresses->removeElement($address)) {
  171.             // set the owning side to null (unless already changed)
  172.             if ($address->getUser() === $this) {
  173.                 $address->setUser(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Collection<int, BookAd>
  180.      */
  181.     public function getBookAds(): Collection
  182.     {
  183.         return $this->bookAds;
  184.     }
  185.     public function addBookAd(BookAd $bookAd): self
  186.     {
  187.         if (!$this->bookAds->contains($bookAd)) {
  188.             $this->bookAds->add($bookAd);
  189.             $bookAd->setUser($this);
  190.         }
  191.         return $this;
  192.     }
  193.     public function removeBookAd(BookAd $bookAd): self
  194.     {
  195.         if ($this->bookAds->removeElement($bookAd)) {
  196.             // set the owning side to null (unless already changed)
  197.             if ($bookAd->getUser() === $this) {
  198.                 $bookAd->setUser(null);
  199.             }
  200.         }
  201.         return $this;
  202.     }
  203.     public function getBasket(): ?Basket
  204.     {
  205.         return $this->basket;
  206.     }
  207.     public function setBasket(Basket $basket): self
  208.     {
  209.         // set the owning side of the relation if necessary
  210.         if ($basket->getUser() !== $this) {
  211.             $basket->setUser($this);
  212.         }
  213.         $this->basket $basket;
  214.         return $this;
  215.     }
  216. }