<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
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]
private ?string $password = null;
#[ORM\Column(length: 50)]
private ?string $fullName = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\OneToMany(mappedBy: 'utilisateur', targetEntity: EntreeStock::class)]
private Collection $entreeStocks;
#[ORM\OneToMany(mappedBy: 'utilisateur', targetEntity: SortieStock::class)]
private Collection $sortieStocks;
#[ORM\OneToMany(mappedBy: 'utilisateur', targetEntity: Produit::class)]
private Collection $produits;
#[ORM\Column(length: 255)]
private ?string $telephone = null;
#[ORM\Column(length: 255)]
private ?string $adress = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ActionLog::class)]
private Collection $actionLogs;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?Livreur $livreur = null;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Boutique $boutique = null;
public function __construct() {
$this->createdAt= new \DateTimeImmutable();
$this->entreeStocks = new ArrayCollection();
$this->sortieStocks = new ArrayCollection();
$this->produits = new ArrayCollection();
$this->actionLogs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$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
{
return array_unique($this->roles);
}
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFullName(): ?string
{
return $this->fullName;
}
public function setFullName(string $fullName): static
{
$this->fullName = $fullName;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, EntreeStock>
*/
public function getEntreeStocks(): Collection
{
return $this->entreeStocks;
}
public function addEntreeStock(EntreeStock $entreeStock): static
{
if (!$this->entreeStocks->contains($entreeStock)) {
$this->entreeStocks->add($entreeStock);
$entreeStock->setUtilisateur($this);
}
return $this;
}
public function removeEntreeStock(EntreeStock $entreeStock): static
{
if ($this->entreeStocks->removeElement($entreeStock)) {
// set the owning side to null (unless already changed)
if ($entreeStock->getUtilisateur() === $this) {
$entreeStock->setUtilisateur(null);
}
}
return $this;
}
/**
* @return Collection<int, SortieStock>
*/
public function getSortieStocks(): Collection
{
return $this->sortieStocks;
}
public function addSortieStock(SortieStock $sortieStock): static
{
if (!$this->sortieStocks->contains($sortieStock)) {
$this->sortieStocks->add($sortieStock);
$sortieStock->setUtilisateur($this);
}
return $this;
}
public function removeSortieStock(SortieStock $sortieStock): static
{
if ($this->sortieStocks->removeElement($sortieStock)) {
// set the owning side to null (unless already changed)
if ($sortieStock->getUtilisateur() === $this) {
$sortieStock->setUtilisateur(null);
}
}
return $this;
}
/**
* @return Collection<int, Produit>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produit $produit): static
{
if (!$this->produits->contains($produit)) {
$this->produits->add($produit);
$produit->setUtilisateur($this);
}
return $this;
}
public function removeProduit(Produit $produit): static
{
if ($this->produits->removeElement($produit)) {
// set the owning side to null (unless already changed)
if ($produit->getUtilisateur() === $this) {
$produit->setUtilisateur(null);
}
}
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): static
{
$this->telephone = $telephone;
return $this;
}
public function getAdress(): ?string
{
return $this->adress;
}
public function setAdress(string $adress): static
{
$this->adress = $adress;
return $this;
}
/**
* @return Collection<int, ActionLog>
*/
public function getActionLogs(): Collection
{
return $this->actionLogs;
}
public function addActionLog(ActionLog $actionLog): static
{
if (!$this->actionLogs->contains($actionLog)) {
$this->actionLogs->add($actionLog);
$actionLog->setUser($this);
}
return $this;
}
public function removeActionLog(ActionLog $actionLog): static
{
if ($this->actionLogs->removeElement($actionLog)) {
// set the owning side to null (unless already changed)
if ($actionLog->getUser() === $this) {
$actionLog->setUser(null);
}
}
return $this;
}
public function getLivreur(): ?Livreur
{
return $this->livreur;
}
public function setLivreur(Livreur $livreur): static
{
// set the owning side of the relation if necessary
if ($livreur->getUser() !== $this) {
$livreur->setUser($this);
}
$this->livreur = $livreur;
return $this;
}
public function getBoutique(): ?Boutique
{
return $this->boutique;
}
public function setBoutique(?Boutique $boutique): static
{
$this->boutique = $boutique;
return $this;
}
}