src/Entity/User.php line 16

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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserRepository::class)
  11.  * @ORM\Table(name="app_user")
  12.  */
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private ?int $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255, nullable=true)
  23.      */
  24.     private ?string $name;
  25.     /**
  26.      * @ORM\Column(type="datetime_immutable", nullable=true, options={"default": "CURRENT_TIMESTAMP"})
  27.      */
  28.     private $createAt;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private ?string $telegramId;
  33.     /**
  34.      * @ORM\Column(type="string", length=255, nullable=true)
  35.      */
  36.     private ?string $phone;
  37.     /**
  38.      * @ORM\OneToMany(targetEntity=QuestionnaireResult::class, mappedBy="user")
  39.      */
  40.     private $questionnaireResults;
  41.     /**
  42.      * @ORM\Column(type="boolean", nullable=true)
  43.      */
  44.     private $isAdmin;
  45.     /**
  46.      * @ORM\Column(type="boolean", nullable=true, options={"default": false})
  47.      */
  48.     private ?bool $isBanned false;
  49.     /**
  50.      * @ORM\Column(type="string", length=180, unique=true, nullable=true)
  51.      */
  52.     private ?string $email;
  53.     /**
  54.      * @ORM\Column(type="string", length=180, nullable=true)
  55.      */
  56.     private ?string $city;
  57.     /**
  58.      * @ORM\Column(type="json", nullable=true)
  59.      */
  60.     private ?array $roles null;
  61.     /**
  62.      * @var string The hashed password
  63.      * @ORM\Column(type="string", nullable=true)
  64.      */
  65.     private string $password;
  66.     /**
  67.      * @ORM\Column(type="string", length=255, nullable=true)
  68.      */
  69.     private ?string $brandsHistory null;
  70.     public function __construct()
  71.     {
  72.         $this->questionnaireResults = new ArrayCollection();
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function __toString(): string
  79.     {
  80.         return $this->getPhone().", ".$this->getName();
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->name;
  85.     }
  86.     public function setName(?string $name): self
  87.     {
  88.         $this->name $name;
  89.         return $this;
  90.     }
  91.     public function getCreateAt(): ?\DateTimeImmutable
  92.     {
  93.         return $this->createAt;
  94.     }
  95.     public function setCreateAt(\DateTimeInterface $createAt): self
  96.     {
  97.         $this->createAt $createAt;
  98.         return $this;
  99.     }
  100.     public function getTelegramId(): ?string
  101.     {
  102.         return $this->telegramId;
  103.     }
  104.     public function setTelegramId(?string $telegramId): self
  105.     {
  106.         $this->telegramId $telegramId;
  107.         return $this;
  108.     }
  109.     public function getPhone(): ?string
  110.     {
  111.         return $this->phone;
  112.     }
  113.     public function setPhone(?string $phone): self
  114.     {
  115.         $this->phone $phone;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, QuestionnaireResult>
  120.      */
  121.     public function getQuestionnaireResults(): Collection
  122.     {
  123.         return $this->questionnaireResults;
  124.     }
  125.     public function addQuestionnaireResult(QuestionnaireResult $questionnaireResult): self
  126.     {
  127.         if (!$this->questionnaireResults->contains($questionnaireResult)) {
  128.             $this->questionnaireResults[] = $questionnaireResult;
  129.             $questionnaireResult->setUser($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeQuestionnaireResult(QuestionnaireResult $questionnaireResult): self
  134.     {
  135.         if ($this->questionnaireResults->removeElement($questionnaireResult)) {
  136.             // set the owning side to null (unless already changed)
  137.             if ($questionnaireResult->getUser() === $this) {
  138.                 $questionnaireResult->setUser(null);
  139.             }
  140.         }
  141.         return $this;
  142.     }
  143.     public function isIsAdmin(): ?bool
  144.     {
  145.         return $this->isAdmin;
  146.     }
  147.     public function setIsAdmin(?bool $isAdmin): self
  148.     {
  149.         $this->isAdmin $isAdmin;
  150.         return $this;
  151.     }
  152.     public function isBanned(): ?bool
  153.     {
  154.         return $this->isBanned;
  155.     }
  156.     public function setIsBanned(?bool $isBanned): self
  157.     {
  158.         $this->isBanned $isBanned;
  159.         return $this;
  160.     }
  161.     public function getEmail(): ?string
  162.     {
  163.         return $this->email;
  164.     }
  165.     public function setEmail(string $email): self
  166.     {
  167.         $this->email $email;
  168.         return $this;
  169.     }
  170.     /**
  171.      * A visual identifier that represents this user.
  172.      *
  173.      * @see UserInterface
  174.      */
  175.     public function getUserIdentifier(): string
  176.     {
  177.         return (string) $this->email;
  178.     }
  179.     /**
  180.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  181.      */
  182.     public function getUsername(): string
  183.     {
  184.         return (string) $this->email;
  185.     }
  186.     /**
  187.      * @see UserInterface
  188.      */
  189.     public function getRoles(): array
  190.     {
  191.         $roles $this->roles;
  192.         // guarantee every user at least has ROLE_USER
  193.         $roles[] = 'ROLE_USER';
  194.         return array_unique($roles);
  195.     }
  196.     public function setRoles(array $roles): self
  197.     {
  198.         $this->roles $roles;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @see PasswordAuthenticatedUserInterface
  203.      */
  204.     public function getPassword(): string
  205.     {
  206.         return $this->password;
  207.     }
  208.     public function setPassword(string $password): self
  209.     {
  210.         $this->password $password;
  211.         return $this;
  212.     }
  213.     /**
  214.      * Returning a salt is only needed, if you are not using a modern
  215.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  216.      *
  217.      * @see UserInterface
  218.      */
  219.     public function getSalt(): ?string
  220.     {
  221.         return null;
  222.     }
  223.     /**
  224.      * @see UserInterface
  225.      */
  226.     public function eraseCredentials()
  227.     {
  228.         // If you store any temporary, sensitive data on the user, clear it here
  229.         // $this->plainPassword = null;
  230.     }
  231.     public function getCity(): ?string
  232.     {
  233.         return $this->city;
  234.     }
  235.     public function setCity(?string $city): self
  236.     {
  237.         $this->city $city;
  238.         return $this;
  239.     }
  240.     public function getBrandsHistory(): ?string
  241.     {
  242.         return $this->brandsHistory;
  243.     }
  244.     public function setBrandsHistory(?string $brandsHistory): self
  245.     {
  246.         $this->brandsHistory $brandsHistory;
  247.         return $this;
  248.     }
  249. }