src/Entity/User.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @ApiResource(
  15.  *     collectionOperations={"get","post"},
  16.  *     itemOperations={"get","put","delete"},
  17.  *     normalizationContext={"groups"={"user"}},
  18.  *     denormalizationContext={"groups"={"user"}},
  19.  *     attributes={"pagination_enabled"=false}
  20.  * )
  21.  */
  22. class User implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      * @Groups("user")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=180, unique=true)
  33.      * @Groups("user")
  34.      * @Assert\NotBlank()
  35.      * @Assert\Email()
  36.      */
  37.     private $email;
  38.     /**
  39.      * @ORM\Column(type="json")
  40.      */
  41.     private $roles = [];
  42.     /**
  43.      * @var string The hashed password
  44.      * @ORM\Column(type="string")
  45.      */
  46.     private $password;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, nullable=true)
  49.      * @Groups("user")
  50.      */
  51.     private $lastname;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      * @Groups("user")
  55.      */
  56.     private $firstname;
  57.     /**
  58.      * @ORM\Column(type="boolean")
  59.      * @Groups("user")
  60.      */
  61.     private $isActive;
  62.     /**
  63.      * @ORM\Column(type="string", length=255)
  64.      * @Groups("user")
  65.      */
  66.     private $lang;
  67.     /**
  68.      * @ORM\Column(type="boolean")
  69.      * @Groups("user")
  70.      */
  71.     private $isNew;
  72.     /**
  73.      * @ORM\Column(type="integer")
  74.      * @Groups("user")
  75.      */
  76.     private $rateCode;
  77.     /**
  78.      * @ORM\Column(type="string", length=255)
  79.      * @Groups("user")
  80.      * @Groups("order")
  81.      */
  82.     private $customerId;
  83.     /**
  84.      * @ORM\Column(type="integer")
  85.      * @Groups("user")
  86.      * @Groups("order")
  87.      */
  88.     private $deliveryAddressId;
  89.     /**
  90.      * @ORM\Column(type="string", length=255)
  91.      * @Groups("user")
  92.      */
  93.     private $customerName;
  94.     /**
  95.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
  96.      */
  97.     private $orders;
  98.     /**
  99.      * @ORM\Column(type="string", length=255, nullable=true)
  100.      */
  101.     private $passwordRequest;
  102.     /**
  103.      * @ORM\Column(type="boolean", nullable=true)
  104.      * @Groups("user")
  105.      */
  106.     private $isShippingCost;
  107.     /**
  108.      * @ORM\Column(type="float", nullable=true)
  109.      * @Groups("user")
  110.      */
  111.     private $minOrder;
  112.     /**
  113.      * @ORM\Column(type="float", nullable=true)
  114.      * @Groups("user")
  115.      */
  116.     private $shippingCosts;
  117.     /**
  118.      * @ORM\Column(type="boolean")
  119.      * @Groups("user")
  120.      */
  121.     private $isAdminCustomer;
  122.     /**
  123.      * @ORM\Column(type="boolean")
  124.      * @Groups("user")
  125.      */
  126.     private $defaultUser;
  127.     /**
  128.      * @ORM\Column(type="boolean")
  129.      * @Groups("user")
  130.      */
  131.     private $internalCustomer;
  132.     public function __construct()
  133.     {
  134.         $this->orders = new ArrayCollection();
  135.     }
  136.     public function getId(): ?int
  137.     {
  138.         return $this->id;
  139.     }
  140.     public function getEmail(): ?string
  141.     {
  142.         return $this->email;
  143.     }
  144.     public function setEmail(string $email): self
  145.     {
  146.         $this->email $email;
  147.         return $this;
  148.     }
  149.     /**
  150.      * A visual identifier that represents this user.
  151.      *
  152.      * @see UserInterface
  153.      */
  154.     public function getUsername(): string
  155.     {
  156.         return (string) $this->email;
  157.     }
  158.     /**
  159.      * @see UserInterface
  160.      */
  161.     public function getRoles(): array
  162.     {
  163.         $roles $this->roles;
  164.         // guarantee every user at least has ROLE_USER
  165.         $roles[] = 'ROLE_USER';
  166.         return array_unique($roles);
  167.     }
  168.     public function setRoles(array $roles): self
  169.     {
  170.         $this->roles $roles;
  171.         return $this;
  172.     }
  173.     /**
  174.      * @see UserInterface
  175.      */
  176.     public function getPassword(): string
  177.     {
  178.         return (string) $this->password;
  179.     }
  180.     public function setPassword(string $password): self
  181.     {
  182.         $this->password $password;
  183.         return $this;
  184.     }
  185.     /**
  186.      * Returning a salt is only needed, if you are not using a modern
  187.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  188.      *
  189.      * @see UserInterface
  190.      */
  191.     public function getSalt(): ?string
  192.     {
  193.         return null;
  194.     }
  195.     /**
  196.      * @see UserInterface
  197.      */
  198.     public function eraseCredentials()
  199.     {
  200.         // If you store any temporary, sensitive data on the user, clear it here
  201.         // $this->plainPassword = null;
  202.     }
  203.     public function getLastname(): ?string
  204.     {
  205.         return $this->lastname;
  206.     }
  207.     public function setLastname(string $lastname): self
  208.     {
  209.         $this->lastname $lastname;
  210.         return $this;
  211.     }
  212.     public function getFirstname(): ?string
  213.     {
  214.         return $this->firstname;
  215.     }
  216.     public function setFirstname(string $firstname): self
  217.     {
  218.         $this->firstname $firstname;
  219.         return $this;
  220.     }
  221.     public function getIsActive(): ?bool
  222.     {
  223.         return $this->isActive;
  224.     }
  225.     public function setIsActive(bool $isActive): self
  226.     {
  227.         $this->isActive $isActive;
  228.         return $this;
  229.     }
  230.     public function getLang(): ?string
  231.     {
  232.         return $this->lang;
  233.     }
  234.     public function setLang(string $lang): self
  235.     {
  236.         $this->lang $lang;
  237.         return $this;
  238.     }
  239.     public function getIsNew(): ?bool
  240.     {
  241.         return $this->isNew;
  242.     }
  243.     public function setIsNew(bool $isNew): self
  244.     {
  245.         $this->isNew $isNew;
  246.         return $this;
  247.     }
  248.     public function getRateCode(): ?int
  249.     {
  250.         return $this->rateCode;
  251.     }
  252.     public function setRateCode(int $rateCode): self
  253.     {
  254.         $this->rateCode $rateCode;
  255.         return $this;
  256.     }
  257.     public function getCustomerId(): ?string
  258.     {
  259.         return $this->customerId;
  260.     }
  261.     public function setCustomerId(string $customerId): self
  262.     {
  263.         $this->customerId $customerId;
  264.         return $this;
  265.     }
  266.     public function getDeliveryAddressId(): ?int
  267.     {
  268.         return $this->deliveryAddressId;
  269.     }
  270.     public function setDeliveryAddressId(int $deliveryAddressId): self
  271.     {
  272.         $this->deliveryAddressId $deliveryAddressId;
  273.         return $this;
  274.     }
  275.     public function getCustomerName(): ?string
  276.     {
  277.         return $this->customerName;
  278.     }
  279.     public function setCustomerName(string $customerName): self
  280.     {
  281.         $this->customerName $customerName;
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return Collection|Order[]
  286.      */
  287.     public function getOrders(): Collection
  288.     {
  289.         return $this->orders;
  290.     }
  291.     public function addOrder(Order $order): self
  292.     {
  293.         if (!$this->orders->contains($order)) {
  294.             $this->orders[] = $order;
  295.             $order->setUser($this);
  296.         }
  297.         return $this;
  298.     }
  299.     public function removeOrder(Order $order): self
  300.     {
  301.         if ($this->orders->removeElement($order)) {
  302.             // set the owning side to null (unless already changed)
  303.             if ($order->getUser() === $this) {
  304.                 $order->setUser(null);
  305.             }
  306.         }
  307.         return $this;
  308.     }
  309.     public function getPasswordRequest(): ?string
  310.     {
  311.         return $this->passwordRequest;
  312.     }
  313.     public function setPasswordRequest(?string $passwordRequest): self
  314.     {
  315.         $this->passwordRequest $passwordRequest;
  316.         return $this;
  317.     }
  318.     public function getIsShippingCost(): ?bool
  319.     {
  320.         return $this->isShippingCost;
  321.     }
  322.     public function setIsPromotion(?bool $isShippingCost): self
  323.     {
  324.         $this->isShippingCost $isShippingCost;
  325.         return $this;
  326.     }
  327.     public function getMinOrder(): ?float
  328.     {
  329.         return $this->minOrder;
  330.     }
  331.     public function setMinOrder(?float $minOrder): self
  332.     {
  333.         $this->minOrder $minOrder;
  334.         return $this;
  335.     }
  336.     public function getShippingCosts(): ?float
  337.     {
  338.         return $this->shippingCosts;
  339.     }
  340.     public function setShippingCosts(?float $shippingCosts): self
  341.     {
  342.         $this->shippingCosts $shippingCosts;
  343.         return $this;
  344.     }
  345.     public function getIsAdminCustomer(): ?bool
  346.     {
  347.         return $this->isAdminCustomer;
  348.     }
  349.     public function setIsAdminCustomer(bool $isAdminCustomer): self
  350.     {
  351.         $this->isAdminCustomer $isAdminCustomer;
  352.         return $this;
  353.     }
  354.     public function getDefaultUser(): ?bool
  355.     {
  356.         return $this->defaultUser;
  357.     }
  358.     public function setDefaultUser(bool $defaultUser): self
  359.     {
  360.         $this->defaultUser $defaultUser;
  361.         return $this;
  362.     }
  363.     public function isInternalCustomer(): ?bool
  364.     {
  365.         return $this->internalCustomer;
  366.     }
  367.     public function setInternalCustomer(bool $internalCustomer): self
  368.     {
  369.         $this->internalCustomer $internalCustomer;
  370.         return $this;
  371.     }
  372.     public function getUserIdentifier(): string
  373.     {
  374.         return (string) $this->email;
  375.     }
  376. }