src/Entity/User.php line 19
<?php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Collections\Collection;
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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[Vich\Uploadable]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups("shop_browse")]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column(type: 'json')]
private $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 255)]
#[Groups("shop_browse")]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
// START IMAGE
#[Vich\UploadableField(mapping: 'user_images', fileNameProperty: 'imageNameUser')]
private ?File $picture = null;
#[ORM\Column(nullable: true)]
private ?string $imageNameUser = null;
#[ORM\Column(length: 64)]
private ?string $phoneNumber = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $about = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $updatedAt = null;
/*#[ORM\ManyToMany(targetEntity: Shop::class, inversedBy: 'users', cascade: ["persist"])]
#[ORM\JoinTable(name: "user_shop")]
#[Groups("shop_browse")]
private Collection $shops;*/
#[ORM\OneToMany(mappedBy: 'users', targetEntity: Shop::class, cascade: ["persist"])]
#[Groups("shop_browse")]
private Collection $shops;
public function __construct()
{
$this->shops = 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;
}
// PICTURE ------ DEBUT DE L'UTILISATION DE VICH ---------------------------
/**
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $picture
*/
public function setPicture(?File $picture = null): void
{
$this->picture = $picture;
/*if (null !== $picture) {
// 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 getPicture(): ?File
{
return $this->picture;
}
public function setImageNameUser(?string $imageNameUser): void
{
$this->imageNameUser = $imageNameUser;
}
public function getImageNameUser(): ?string
{
return $this->imageNameUser;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/*
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(string $picture): self
{
$this->picture = $picture;
return $this;
}
*/
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getAbout(): ?string
{
return $this->about;
}
public function setAbout(?string $about): self
{
$this->about = $about;
return $this;
}
/**
* @return Collection<int, Shop>
*/
public function getShops(): Collection
{
return $this->shops;
}
public function addShop(Shop $shop): self
{
if (!$this->shops->contains($shop)) {
$this->shops->add($shop);
$shop->setUsers($this);
}
return $this;
}
public function removeShop(Shop $shop): self
{
if ($this->shops->removeElement($shop)) {
// set the owning side to null (unless already changed)
if ($shop->getUsers() === $this) {
$shop->setUsers(null);
}
}
return $this;
}
}