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.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  13.  */
  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 $email;
  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.      * @ORM\Column(type="boolean")
  37.      */
  38.     private $isVerified false;
  39.     /**
  40.      * @ORM\Column(type="string", length=150)
  41.      */
  42.     private $lname;
  43.     /**
  44.      * @ORM\Column(type="string", length=150)
  45.      */
  46.     private $fname;
  47.     /**
  48.      * @ORM\Column(type="string", length=150, nullable=true)
  49.      */
  50.     private $adress;
  51.     /**
  52.      * @ORM\Column(type="string", length=13)
  53.      */
  54.     private $phone;
  55.     /**
  56.      * @ORM\Column(type="string", length=100, nullable=true)
  57.      */
  58.     private $profilePicture;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity=City::class, inversedBy="users")
  61.      * @ORM\JoinColumn(nullable=false)
  62.      */
  63.     private $city;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=Article::class, mappedBy="user")
  66.      */
  67.     private $articles;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity=UserCategory::class, inversedBy="users")
  70.      */
  71.     private $category;
  72.     public function __construct()
  73.     {
  74.         $this->articles = new ArrayCollection();
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getEmail(): ?string
  81.     {
  82.         return $this->email;
  83.     }
  84.     public function setEmail(string $email): self
  85.     {
  86.         $this->email $email;
  87.         return $this;
  88.     }
  89.     /**
  90.      * A visual identifier that represents this user.
  91.      *
  92.      * @see UserInterface
  93.      */
  94.     public function getUserIdentifier(): string
  95.     {
  96.         return (string) $this->email;
  97.     }
  98.     /**
  99.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  100.      */
  101.     public function getUsername(): string
  102.     {
  103.         return (string) $this->email;
  104.     }
  105.     /**
  106.      * @see UserInterface
  107.      */
  108.     public function getRoles(): array
  109.     {
  110.         $roles $this->roles;
  111.         // guarantee every user at least has ROLE_USER
  112.         $roles[] = 'ROLE_USER';
  113.         return array_unique($roles);
  114.     }
  115.     public function setRoles(array $roles): self
  116.     {
  117.         $this->roles $roles;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @see PasswordAuthenticatedUserInterface
  122.      */
  123.     public function getPassword(): string
  124.     {
  125.         return $this->password;
  126.     }
  127.     public function setPassword(string $password): self
  128.     {
  129.         $this->password $password;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Returning a salt is only needed, if you are not using a modern
  134.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  135.      *
  136.      * @see UserInterface
  137.      */
  138.     public function getSalt(): ?string
  139.     {
  140.         return null;
  141.     }
  142.     /**
  143.      * @see UserInterface
  144.      */
  145.     public function eraseCredentials()
  146.     {
  147.         // If you store any temporary, sensitive data on the user, clear it here
  148.         // $this->plainPassword = null;
  149.     }
  150.     public function isVerified(): bool
  151.     {
  152.         return $this->isVerified;
  153.     }
  154.     public function setIsVerified(bool $isVerified): self
  155.     {
  156.         $this->isVerified $isVerified;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return mixed
  161.      */
  162.     public function getLname()
  163.     {
  164.         return $this->lname;
  165.     }
  166.     /**
  167.      * @param mixed $lname
  168.      */
  169.     public function setLname($lname): void
  170.     {
  171.         $this->lname $lname;
  172.     }
  173.     /**
  174.      * @return mixed
  175.      */
  176.     public function getFname()
  177.     {
  178.         return $this->fname;
  179.     }
  180.     /**
  181.      * @param mixed $fname
  182.      */
  183.     public function setFname($fname): void
  184.     {
  185.         $this->fname $fname;
  186.     }
  187.     /**
  188.      * @return mixed
  189.      */
  190.     public function getAdress()
  191.     {
  192.         return $this->adress;
  193.     }
  194.     /**
  195.      * @param mixed $adress
  196.      */
  197.     public function setAdress($adress): void
  198.     {
  199.         $this->adress $adress;
  200.     }
  201.     /**
  202.      * @return mixed
  203.      */
  204.     public function getPhone()
  205.     {
  206.         return $this->phone;
  207.     }
  208.     /**
  209.      * @param mixed $phone
  210.      */
  211.     public function setPhone($phone): void
  212.     {
  213.         $this->phone $phone;
  214.     }
  215.     /**
  216.      * @return mixed
  217.      */
  218.     public function getProfilePicture()
  219.     {
  220.         return $this->profilePicture;
  221.     }
  222.     /**
  223.      * @param mixed $profilePicture
  224.      */
  225.     public function setProfilePicture($profilePicture): void
  226.     {
  227.         $this->profilePicture $profilePicture;
  228.     }
  229.     /**
  230.      * @return mixed
  231.      */
  232.     public function getCity()
  233.     {
  234.         return $this->city;
  235.     }
  236.     /**
  237.      * @param mixed $city
  238.      */
  239.     public function setCity($city): void
  240.     {
  241.         $this->city $city;
  242.     }
  243.     /**
  244.      * @return Collection<int, Article>
  245.      */
  246.     public function getArticles(): Collection
  247.     {
  248.         return $this->articles;
  249.     }
  250.     public function addArticle(Article $article): self
  251.     {
  252.         if (!$this->articles->contains($article)) {
  253.             $this->articles[] = $article;
  254.             $article->setUser($this);
  255.         }
  256.         return $this;
  257.     }
  258.     public function removeArticle(Article $article): self
  259.     {
  260.         if ($this->articles->removeElement($article)) {
  261.             // set the owning side to null (unless already changed)
  262.             if ($article->getUser() === $this) {
  263.                 $article->setUser(null);
  264.             }
  265.         }
  266.         return $this;
  267.     }
  268.     public function getCategory(): ?UserCategory
  269.     {
  270.         return $this->category;
  271.     }
  272.     public function setCategory(?UserCategory $category): self
  273.     {
  274.         $this->category $category;
  275.         return $this;
  276.     }
  277. }