<?php
namespace App\Entity;
use App\Entity\Application\Points;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\ClientRepository")
* @ORM\EntityListeners({"App\Listener\EntityListener"})
* @Vich\Uploadable()
*/
class Client implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
/**
*
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("email")
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $type;
/**
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("firstName")
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $firstName;
/**
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("lastName")
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $lastName;
/**
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("zip")
* @ORM\Column(type="string", length=7, nullable=true)
*/
protected $zip;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Order", mappedBy="client")
*/
protected $orders;
/**
* @ORM\Column(type="datetime")
*/
protected $createts;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $registerApp;
/**
* @ORM\Column(type="string", nullable=true, length=2)
*/
protected $locale;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $editts;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
*/
protected $editUser;
/**
* @ORM\OneToMany(targetEntity=ClientAddress::class, cascade={"persist"}, mappedBy="client", orphanRemoval=true)
*/
private $clientAddresses;
/**
* @ORM\OneToOne(targetEntity=ClientAddress::class, cascade={"persist"})
*/
private $billingAddress;
/**
* @ORM\OneToOne(targetEntity=ClientAddress::class, cascade={"persist"})
*/
private $deliveryAddress;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $hasDeliveryAddress = false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\RecentlyProduct", mappedBy="client")
* @ORM\OrderBy({"createts"="DESC"})
*/
private $recentlyProducts;
/**
* @ORM\OneToMany(targetEntity=Cart::class, mappedBy="client")
*/
private $carts;
/**
* @var string Tokeny
* @ORM\Column(type="string", nullable=true)
*/
private $confirmToken;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = true;
/**
* @ORM\Column(type="boolean")
*/
private $isBlocked = false;
/**
* @ORM\OneToMany(targetEntity=ClientToken::class, mappedBy="client", orphanRemoval=true, cascade={"all"})
*/
private $clientTokens;
/**
* @Vich\UploadableField(mapping="avatar_image", fileNameProperty="avatar")
* @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg", "image/gif"})
* @var File|null
*/
private $avatarFile;
/**
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("avatar")
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatar;
/**
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("birthdate")
* @ORM\Column(type="datetime", nullable=true)
*/
protected $birthdate;
/**
* Telefon z Appky
*
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("phone")
* @ORM\Column(type="text", nullable=true)
*/
protected $phone;
/**
* Body
*
* @Serializer\Groups({"api","min"})
* @Serializer\SerializedName("points")
* @ORM\Column(type="integer", nullable=true)
*/
protected $points = 0;
/**
* @Serializer\Groups({"pointsHistory"})
* @Serializer\SerializedName("pointsHistory")
* @ORM\OneToMany(targetEntity=Points::class, mappedBy="client", orphanRemoval=true)
* @ORM\OrderBy({"createts"="DESC"})
*/
private $pointsHistory;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->clientAddresses = new ArrayCollection();
$this->recentlyProducts = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->clientTokens = new ArrayCollection();
$this->pointsHistory = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function createApiToken( )
{
return new ClientToken($this);
}
/**
* Get Email
*
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* Set Email
*
* @param mixed $email
*/
public function setEmail( $email )
{
$this->email = $email;
}
public function getFullName()
{
return sprintf( '%s %s', $this->getLastName(), $this->getFirstName() );
}
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;
}
/**
* @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->setClient( $this );
}
return $this;
}
public function removeOrder( Order $order ): self
{
if ( $this->orders->contains( $order ) ) {
$this->orders->removeElement( $order );
// set the owning side to null (unless already changed)
if ( $order->getClient() === $this ) {
$order->setClient( null );
}
}
return $this;
}
public function getCreatets(): ?\DateTimeInterface
{
return $this->createts;
}
public function setCreatets( \DateTimeInterface $createts ): self
{
$this->createts = $createts;
return $this;
}
public function getEditts(): ?\DateTimeInterface
{
return $this->editts;
}
public function setEditts( ?\DateTimeInterface $editts ): self
{
$this->editts = $editts;
return $this;
}
public function getEditUser(): ?User
{
return $this->editUser;
}
public function setEditUser( ?User $editUser ): self
{
$this->editUser = $editUser;
return $this;
}
/**
* Get Type
*
* @return mixed
*/
public function getType()
{
return $this->type;
}
/**
* Set Type
*
* @param mixed $type
*/
public function setType( $type )
{
$this->type = $type;
}
/**
* @return Collection|ClientAddress[]
*/
public function getClientAddresses(): Collection
{
return $this->clientAddresses;
}
public function addClientAddress(ClientAddress $clientAddress): self
{
if (!$this->clientAddresses->contains($clientAddress)) {
$this->clientAddresses[] = $clientAddress;
$clientAddress->setClient($this);
}
return $this;
}
public function removeClientAddress(ClientAddress $clientAddress): self
{
if ($this->clientAddresses->contains($clientAddress)) {
$this->clientAddresses->removeElement($clientAddress);
// set the owning side to null (unless already changed)
if ($clientAddress->getClient() === $this) {
$clientAddress->setClient(null);
}
}
return $this;
}
public function getBillingAddress(): ?ClientAddress
{
return $this->billingAddress;
}
public function setBillingAddress( ?ClientAddress $billingAddress ): self
{
$this->billingAddress = $billingAddress;
return $this;
}
public function getDeliveryAddress(): ?ClientAddress
{
return $this->deliveryAddress;
}
public function setDeliveryAddress( ?ClientAddress $deliveryAddress ): self
{
$this->deliveryAddress = $deliveryAddress;
return $this;
}
/**
* @return Collection|RecentlyProduct[]
*/
public function getRecentlyProducts(): Collection
{
return $this->recentlyProducts->slice( 0, 10 );
}
public function addRecentlyProduct( RecentlyProduct $recentlyProduct ): self
{
if ( !$this->recentlyProducts->contains( $recentlyProduct ) ) {
$this->recentlyProducts[] = $recentlyProduct;
$recentlyProduct->setClient( $this );
}
return $this;
}
public function removeRecentlyProduct( RecentlyProduct $recentlyProduct ): self
{
if ( $this->recentlyProducts->contains( $recentlyProduct ) ) {
$this->recentlyProducts->removeElement( $recentlyProduct );
// set the owning side to null (unless already changed)
if ( $recentlyProduct->getClient() === $this ) {
$recentlyProduct->setClient( null );
}
}
return $this;
}
/**
* @return Collection|Cart[]
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart( Cart $cart ): self
{
if ( !$this->carts->contains( $cart ) ) {
$this->carts[] = $cart;
$cart->setClient( $this );
}
return $this;
}
public function removeCart( Cart $cart ): self
{
if ( $this->carts->contains( $cart ) ) {
$this->carts->removeElement( $cart );
// set the owning side to null (unless already changed)
if ( $cart->getClient() === $this ) {
$cart->setClient( null );
}
}
return $this;
}
/**
* addRoles -
*
* @param $role
*/
public function addRoles( $role )
{
$roles = $this->roles;
$roles[] = $role;
$this->setRoles( array_unique( $roles ) );
}
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;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->email;
}
/**
* Get LastLogin
*
* @return mixed
*/
public function getLastLogin()
{
return $this->lastLogin;
}
/**
* Set LastLogin
*
* @param mixed $lastLogin
*/
public function setLastLogin( $lastLogin )
{
$this->lastLogin = $lastLogin;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified( bool $isVerified ): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* Get ConfirmToken
*
* @return string
*/
public function getConfirmToken()
{
return $this->confirmToken;
}
/**
* Set ConfirmToken
*
* @param string $confirmToken
*/
public function setConfirmToken( $confirmToken )
{
$this->confirmToken = $confirmToken;
}
/**
* Get HasDeliveryAddress
*
* @return mixed
*/
public function getHasDeliveryAddress()
{
return $this->hasDeliveryAddress;
}
/**
* Set HasDeliveryAddress
*
* @param mixed $hasDeliveryAddress
*/
public function setHasDeliveryAddress( $hasDeliveryAddress )
{
$this->hasDeliveryAddress = $hasDeliveryAddress;
}
/**
* @return Collection|ClientToken[]
*/
public function getClientTokens(): Collection
{
return $this->clientTokens;
}
public function addClientToken(ClientToken $clientToken): self
{
if (!$this->clientTokens->contains($clientToken)) {
$this->clientTokens[] = $clientToken;
$clientToken->setClient($this);
}
return $this;
}
public function removeClientToken(ClientToken $clientToken): self
{
if ($this->clientTokens->removeElement($clientToken)) {
// set the owning side to null (unless already changed)
if ($clientToken->getClient() === $this) {
$clientToken->setClient(null);
}
}
return $this;
}
/**
* Get Avatar
*
* @return mixed
*/
public function getAvatar()
{
return $this->avatar;
}
/**
* Set Avatar
*
* @param mixed $avatar
*/
public function setAvatar( $avatar )
{
$this->avatar = $avatar;
}
/**
* Get AvatarFile
*
* @return null|File
*/
public function getAvatarFile(): ?File
{
return $this->avatarFile;
}
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $avatarFile
*/
public function setAvatarFile(?File $avatarFile = null): void
{
$this->avatarFile = $avatarFile;
if (null !== $avatarFile) {
$this->editts = new \DateTime();
}
}
/**
* Get Birthdate
*
* @return mixed
*/
public function getBirthdate()
{
return $this->birthdate;
}
/**
* Set Birthdate
*
* @param mixed $birthdate
*/
public function setBirthdate( $birthdate )
{
if(!$birthdate instanceof \DateTime && $birthdate !== null){
$birthdate = (new \DateTime($birthdate))->setTime(12,12,12);
}
$this->birthdate = $birthdate;
}
/**
* Get Phone
*
* @return mixed
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set Phone
*
* @param mixed $phone
*/
public function setPhone( $phone )
{
$this->phone = $phone;
}
/**
* Get Points
*
* @return mixed
*/
public function getPoints()
{
return $this->points;
}
/**
* Set Points
*
* @param mixed $points
*/
public function setPoints( $points )
{
$this->points = $points;
}
/**
* Add Points
*
* @param mixed $points
*/
public function addPoints( $points )
{
$this->points = $this->getPoints()+$points;
}
/**
* @return Collection|Points[]
*/
public function getPointsHistory(): Collection
{
return $this->pointsHistory;
}
public function addPointsHistory(Points $pointsHistory): self
{
if (!$this->pointsHistory->contains($pointsHistory)) {
$this->pointsHistory[] = $pointsHistory;
$pointsHistory->setClient($this);
}
return $this;
}
public function removePointsHistory(Points $pointsHistory): self
{
if ($this->pointsHistory->removeElement($pointsHistory)) {
// set the owning side to null (unless already changed)
if ($pointsHistory->getClient() === $this) {
$pointsHistory->setClient(null);
}
}
return $this;
}
/**
* Get RegisterApp
*
* @return mixed
*/
public function getRegisterApp()
{
return $this->registerApp;
}
/**
* Set RegisterApp
*
* @param mixed $registerApp
*/
public function setRegisterApp( $registerApp )
{
$this->registerApp = $registerApp;
}
/**
* @return bool
*/
public function isBlocked(): bool
{
return $this->isBlocked;
}
/**
* @param bool $isBlocked
*/
public function setIsBlocked(bool $isBlocked): void
{
$this->isBlocked = $isBlocked;
}
/**
* @return mixed
*/
public function getZip()
{
return $this->zip;
}
/**
* @param mixed $zip
*/
public function setZip($zip): void
{
$this->zip = $zip;
}
/**
* @return mixed
*/
public function getLocale()
{
return $this->locale;
}
/**
* @param mixed $locale
*/
public function setLocale($locale): void
{
$this->locale = $locale;
}
}