<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ApiResource(
* normalizationContext={"groups"={"user:read"}},
* denormalizationContext={"groups"={"user:write"}},
* )
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"user:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Groups({"user:read", "user:write", "list_incoming_order"})
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"user:read", "user:write", "list_incoming_order"})
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=ProductImport::class, mappedBy="user")
*/
private $productImports;
/**
* @ORM\OneToMany(targetEntity=ProductOut::class, mappedBy="user")
*/
private $productOuts;
/**
* @ORM\OneToMany(targetEntity=IncomingOrder::class, mappedBy="user")
*/
private $incomingOrders;
public function __construct()
{
$this->productImports = new ArrayCollection();
$this->productOuts = new ArrayCollection();
$this->productIns = new ArrayCollection();
$this->incomingOrders = 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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): 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;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return Collection|ProductImport[]
*/
public function getProductImports(): Collection
{
return $this->productImports;
}
public function addProductImport(ProductImport $productImport): self
{
if (!$this->productImports->contains($productImport)) {
$this->productImports[] = $productImport;
$productImport->setUser($this);
}
return $this;
}
public function removeProductImport(ProductImport $productImport): self
{
if ($this->productImports->removeElement($productImport)) {
// set the owning side to null (unless already changed)
if ($productImport->getUser() === $this) {
$productImport->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductOut>
*/
public function getProductOuts(): Collection
{
return $this->productOuts;
}
public function addProductOut(ProductOut $productOut): self
{
if (!$this->productOuts->contains($productOut)) {
$this->productOuts[] = $productOut;
$productOut->setUser($this);
}
return $this;
}
public function removeProductOut(ProductOut $productOut): self
{
if ($this->productOuts->removeElement($productOut)) {
// set the owning side to null (unless already changed)
if ($productOut->getUser() === $this) {
$productOut->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, IncomingOrder>
*/
public function getIncomingOrder(): Collection
{
return $this->incomingOrders;
}
public function addOrderDate(IncomingOrder $incomingOrders): self
{
if (!$this->incomingOrders->contains($incomingOrders)) {
$this->incomingOrders[] = $incomingOrders;
$incomingOrders->setUserId($this);
}
return $this;
}
public function removeOrderDate(IncomingOrder $incomingOrders): self
{
if ($this->incomingOrders->removeElement($incomingOrders)) {
// set the owning side to null (unless already changed)
if ($incomingOrders->getUserId() === $this) {
$incomingOrders->setUserId(null);
}
}
return $this;
}
}