src/Entity/User.php line 15

  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'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(type'float'nullabletrue)]
  19.     private ?float $credit null;
  20.     #[ORM\Column(length180uniquetrue)]
  21.     private ?string $email null;
  22.     #[ORM\Column(length180)]
  23.     public ?string $name null;
  24.     #[ORM\OneToMany(mappedBy'user'targetEntityGallery::class, cascade: ["persist""remove"])]
  25.     protected ?Collection $gallery null;
  26.     #[ORM\OneToMany(mappedBy'user'targetEntityUserGallery::class, cascade: ["persist""remove"])]
  27.     protected ?Collection $userGallery null;
  28.     #[ORM\OneToMany(mappedBy'user'targetEntityUserTemplate::class, cascade: ["persist""remove"])]
  29.     protected ?Collection $userTemplate null;
  30.     #[ORM\Column(type'boolean'options: ['default' => true])]
  31.     private bool $isActive true;
  32.     #[ORM\Column]
  33.     private array $roles = [];
  34.     /**
  35.      * @var ?string The hashed password
  36.      */
  37.     #[ORM\Column]
  38.     private ?string $password '';
  39.     #[ORM\Column(type'boolean')]
  40.     private bool $isVerified false;
  41.     public function __toString(): string
  42.     {
  43.         if ($this->name){
  44.             return $this->name;
  45.         }else{
  46.             return '';
  47.         }
  48.     }
  49.     public function __construct()
  50.     {
  51.         $this->gallery = new ArrayCollection();
  52.         $this->userGallery = new ArrayCollection();
  53.         $this->userTemplate = new ArrayCollection();
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getEmail(): ?string
  60.     {
  61.         return $this->email;
  62.     }
  63.     public function setEmail(string $email): self
  64.     {
  65.         $this->email $email;
  66.         return $this;
  67.     }
  68.     /**
  69.      * A visual identifier that represents this user.
  70.      *
  71.      * @see UserInterface
  72.      */
  73.     public function getUserIdentifier(): string
  74.     {
  75.         return (string) $this->email;
  76.     }
  77.     /**
  78.      * @see UserInterface
  79.      */
  80.     public function getRoles(): array
  81.     {
  82.         $roles $this->roles;
  83.         // guarantee every user at least has ROLE_USER
  84.         $roles[] = 'ROLE_USER';
  85.         return array_unique($roles);
  86.     }
  87.     public function setRoles(array $roles): self
  88.     {
  89.         $this->roles $roles;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @see PasswordAuthenticatedUserInterface
  94.      */
  95.     public function getPassword(): ?string
  96.     {
  97.         return $this->password;
  98.     }
  99.     public function setPassword(?string $password): self
  100.     {
  101.         $this->password $password;
  102.         return $this;
  103.     }
  104.     /**
  105.      * @see UserInterface
  106.      */
  107.     public function eraseCredentials()
  108.     {
  109.         // If you store any temporary, sensitive data on the user, clear it here
  110.         // $this->plainPassword = null;
  111.     }
  112.     public function isVerified(): bool
  113.     {
  114.         return $this->isVerified;
  115.     }
  116.     public function setIsVerified(bool $isVerified): self
  117.     {
  118.         $this->isVerified $isVerified;
  119.         return $this;
  120.     }
  121.     public function isIsVerified(): ?bool
  122.     {
  123.         return $this->isVerified;
  124.     }
  125.     /**
  126.      * @return string|null
  127.      */
  128.     public function getName(): ?string
  129.     {
  130.         return $this->name;
  131.     }
  132.     /**
  133.      * @param string|null $name
  134.      */
  135.     public function setName(?string $name): void
  136.     {
  137.         $this->name $name;
  138.     }
  139.     /**
  140.      * @return Collection<int, Gallery>
  141.      */
  142.     public function getGallery(): Collection
  143.     {
  144.         return $this->gallery;
  145.     }
  146.     public function addGallery(Gallery $gallery): static
  147.     {
  148.         if (!$this->gallery->contains($gallery)) {
  149.             $this->gallery->add($gallery);
  150.             $gallery->setUser($this);
  151.         }
  152.         return $this;
  153.     }
  154.     public function removeGallery(Gallery $gallery): static
  155.     {
  156.         if ($this->gallery->removeElement($gallery)) {
  157.             // set the owning side to null (unless already changed)
  158.             if ($gallery->getUser() === $this) {
  159.                 $gallery->setUser(null);
  160.             }
  161.         }
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, UserGallery>
  166.      */
  167.     public function getUserGallery(): Collection
  168.     {
  169.         return $this->userGallery;
  170.     }
  171.     public function addUserGallery(UserGallery $userGallery): static
  172.     {
  173.         if (!$this->userGallery->contains($userGallery)) {
  174.             $this->userGallery->add($userGallery);
  175.             $userGallery->setUser($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeUserGallery(UserGallery $userGallery): static
  180.     {
  181.         if ($this->userGallery->removeElement($userGallery)) {
  182.             // set the owning side to null (unless already changed)
  183.             if ($userGallery->getUser() === $this) {
  184.                 $userGallery->setUser(null);
  185.             }
  186.         }
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return Collection<int, UserTemplate>
  191.      */
  192.     public function getUserTemplate(): Collection
  193.     {
  194.         return $this->userTemplate;
  195.     }
  196.     public function addUserTemplate(UserTemplate $userTemplate): static
  197.     {
  198.         if (!$this->userTemplate->contains($userTemplate)) {
  199.             $this->userTemplate->add($userTemplate);
  200.             $userTemplate->setUser($this);
  201.         }
  202.         return $this;
  203.     }
  204.     public function removeUserTemplate(UserTemplate $userTemplate): static
  205.     {
  206.         if ($this->userTemplate->removeElement($userTemplate)) {
  207.             // set the owning side to null (unless already changed)
  208.             if ($userTemplate->getUser() === $this) {
  209.                 $userTemplate->setUser(null);
  210.             }
  211.         }
  212.         return $this;
  213.     }
  214.     public function isActive(): bool
  215.     {
  216.         return $this->isActive;
  217.     }
  218.     public function getIsActive(): bool
  219.     {
  220.         return $this->isActive;
  221.     }
  222.     public function setIsActive(bool $isActive): self
  223.     {
  224.         $this->isActive $isActive;
  225.         return $this;
  226.     }
  227.     public function isIsActive(): ?bool
  228.     {
  229.         return $this->isActive;
  230.     }
  231.     /**
  232.      * @return float|null
  233.      */
  234.     public function getCredit(): ?float
  235.     {
  236.         return $this->credit;
  237.     }
  238.     /**
  239.      * @param float|null $credit
  240.      */
  241.     public function setCredit(?float $credit): void
  242.     {
  243.         $this->credit $credit;
  244.     }
  245. }