src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  11.  * @ORM\Table(name="users")
  12.  * @UniqueEntity(fields={"username"}, message="Det här användarnamnet är ogiltigt eller används redan")
  13.  * @UniqueEntity(fields={"email"}, message="Den här e-postadressen är ogiltigt eller används redan")
  14.  */
  15. class User implements UserInterface
  16. {
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      */
  26.     private $username;
  27.     /**
  28.      * @ORM\Column(type="json")
  29.      */
  30.     private $roles = [];
  31.     /**
  32.      * @var string The hashed password
  33.      * @ORM\Column(type="string")
  34.      */
  35.     private $password;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private $firstname;
  40.     /**
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $lastname;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, unique=true)
  46.      * @Assert\Email
  47.      */
  48.     private $email;
  49.     /**
  50.      * @ORM\Column(type="boolean")
  51.      */
  52.     private $authenticated false;
  53.     /**
  54.      * @ORM\OneToOne(targetEntity="App\Entity\Image", cascade={"persist", "remove"})
  55.      */
  56.     private $image;
  57.     /**
  58.      * @ORM\Column(type="integer")
  59.      */
  60.     private $houseNumber 0;
  61.     /**
  62.      * @ORM\Column(type="datetime", nullable=true)
  63.      */
  64.     private $created;
  65.     /**
  66.      * @ORM\Column(type="datetime", nullable=true)
  67.      */
  68.     private $lastLogin;
  69.     /**
  70.      * @ORM\Column(type="datetime", nullable=true)
  71.      */
  72.     private $lastActive;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="seller", orphanRemoval=true)
  75.      */
  76.     private $products;
  77.     /**
  78.      * @ORM\Column(type="string", length=255)
  79.      */
  80.     private $address '';
  81.     public function __construct()
  82.     {
  83.         $this->products = new ArrayCollection();
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUsername(): string
  95.     {
  96.         return (string) $this->username;
  97.     }
  98.     public function setUsername(string $username): self
  99.     {
  100.         $this->username $username;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @see UserInterface
  105.      */
  106.     public function getRoles(): array
  107.     {
  108.         $roles $this->roles;
  109.         // guarantee every user at least has ROLE_USER
  110.         $roles[] = 'ROLE_USER';
  111.         return array_unique($roles);
  112.     }
  113.     public function setRoles(array $roles): self
  114.     {
  115.         $this->roles $roles;
  116.         return $this;
  117.     }
  118.     public function hasRole($role): bool
  119.     {
  120.         return in_array($role$this->getRoles());
  121.     }
  122.     /**
  123.      * @see UserInterface
  124.      */
  125.     public function getPassword(): string
  126.     {
  127.         return (string) $this->password;
  128.     }
  129.     public function setPassword(string $password): self
  130.     {
  131.         $this->password $password;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @see UserInterface
  136.      */
  137.     public function getSalt()
  138.     {
  139.         // not needed when using the "bcrypt" algorithm in security.yaml
  140.     }
  141.     /**
  142.      * @see UserInterface
  143.      */
  144.     public function eraseCredentials()
  145.     {
  146.         // If you store any temporary, sensitive data on the user, clear it here
  147.         // $this->plainPassword = null;
  148.     }
  149.     public function getFirstname(): ?string
  150.     {
  151.         return $this->firstname;
  152.     }
  153.     public function setFirstname(string $firstname): self
  154.     {
  155.         $this->firstname $firstname;
  156.         return $this;
  157.     }
  158.     public function getLastname(): ?string
  159.     {
  160.         return $this->lastname;
  161.     }
  162.     public function setLastname(string $lastname): self
  163.     {
  164.         $this->lastname $lastname;
  165.         return $this;
  166.     }
  167.     public function getFullname(): ?string {
  168.         return $this->getFirstname() . ' ' $this->getLastname();
  169.     }
  170.     public function getEmail(): ?string
  171.     {
  172.         return $this->email;
  173.     }
  174.     public function setEmail(string $email): self
  175.     {
  176.         $this->email $email;
  177.         return $this;
  178.     }
  179.     public function getAuthenticated(): ?bool
  180.     {
  181.         return $this->authenticated;
  182.     }
  183.     public function setAuthenticated(bool $authenticated): self
  184.     {
  185.         $this->authenticated $authenticated;
  186.         return $this;
  187.     }
  188.     public function getImage(): ?Image
  189.     {
  190.         return $this->image;
  191.     }
  192.     public function setImage(?Image $image): self
  193.     {
  194.         $this->image $image;
  195.         return $this;
  196.     }
  197.     public function getHouseNumber(): ?int
  198.     {
  199.         return $this->houseNumber;
  200.     }
  201.     public function setHouseNumber(int $houseNumber): self
  202.     {
  203.         $this->houseNumber $houseNumber;
  204.         return $this;
  205.     }
  206.     public function getCreated(): ?\DateTimeInterface
  207.     {
  208.         return $this->created;
  209.     }
  210.     public function setCreated(?\DateTimeInterface $created): self
  211.     {
  212.         $this->created $created;
  213.         return $this;
  214.     }
  215.     public function getLastLogin(): ?\DateTimeInterface
  216.     {
  217.         return $this->lastLogin;
  218.     }
  219.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  220.     {
  221.         $this->lastLogin $lastLogin;
  222.         return $this;
  223.     }
  224.     public function getLastActive(): ?\DateTimeInterface
  225.     {
  226.         return $this->lastActive;
  227.     }
  228.     public function setLastActive(?\DateTimeInterface $lastActive): self
  229.     {
  230.         $this->lastActive $lastActive;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection|Product[]
  235.      */
  236.     public function getProducts(): Collection
  237.     {
  238.         return $this->products;
  239.     }
  240.     public function addProduct(Product $product): self
  241.     {
  242.         if (!$this->products->contains($product)) {
  243.             $this->products[] = $product;
  244.             $product->setSeller($this);
  245.         }
  246.         return $this;
  247.     }
  248.     public function removeProduct(Product $product): self
  249.     {
  250.         if ($this->products->contains($product)) {
  251.             $this->products->removeElement($product);
  252.             // set the owning side to null (unless already changed)
  253.             if ($product->getSeller() === $this) {
  254.                 $product->setSeller(null);
  255.             }
  256.         }
  257.         return $this;
  258.     }
  259.     public function getAddress(): ?string
  260.     {
  261.         return $this->address;
  262.     }
  263.     public function setAddress(string $address): self
  264.     {
  265.         $this->address $address;
  266.         return $this;
  267.     }
  268. }