<?php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[Vich\Uploadable]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(fields: ['email'], message: "Il existe déjà un compte avec cette adresse e-mail.")]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column(nullable: true)]
#[Groups(
[
'WRITE:USER'
]
)]
private ?string $password = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $firstname = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastname = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updatedAt = null;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(length: 255, nullable: true)]
private ?string $githubId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $googleId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $facebookId = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $company = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $phoneNumber = null;
#[Vich\UploadableField(mapping: 'user_images', fileNameProperty: 'imageName', size: 'imageSize')]
private ?File $imageFile = null;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $imageName = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $imageSize = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $imageUrl = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: FilesUser::class, orphanRemoval: true)]
private Collection $filesUsers;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: FileEnrich::class, orphanRemoval: true)]
private Collection $fileEnriches;
public function __construct()
{
$this->filesUsers = new ArrayCollection();
$this->fileEnriches = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(?string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getGithubId(): ?string
{
return $this->githubId;
}
public function setGithubId(?string $githubId): self
{
$this->githubId = $githubId;
return $this;
}
public function getGoogleId(): ?string
{
return $this->googleId;
}
public function setGoogleId(?string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
public function getCompany(): ?string
{
return $this->company;
}
public function setCompany(?string $company): self
{
$this->company = $company;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getImageUrl(): ?string
{
return $this->imageUrl;
}
public function setImageUrl(?string $imageUrl): self
{
$this->imageUrl = $imageUrl;
return $this;
}
/**
* @return Collection<int, FilesUser>
*/
public function getFilesUsers(): Collection
{
return $this->filesUsers;
}
public function addFilesUser(FilesUser $filesUser): self
{
if (!$this->filesUsers->contains($filesUser)) {
$this->filesUsers->add($filesUser);
$filesUser->setUser($this);
}
return $this;
}
public function removeFilesUser(FilesUser $filesUser): self
{
if ($this->filesUsers->removeElement($filesUser)) {
// set the owning side to null (unless already changed)
if ($filesUser->getUser() === $this) {
$filesUser->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, FileEnrich>
*/
public function getFileEnriches(): Collection
{
return $this->fileEnriches;
}
public function addFileEnrich(FileEnrich $fileEnrich): self
{
if (!$this->fileEnriches->contains($fileEnrich)) {
$this->fileEnriches->add($fileEnrich);
$fileEnrich->setUser($this);
}
return $this;
}
public function removeFileEnrich(FileEnrich $fileEnrich): self
{
if ($this->fileEnriches->removeElement($fileEnrich)) {
// set the owning side to null (unless already changed)
if ($fileEnrich->getUser() === $this) {
$fileEnrich->setUser(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->firstname . ' ' . $this->lastname;
}
}