src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  */
  13. #[UniqueEntity(fields: ['name'], message'There is already an account with this name')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity=Partner::class)
  38.      */
  39.     private $partner;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private $email;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      */
  47.     private $nameSurname;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=Partner::class, mappedBy="keeper")
  50.      */
  51.     private $partners;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity=Zamowienia::class, mappedBy="user")
  54.      */
  55.     private $zamowienias;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=Purchaser::class, mappedBy="user")
  58.      */
  59.     private $purchasers;
  60.     /**
  61.      * @ORM\Column(type="datetime", nullable=true)
  62.      */
  63.     private $lastLogin;
  64.     /**
  65.      * @ORM\Column(type="boolean")
  66.      */
  67.     private $www;
  68.     public function __construct()
  69.     {
  70.         $this->partners = new ArrayCollection();
  71.         $this->zamowienias = new ArrayCollection();
  72.         $this->purchasers = new ArrayCollection();
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getName(): ?string
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function setName(string $name): self
  83.     {
  84.         $this->name $name;
  85.         return $this;
  86.     }
  87.     /**
  88.      * A visual identifier that represents this user.
  89.      *
  90.      * @see UserInterface
  91.      */
  92.     public function getUserIdentifier(): string
  93.     {
  94.         return (string) $this->name;
  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.         //dd(array_unique($roles));
  105.         return array_unique($roles);
  106.     }
  107.     public function setRoles(array $roles): self
  108.     {
  109.         $this->roles $roles;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @see PasswordAuthenticatedUserInterface
  114.      */
  115.     public function getPassword(): string
  116.     {
  117.         return $this->password;
  118.     }
  119.     public function setPassword(string $password): self
  120.     {
  121.         $this->password $password;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @see UserInterface
  126.      */
  127.     public function eraseCredentials()
  128.     {
  129.         // If you store any temporary, sensitive data on the user, clear it here
  130.         // $this->plainPassword = null;
  131.         $this->roles = [];
  132.     }
  133.     public function __toString(): string
  134.        {
  135.             return $this->name;
  136.         }
  137.     public function getLastLogin() {
  138.         return $this->lastLogin;
  139.     }
  140.     public function getPartner(): ?Partner
  141.     {
  142.         return $this->partner;
  143.     }
  144.     public function setPartner(?Partner $partner): self
  145.     {
  146.         $this->partner $partner;
  147.         
  148.         return $this;
  149.     }
  150.     public function getEmail(): ?string
  151.     {
  152.         return $this->email;
  153.     }
  154.     public function setEmail(?string $email): self
  155.     {
  156.         $this->email $email;
  157.         return $this;
  158.     }
  159.     public function getNameSurname(): ?string
  160.     {
  161.         return $this->nameSurname;
  162.     }
  163.     public function setNameSurname(?string $nameSurname): self
  164.     {
  165.         $this->nameSurname $nameSurname;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return Collection<int, Partner>
  170.      */
  171.     public function getPartners(): Collection
  172.     {
  173.         return $this->partners;
  174.     }
  175.     public function addPartner(Partner $partner): self
  176.     {
  177.         if (!$this->partners->contains($partner)) {
  178.             $this->partners[] = $partner;
  179.             $partner->setKeeper($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removePartner(Partner $partner): self
  184.     {
  185.         if ($this->partners->removeElement($partner)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($partner->getKeeper() === $this) {
  188.                 $partner->setKeeper(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection<int, Zamowienia>
  195.      */
  196.     public function getZamowienias(): Collection
  197.     {
  198.         return $this->zamowienias;
  199.     }
  200.     public function addZamowienia(Zamowienia $zamowienia): self
  201.     {
  202.         if (!$this->zamowienias->contains($zamowienia)) {
  203.             $this->zamowienias[] = $zamowienia;
  204.             $zamowienia->setUser($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeZamowienia(Zamowienia $zamowienia): self
  209.     {
  210.         if ($this->zamowienias->removeElement($zamowienia)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($zamowienia->getUser() === $this) {
  213.                 $zamowienia->setUser(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     /**
  219.      * @return Collection<int, Purchaser>
  220.      */
  221.     public function getPurchasers(): Collection
  222.     {
  223.         return $this->purchasers;
  224.     }
  225.     public function addPurchaser(Purchaser $purchaser): self
  226.     {
  227.         if (!$this->purchasers->contains($purchaser)) {
  228.             $this->purchasers[] = $purchaser;
  229.             $purchaser->setUser($this);
  230.         }
  231.         return $this;
  232.     }
  233.     public function removePurchaser(Purchaser $purchaser): self
  234.     {
  235.         if ($this->purchasers->removeElement($purchaser)) {
  236.             // set the owning side to null (unless already changed)
  237.             if ($purchaser->getUser() === $this) {
  238.                 $purchaser->setUser(null);
  239.             }
  240.         }
  241.         return $this;
  242.     }
  243.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  244.     {
  245.         $this->lastLogin $lastLogin;
  246.         return $this;
  247.     }
  248.     public function isWww(): ?bool
  249.     {
  250.         return $this->www;
  251.     }
  252.     public function setWww(bool $www): self
  253.     {
  254.         $this->www $www;
  255.         return $this;
  256.     }
  257. }