<?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 Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ApiResource(
* collectionOperations={"get","post"},
* itemOperations={"get","put","delete"},
* normalizationContext={"groups"={"user"}},
* denormalizationContext={"groups"={"user"}},
* attributes={"pagination_enabled"=false}
* )
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups("user")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Groups("user")
* @Assert\NotBlank()
* @Assert\Email()
*/
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, nullable=true)
* @Groups("user")
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups("user")
*/
private $firstname;
/**
* @ORM\Column(type="boolean")
* @Groups("user")
*/
private $isActive;
/**
* @ORM\Column(type="string", length=255)
* @Groups("user")
*/
private $lang;
/**
* @ORM\Column(type="boolean")
* @Groups("user")
*/
private $isNew;
/**
* @ORM\Column(type="integer")
* @Groups("user")
*/
private $rateCode;
/**
* @ORM\Column(type="string", length=255)
* @Groups("user")
* @Groups("order")
*/
private $customerId;
/**
* @ORM\Column(type="integer")
* @Groups("user")
* @Groups("order")
*/
private $deliveryAddressId;
/**
* @ORM\Column(type="string", length=255)
* @Groups("user")
*/
private $customerName;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
*/
private $orders;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $passwordRequest;
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups("user")
*/
private $isShippingCost;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups("user")
*/
private $minOrder;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups("user")
*/
private $shippingCosts;
/**
* @ORM\Column(type="boolean")
* @Groups("user")
*/
private $isAdminCustomer;
/**
* @ORM\Column(type="boolean")
* @Groups("user")
*/
private $defaultUser;
/**
* @ORM\Column(type="boolean")
* @Groups("user")
*/
private $internalCustomer;
public function __construct()
{
$this->orders = 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 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 UserInterface
*/
public function getPassword(): string
{
return (string) $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 getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getLang(): ?string
{
return $this->lang;
}
public function setLang(string $lang): self
{
$this->lang = $lang;
return $this;
}
public function getIsNew(): ?bool
{
return $this->isNew;
}
public function setIsNew(bool $isNew): self
{
$this->isNew = $isNew;
return $this;
}
public function getRateCode(): ?int
{
return $this->rateCode;
}
public function setRateCode(int $rateCode): self
{
$this->rateCode = $rateCode;
return $this;
}
public function getCustomerId(): ?string
{
return $this->customerId;
}
public function setCustomerId(string $customerId): self
{
$this->customerId = $customerId;
return $this;
}
public function getDeliveryAddressId(): ?int
{
return $this->deliveryAddressId;
}
public function setDeliveryAddressId(int $deliveryAddressId): self
{
$this->deliveryAddressId = $deliveryAddressId;
return $this;
}
public function getCustomerName(): ?string
{
return $this->customerName;
}
public function setCustomerName(string $customerName): self
{
$this->customerName = $customerName;
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
public function getPasswordRequest(): ?string
{
return $this->passwordRequest;
}
public function setPasswordRequest(?string $passwordRequest): self
{
$this->passwordRequest = $passwordRequest;
return $this;
}
public function getIsShippingCost(): ?bool
{
return $this->isShippingCost;
}
public function setIsPromotion(?bool $isShippingCost): self
{
$this->isShippingCost = $isShippingCost;
return $this;
}
public function getMinOrder(): ?float
{
return $this->minOrder;
}
public function setMinOrder(?float $minOrder): self
{
$this->minOrder = $minOrder;
return $this;
}
public function getShippingCosts(): ?float
{
return $this->shippingCosts;
}
public function setShippingCosts(?float $shippingCosts): self
{
$this->shippingCosts = $shippingCosts;
return $this;
}
public function getIsAdminCustomer(): ?bool
{
return $this->isAdminCustomer;
}
public function setIsAdminCustomer(bool $isAdminCustomer): self
{
$this->isAdminCustomer = $isAdminCustomer;
return $this;
}
public function getDefaultUser(): ?bool
{
return $this->defaultUser;
}
public function setDefaultUser(bool $defaultUser): self
{
$this->defaultUser = $defaultUser;
return $this;
}
public function isInternalCustomer(): ?bool
{
return $this->internalCustomer;
}
public function setInternalCustomer(bool $internalCustomer): self
{
$this->internalCustomer = $internalCustomer;
return $this;
}
public function getUserIdentifier(): string
{
return (string) $this->email;
}
}