src/Entity/User.php line 22

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 Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @ApiResource(
  15.  *  normalizationContext={"groups"={"user:read"}},
  16.  *  denormalizationContext={"groups"={"user:write"}},
  17.  * )
  18.  */
  19. class User implements UserInterfacePasswordAuthenticatedUserInterface
  20. {
  21.     use TimestampableEntity;
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      * @Groups({"user:read"})
  27.      */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=180, unique=true)
  31.      * @Groups({"user:read", "user:write", "list_incoming_order"})
  32.      */
  33.     private $email;
  34.     /**
  35.      * @ORM\Column(type="json")
  36.      */
  37.     private $roles = [];
  38.     /**
  39.      * @var string The hashed password
  40.      * @ORM\Column(type="string")
  41.      */
  42.     private $password;
  43.     /**
  44.      * @ORM\Column(type="string", length=255)
  45.      * @Groups({"user:read", "user:write", "list_incoming_order"})
  46.      */
  47.     private $name;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=ProductImport::class, mappedBy="user")
  50.      */
  51.     private $productImports;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity=ProductOut::class, mappedBy="user")
  54.      */
  55.     private $productOuts;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=IncomingOrder::class, mappedBy="user")
  58.      */
  59.     private $incomingOrders;
  60.     public function __construct()
  61.     {
  62.         $this->productImports = new ArrayCollection();
  63.         $this->productOuts = new ArrayCollection();
  64.         $this->productIns = new ArrayCollection();
  65.         $this->incomingOrders = new ArrayCollection();
  66.     }
  67.     public function getId(): ?int
  68.     {
  69.         return $this->id;
  70.     }
  71.     public function getEmail(): ?string
  72.     {
  73.         return $this->email;
  74.     }
  75.     public function setEmail(string $email): self
  76.     {
  77.         $this->email $email;
  78.         return $this;
  79.     }
  80.     /**
  81.      * A visual identifier that represents this user.
  82.      *
  83.      * @see UserInterface
  84.      */
  85.     public function getUserIdentifier(): string
  86.     {
  87.         return (string) $this->email;
  88.     }
  89.     /**
  90.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  91.      */
  92.     public function getUsername(): string
  93.     {
  94.         return (string) $this->email;
  95.     }
  96.     /**
  97.      * @see UserInterface
  98.      */
  99.     public function getRoles(): array
  100.     {
  101.         $roles $this->roles;
  102.         // guarantee every user at least has ROLE_USER
  103.         $roles[] = 'ROLE_USER';
  104.         return array_unique($roles);
  105.     }
  106.     public function setRoles(array $roles): self
  107.     {
  108.         $this->roles $roles;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @see PasswordAuthenticatedUserInterface
  113.      */
  114.     public function getPassword(): string
  115.     {
  116.         return $this->password;
  117.     }
  118.     public function setPassword(string $password): self
  119.     {
  120.         $this->password $password;
  121.         return $this;
  122.     }
  123.     /**
  124.      * Returning a salt is only needed, if you are not using a modern
  125.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  126.      *
  127.      * @see UserInterface
  128.      */
  129.     public function getSalt(): ?string
  130.     {
  131.         return null;
  132.     }
  133.     /**
  134.      * @see UserInterface
  135.      */
  136.     public function eraseCredentials()
  137.     {
  138.         // If you store any temporary, sensitive data on the user, clear it here
  139.         // $this->plainPassword = null;
  140.     }
  141.     public function getName(): ?string
  142.     {
  143.         return $this->name;
  144.     }
  145.     public function setName(string $name): self
  146.     {
  147.         $this->name $name;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection|ProductImport[]
  152.      */
  153.     public function getProductImports(): Collection
  154.     {
  155.         return $this->productImports;
  156.     }
  157.     public function addProductImport(ProductImport $productImport): self
  158.     {
  159.         if (!$this->productImports->contains($productImport)) {
  160.             $this->productImports[] = $productImport;
  161.             $productImport->setUser($this);
  162.         }
  163.         return $this;
  164.     }
  165.     public function removeProductImport(ProductImport $productImport): self
  166.     {
  167.         if ($this->productImports->removeElement($productImport)) {
  168.             // set the owning side to null (unless already changed)
  169.             if ($productImport->getUser() === $this) {
  170.                 $productImport->setUser(null);
  171.             }
  172.         }
  173.         return $this;
  174.     }
  175.     /**
  176.      * @return Collection<int, ProductOut>
  177.      */
  178.     public function getProductOuts(): Collection
  179.     {
  180.         return $this->productOuts;
  181.     }
  182.     public function addProductOut(ProductOut $productOut): self
  183.     {
  184.         if (!$this->productOuts->contains($productOut)) {
  185.             $this->productOuts[] = $productOut;
  186.             $productOut->setUser($this);
  187.         }
  188.         return $this;
  189.     }
  190.     public function removeProductOut(ProductOut $productOut): self
  191.     {
  192.         if ($this->productOuts->removeElement($productOut)) {
  193.             // set the owning side to null (unless already changed)
  194.             if ($productOut->getUser() === $this) {
  195.                 $productOut->setUser(null);
  196.             }
  197.         }
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return Collection<int, IncomingOrder>
  202.      */
  203.     public function getIncomingOrder(): Collection
  204.     {
  205.         return $this->incomingOrders;
  206.     }
  207.     public function addOrderDate(IncomingOrder $incomingOrders): self
  208.     {
  209.         if (!$this->incomingOrders->contains($incomingOrders)) {
  210.             $this->incomingOrders[] = $incomingOrders;
  211.             $incomingOrders->setUserId($this);
  212.         }
  213.         return $this;
  214.     }
  215.     public function removeOrderDate(IncomingOrder $incomingOrders): self
  216.     {
  217.         if ($this->incomingOrders->removeElement($incomingOrders)) {
  218.             // set the owning side to null (unless already changed)
  219.             if ($incomingOrders->getUserId() === $this) {
  220.                 $incomingOrders->setUserId(null);
  221.             }
  222.         }
  223.         return $this;
  224.     }
  225. }