src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  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'There is already an account with this email')]
  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(type'boolean')]
  30.     private $isVerified false;
  31.     #[ORM\OneToMany(targetEntityNotification::class, mappedBy'user')]
  32.     private Collection $notifications;
  33.     #[ORM\ManyToMany(targetEntityShop::class, mappedBy'manager')]
  34.     private Collection $shops;
  35.     #[ORM\Column]
  36.     private ?DateTimeImmutable $createdAt null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $firstname null;
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $lastname null;
  41.     #[ORM\Column(length20nullabletrue)]
  42.     private ?string $gender null;
  43.     #[ORM\Column(length50nullabletrue)]
  44.     private ?string $kycStatus null;
  45.     #[ORM\Column(length255nullabletrue)]
  46.     private ?string $selfieSubmitted null;
  47.     #[ORM\Column(length255nullabletrue)]
  48.     private ?string $frontDocumentSubmitted null;
  49.     #[ORM\Column(length255nullabletrue)]
  50.     private ?string $backDocumentSubmitted null;
  51.     #[ORM\Column(nullabletrue)]
  52.     private ?DateTimeImmutable $kycSubmittedAt null;
  53.     #[ORM\Column(nullabletrue)]
  54.     private ?DateTimeImmutable $kycVerifiedAt null;
  55.     #[ORM\OneToMany(targetEntityAddress::class, mappedBy'user'cascade: ['persist''remove'])]
  56.     private Collection $addresses;
  57.     #[ORM\Column(length50nullabletrue)]
  58.     private ?string $phone null;
  59.     #[ORM\Column(length255nullabletrue)]
  60.     private ?string $profilePicture null;
  61.     #[ORM\Column(length255nullabletrue)]
  62.     private ?string $resetToken null;
  63.     #[ORM\Column(nullabletrue)]
  64.     private ?DateTimeImmutable $passwordRequestedAt null;
  65.     public function __construct()
  66.     {
  67.         $this->notifications = new ArrayCollection();
  68.         $this->shops = new ArrayCollection();
  69.         $this->addresses = new ArrayCollection();
  70.     }
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getEmail(): ?string
  76.     {
  77.         return $this->email;
  78.     }
  79.     public function setEmail(string $email): static
  80.     {
  81.         $this->email $email;
  82.         return $this;
  83.     }
  84.     /**
  85.      * A visual identifier that represents this user.
  86.      *
  87.      * @see UserInterface
  88.      */
  89.     public function getUserIdentifier(): string
  90.     {
  91.         return (string)$this->email;
  92.     }
  93.     /**
  94.      * @see UserInterface
  95.      */
  96.     public function getRoles(): array
  97.     {
  98.         $roles $this->roles;
  99.         // guarantee every user at least has ROLE_USER
  100.         $roles[] = 'ROLE_USER';
  101.         return array_unique($roles);
  102.     }
  103.     public function setRoles(array $roles): static
  104.     {
  105.         $this->roles $roles;
  106.         return $this;
  107.     }
  108.     /**
  109.      * @see PasswordAuthenticatedUserInterface
  110.      */
  111.     public function getPassword(): string
  112.     {
  113.         return $this->password;
  114.     }
  115.     public function setPassword(string $password): static
  116.     {
  117.         $this->password $password;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @see UserInterface
  122.      */
  123.     public function eraseCredentials(): void
  124.     {
  125.         // If you store any temporary, sensitive data on the user, clear it here
  126.         // $this->plainPassword = null;
  127.     }
  128.     public function isVerified(): bool
  129.     {
  130.         return $this->isVerified;
  131.     }
  132.     public function setIsVerified(bool $isVerified): static
  133.     {
  134.         $this->isVerified $isVerified;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @return Collection<int, Notification>
  139.      */
  140.     public function getNotifications(): Collection
  141.     {
  142.         return $this->notifications;
  143.     }
  144.     public function addNotification(Notification $notification): static
  145.     {
  146.         if (!$this->notifications->contains($notification)) {
  147.             $this->notifications->add($notification);
  148.             $notification->setUser($this);
  149.         }
  150.         return $this;
  151.     }
  152.     public function removeNotification(Notification $notification): static
  153.     {
  154.         if ($this->notifications->removeElement($notification)) {
  155.             // set the owning side to null (unless already changed)
  156.             if ($notification->getUser() === $this) {
  157.                 $notification->setUser(null);
  158.             }
  159.         }
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection<int, Shop>
  164.      */
  165.     public function getShops(): Collection
  166.     {
  167.         return $this->shops;
  168.     }
  169.     public function addShop(Shop $shop): static
  170.     {
  171.         if (!$this->shops->contains($shop)) {
  172.             $this->shops->add($shop);
  173.             $shop->addManager($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeShop(Shop $shop): static
  178.     {
  179.         if ($this->shops->removeElement($shop)) {
  180.             $shop->removeManager($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function getCreatedAt(): ?DateTimeImmutable
  185.     {
  186.         return $this->createdAt;
  187.     }
  188.     public function setCreatedAt(DateTimeImmutable $createdAt): static
  189.     {
  190.         $this->createdAt $createdAt;
  191.         return $this;
  192.     }
  193.     public function getFirstname(): ?string
  194.     {
  195.         return $this->firstname;
  196.     }
  197.     public function setFirstname(?string $firstname): static
  198.     {
  199.         $this->firstname $firstname;
  200.         return $this;
  201.     }
  202.     public function getLastname(): ?string
  203.     {
  204.         return $this->lastname;
  205.     }
  206.     public function setLastname(?string $lastname): static
  207.     {
  208.         $this->lastname $lastname;
  209.         return $this;
  210.     }
  211.     public function getGender(): ?string
  212.     {
  213.         return $this->gender;
  214.     }
  215.     public function setGender(?string $gender): static
  216.     {
  217.         $this->gender $gender;
  218.         return $this;
  219.     }
  220.     public function getSelfieSubmitted(): ?string
  221.     {
  222.         return $this->selfieSubmitted;
  223.     }
  224.     public function setSelfieSubmitted(?string $selfieSubmitted): static
  225.     {
  226.         $this->selfieSubmitted $selfieSubmitted;
  227.         return $this;
  228.     }
  229.     public function getFrontDocumentSubmitted(): ?string
  230.     {
  231.         return $this->frontDocumentSubmitted;
  232.     }
  233.     public function setFrontDocumentSubmitted(?string $frontDocumentSubmitted): static
  234.     {
  235.         $this->frontDocumentSubmitted $frontDocumentSubmitted;
  236.         return $this;
  237.     }
  238.     public function getBackDocumentSubmitted(): ?string
  239.     {
  240.         return $this->backDocumentSubmitted;
  241.     }
  242.     public function setBackDocumentSubmitted(?string $backDocumentSubmitted): static
  243.     {
  244.         $this->backDocumentSubmitted $backDocumentSubmitted;
  245.         return $this;
  246.     }
  247.     public function getKycSubmittedAt(): ?DateTimeImmutable
  248.     {
  249.         return $this->kycSubmittedAt;
  250.     }
  251.     public function setKycSubmittedAt(?DateTimeImmutable $kycSubmittedAt): static
  252.     {
  253.         $this->kycSubmittedAt $kycSubmittedAt;
  254.         return $this;
  255.     }
  256.     public function getKycVerifiedAt(): ?DateTimeImmutable
  257.     {
  258.         return $this->kycVerifiedAt;
  259.     }
  260.     public function setKycVerifiedAt(?DateTimeImmutable $kycVerifiedAt): static
  261.     {
  262.         $this->kycVerifiedAt $kycVerifiedAt;
  263.         return $this;
  264.     }
  265.     /**
  266.      * @return string|null
  267.      */
  268.     public function getKycStatus(): ?string
  269.     {
  270.         return $this->kycStatus;
  271.     }
  272.     /**
  273.      * @param string|null $kycStatus
  274.      */
  275.     public function setKycStatus(?string $kycStatus): void
  276.     {
  277.         $this->kycStatus $kycStatus;
  278.     }
  279.     /**
  280.      * @return Collection|Address[]
  281.      */
  282.     public function getAddresses(): Collection
  283.     {
  284.         return $this->addresses;
  285.     }
  286.     public function addAddress(Address $address): self
  287.     {
  288.         if (!$this->addresses->contains($address)) {
  289.             $this->addresses[] = $address;
  290.             $address->setUser($this);
  291.         }
  292.         return $this;
  293.     }
  294.     public function removeAddress(Address $address): self
  295.     {
  296.         if ($this->addresses->removeElement($address)) {
  297.             if ($address->getUser() === $this) {
  298.                 $address->setUser(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * Retourne l'adresse par défaut si définie
  305.      */
  306.     public function getDefaultAddress(): ?Address
  307.     {
  308.         foreach ($this->addresses as $address) {
  309.             if ($address->getIsDefault()) {
  310.                 return $address;
  311.             }
  312.         }
  313.         return null;
  314.     }
  315.     public function __toString(): string
  316.     {
  317.         return $this->getUserIdentifier();
  318.     }
  319.     public function getPhone(): ?string
  320.     {
  321.         return $this->phone;
  322.     }
  323.     public function setPhone(?string $phone): static
  324.     {
  325.         $this->phone $phone;
  326.         return $this;
  327.     }
  328.     public function getProfilePicture(): ?string
  329.     {
  330.         return $this->profilePicture;
  331.     }
  332.     public function setProfilePicture(?string $profilePicture): static
  333.     {
  334.         $this->profilePicture $profilePicture;
  335.         return $this;
  336.     }
  337.     public function getProfilePictureUrl(): string
  338.     {
  339.         if ($this->profilePicture) {
  340.             // Si c'est déjà une URL complète, la retourner telle quelle
  341.             if (str_starts_with($this->profilePicture'http')) {
  342.                 return $this->profilePicture;
  343.             }
  344.             // Sinon, retourner le chemin relatif
  345.             return $this->profilePicture;
  346.         }
  347.         // Image par défaut avec initiales
  348.         $initials '';
  349.         if ($this->firstname) {
  350.             $initials .= mb_substr($this->firstname01);
  351.         }
  352.         if ($this->lastname) {
  353.             $initials .= mb_substr($this->lastname01);
  354.         }
  355.         if (empty($initials) && $this->email) {
  356.             $initials mb_substr($this->email01);
  357.         }
  358.         return 'https://ui-avatars.com/api/?name=' urlencode($initials ?: 'U') . '&background=667eea&color=fff&size=200';
  359.     }
  360.     public function getResetToken(): ?string
  361.     {
  362.         return $this->resetToken;
  363.     }
  364.     public function setResetToken(?string $resetToken): static
  365.     {
  366.         $this->resetToken $resetToken;
  367.         return $this;
  368.     }
  369.     public function getPasswordRequestedAt(): ?DateTimeImmutable
  370.     {
  371.         return $this->passwordRequestedAt;
  372.     }
  373.     public function setPasswordRequestedAt(?DateTimeImmutable $passwordRequestedAt): static
  374.     {
  375.         $this->passwordRequestedAt $passwordRequestedAt;
  376.         return $this;
  377.     }
  378.     public function isPasswordRequestNonExpired(int $ttl 3600): bool
  379.     {
  380.         if ($this->passwordRequestedAt === null) {
  381.             return false;
  382.         }
  383.         $expirationDate $this->passwordRequestedAt->modify("+{$ttl} seconds");
  384.         return $expirationDate >= new DateTimeImmutable('now');
  385.     }
  386. }