src/Entity/User.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\UserRepository;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\Delete;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\Put;
  12. use Doctrine\Common\Collections\Collection;
  13. use Symfony\Component\HttpFoundation\File\File;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  20. #[ORM\Entity(repositoryClassUserRepository::class)]
  21. #[Vich\Uploadable]
  22. #[ORM\Table(name'`user`')]
  23. #[UniqueEntity(fields: ['email'], message"Il existe déjà un compte avec cette adresse e-mail.")]
  24. class User implements UserInterfacePasswordAuthenticatedUserInterface
  25. {
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column]
  29.     private ?int $id null;
  30.     #[ORM\Column(length180uniquetrue)]
  31.     private ?string $email null;
  32.     #[ORM\Column]
  33.     private array $roles = [];
  34.     /**
  35.      * @var string The hashed password
  36.      */
  37.     #[ORM\Column(nullabletrue)]
  38.     #[Groups(
  39.         [
  40.             'WRITE:USER'
  41.         ]
  42.     )]
  43.     private ?string $password null;
  44.     #[ORM\Column(length255nullabletrue)]
  45.     private ?string $firstname null;
  46.     #[ORM\Column(length255nullabletrue)]
  47.     private ?string $lastname null;
  48.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  49.     private ?\DateTimeInterface $createdAt null;
  50.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  51.     private ?\DateTimeInterface $updatedAt null;
  52.     #[ORM\Column(type'boolean')]
  53.     private $isVerified false;
  54.     #[ORM\Column(length255nullabletrue)]
  55.     private ?string $githubId null;
  56.     #[ORM\Column(length255nullabletrue)]
  57.     private ?string $googleId null;
  58.     #[ORM\Column(length255nullabletrue)]
  59.     private ?string $facebookId null;
  60.     #[ORM\Column(length255nullabletrue)]
  61.     private ?string $company null;
  62.     #[ORM\Column(length255nullabletrue)]
  63.     private ?string $phoneNumber null;
  64.     #[Vich\UploadableField(mapping'user_images'fileNameProperty'imageName'size'imageSize')]
  65.     private ?File $imageFile null;
  66.     #[ORM\Column(type'string'nullabletrue)]
  67.     private ?string $imageName null;
  68.     #[ORM\Column(type'integer'nullabletrue)]
  69.     private ?int $imageSize null;
  70.     #[ORM\Column(length255nullabletrue)]
  71.     private ?string $imageUrl null;
  72.     #[ORM\OneToMany(mappedBy'user'targetEntityFilesUser::class, orphanRemovaltrue)]
  73.     private Collection $filesUsers;
  74.     #[ORM\OneToMany(mappedBy'user'targetEntityFileEnrich::class, orphanRemovaltrue)]
  75.     private Collection $fileEnriches;
  76.     public function __construct()
  77.     {
  78.         $this->filesUsers = new ArrayCollection();
  79.         $this->fileEnriches = new ArrayCollection();
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getEmail(): ?string
  86.     {
  87.         return $this->email;
  88.     }
  89.     public function setEmail(string $email): self
  90.     {
  91.         $this->email $email;
  92.         return $this;
  93.     }
  94.     /**
  95.      * A visual identifier that represents this user.
  96.      *
  97.      * @see UserInterface
  98.      */
  99.     public function getUserIdentifier(): string
  100.     {
  101.         return (string) $this->email;
  102.     }
  103.     /**
  104.      * @see UserInterface
  105.      */
  106.     public function getRoles(): array
  107.     {
  108.         $roles $this->roles;
  109.         // guarantee every user at least has ROLE_USER
  110.         $roles[] = 'ROLE_USER';
  111.         return array_unique($roles);
  112.     }
  113.     public function setRoles(array $roles): self
  114.     {
  115.         $this->roles $roles;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @see PasswordAuthenticatedUserInterface
  120.      */
  121.     public function getPassword(): ?string
  122.     {
  123.         return $this->password;
  124.     }
  125.     public function setPassword(?string $password): self
  126.     {
  127.         $this->password $password;
  128.         return $this;
  129.     }
  130.     /**
  131.      * @see UserInterface
  132.      */
  133.     public function eraseCredentials()
  134.     {
  135.         // If you store any temporary, sensitive data on the user, clear it here
  136.         // $this->plainPassword = null;
  137.     }
  138.     public function getFirstname(): ?string
  139.     {
  140.         return $this->firstname;
  141.     }
  142.     public function setFirstname(string $firstname): self
  143.     {
  144.         $this->firstname $firstname;
  145.         return $this;
  146.     }
  147.     public function getLastname(): ?string
  148.     {
  149.         return $this->lastname;
  150.     }
  151.     public function setLastname(string $lastname): self
  152.     {
  153.         $this->lastname $lastname;
  154.         return $this;
  155.     }
  156.     public function getCreatedAt(): ?\DateTimeInterface
  157.     {
  158.         return $this->createdAt;
  159.     }
  160.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  161.     {
  162.         $this->createdAt $createdAt;
  163.         return $this;
  164.     }
  165.     public function getUpdatedAt(): ?\DateTimeInterface
  166.     {
  167.         return $this->updatedAt;
  168.     }
  169.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  170.     {
  171.         $this->updatedAt $updatedAt;
  172.         return $this;
  173.     }
  174.     public function isVerified(): bool
  175.     {
  176.         return $this->isVerified;
  177.     }
  178.     public function setIsVerified(bool $isVerified): self
  179.     {
  180.         $this->isVerified $isVerified;
  181.         return $this;
  182.     }
  183.     public function getGithubId(): ?string
  184.     {
  185.         return $this->githubId;
  186.     }
  187.     public function setGithubId(?string $githubId): self
  188.     {
  189.         $this->githubId $githubId;
  190.         return $this;
  191.     }
  192.     public function getGoogleId(): ?string
  193.     {
  194.         return $this->googleId;
  195.     }
  196.     public function setGoogleId(?string $googleId): self
  197.     {
  198.         $this->googleId $googleId;
  199.         return $this;
  200.     }
  201.     public function getFacebookId(): ?string
  202.     {
  203.         return $this->facebookId;
  204.     }
  205.     public function setFacebookId(?string $facebookId): self
  206.     {
  207.         $this->facebookId $facebookId;
  208.         return $this;
  209.     }
  210.     public function getCompany(): ?string
  211.     {
  212.         return $this->company;
  213.     }
  214.     public function setCompany(?string $company): self
  215.     {
  216.         $this->company $company;
  217.         return $this;
  218.     }
  219.     public function getPhoneNumber(): ?string
  220.     {
  221.         return $this->phoneNumber;
  222.     }
  223.     public function setPhoneNumber(?string $phoneNumber): self
  224.     {
  225.         $this->phoneNumber $phoneNumber;
  226.         return $this;
  227.     }
  228.     public function setImageFile(?File $imageFile null): void
  229.     {
  230.         $this->imageFile $imageFile;
  231.         if (null !== $imageFile) {
  232.             // It is required that at least one field changes if you are using doctrine
  233.             // otherwise the event listeners won't be called and the file is lost
  234.             $this->updatedAt = new \DateTimeImmutable();
  235.         }
  236.     }
  237.     public function getImageFile(): ?File
  238.     {
  239.         return $this->imageFile;
  240.     }
  241.     public function setImageName(?string $imageName): void
  242.     {
  243.         $this->imageName $imageName;
  244.     }
  245.     public function getImageName(): ?string
  246.     {
  247.         return $this->imageName;
  248.     }
  249.     public function setImageSize(?int $imageSize): void
  250.     {
  251.         $this->imageSize $imageSize;
  252.     }
  253.     public function getImageSize(): ?int
  254.     {
  255.         return $this->imageSize;
  256.     }
  257.     public function getImageUrl(): ?string
  258.     {
  259.         return $this->imageUrl;
  260.     }
  261.     public function setImageUrl(?string $imageUrl): self
  262.     {
  263.         $this->imageUrl $imageUrl;
  264.         return $this;
  265.     }
  266.     /**
  267.      * @return Collection<int, FilesUser>
  268.      */
  269.     public function getFilesUsers(): Collection
  270.     {
  271.         return $this->filesUsers;
  272.     }
  273.     public function addFilesUser(FilesUser $filesUser): self
  274.     {
  275.         if (!$this->filesUsers->contains($filesUser)) {
  276.             $this->filesUsers->add($filesUser);
  277.             $filesUser->setUser($this);
  278.         }
  279.         return $this;
  280.     }
  281.     public function removeFilesUser(FilesUser $filesUser): self
  282.     {
  283.         if ($this->filesUsers->removeElement($filesUser)) {
  284.             // set the owning side to null (unless already changed)
  285.             if ($filesUser->getUser() === $this) {
  286.                 $filesUser->setUser(null);
  287.             }
  288.         }
  289.         return $this;
  290.     }
  291.     /**
  292.      * @return Collection<int, FileEnrich>
  293.      */
  294.     public function getFileEnriches(): Collection
  295.     {
  296.         return $this->fileEnriches;
  297.     }
  298.     public function addFileEnrich(FileEnrich $fileEnrich): self
  299.     {
  300.         if (!$this->fileEnriches->contains($fileEnrich)) {
  301.             $this->fileEnriches->add($fileEnrich);
  302.             $fileEnrich->setUser($this);
  303.         }
  304.         return $this;
  305.     }
  306.     public function removeFileEnrich(FileEnrich $fileEnrich): self
  307.     {
  308.         if ($this->fileEnriches->removeElement($fileEnrich)) {
  309.             // set the owning side to null (unless already changed)
  310.             if ($fileEnrich->getUser() === $this) {
  311.                 $fileEnrich->setUser(null);
  312.             }
  313.         }
  314.         return $this;
  315.     }
  316. }