src/Entity/Users.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UsersRepository;
  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=UsersRepository::class)
  12.  */
  13. #[UniqueEntity(fields: ['username'], message'There is already an account with this username')]
  14. class Users implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  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\OneToMany(targetEntity=Tickets::class, mappedBy="user")
  38.      */
  39.     private $tickets;
  40.     /**
  41.      * @ORM\ManyToOne(targetEntity=Roles::class, inversedBy="users")
  42.      */
  43.     private $userRole;
  44.     /**
  45.      * @ORM\Column(type="string", length=255)
  46.      */
  47.     private $name;
  48.     /**
  49.      * @ORM\Column(type="boolean")
  50.      */
  51.     private $active;
  52.     /**
  53.      * @ORM\Column(type="string", length=255, nullable=true)
  54.      */
  55.     private $tokens;
  56.     /**
  57.      * @ORM\Column(type="datetime", nullable=true)
  58.      */
  59.     private $created_at;
  60.     /**
  61.      * @ORM\Column(type="datetime", nullable=true)
  62.      */
  63.     private $updated_at;
  64.     /**
  65.      * @ORM\Column(type="string", length=255, nullable=true)
  66.      */
  67.     private $photo;
  68.     public function __construct()
  69.     {
  70.         $this->tickets = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getUsername(): ?string
  77.     {
  78.         return $this->username;
  79.     }
  80.     public function setUsername(string $username): self
  81.     {
  82.         $this->username $username;
  83.         return $this;
  84.     }
  85.     
  86.     public function getRoles(): array
  87.     {
  88.         $roles $this->roles;
  89.         // guarantee every user at least has ROLE_USER
  90.         $roles[] = 'ROLE_USER';
  91.         return array_unique($roles);
  92.     }
  93.     public function setRoles(array $roles): self
  94.     {
  95.         $this->roles $roles;
  96.         return $this;
  97.     }
  98.     /**
  99.      * A visual identifier that represents this user.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getUserIdentifier(): string
  104.     {
  105.         return (string) $this->username;
  106.     }
  107.     /**
  108.      * @see PasswordAuthenticatedUserInterface
  109.      */
  110.     public function getPassword(): string
  111.     {
  112.         return $this->password;
  113.     }
  114.     public function setPassword(string $password): self
  115.     {
  116.         $this->password $password;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @see UserInterface
  121.      */
  122.     public function eraseCredentials()
  123.     {
  124.         // If you store any temporary, sensitive data on the user, clear it here
  125.         // $this->plainPassword = null;
  126.     }
  127.     /**
  128.      * @return Collection<int, Tickets>
  129.      */
  130.     public function getTickets(): Collection
  131.     {
  132.         return $this->tickets;
  133.     }
  134.     public function addTicket(Tickets $ticket): self
  135.     {
  136.         if (!$this->tickets->contains($ticket)) {
  137.             $this->tickets[] = $ticket;
  138.             $ticket->setUser($this);
  139.         }
  140.         return $this;
  141.     }
  142.     public function removeTicket(Tickets $ticket): self
  143.     {
  144.         if ($this->tickets->removeElement($ticket)) {
  145.             // set the owning side to null (unless already changed)
  146.             if ($ticket->getUser() === $this) {
  147.                 $ticket->setUser(null);
  148.             }
  149.         }
  150.         return $this;
  151.     }
  152.     
  153.     public function getUserRole(): ?Roles
  154.     {
  155.         return $this->userRole;
  156.     }
  157.     public function setUserRole(?Roles $userRole): self
  158.     {
  159.         $this->userRole $userRole;
  160.         return $this;
  161.     }
  162.     public function getName(): ?string
  163.     {
  164.         return $this->name;
  165.     }
  166.     public function setName(string $name): self
  167.     {
  168.         $this->name $name;
  169.         return $this;
  170.     }
  171.     public function isActive(): ?bool
  172.     {
  173.         return $this->active;
  174.     }
  175.     public function setActive(bool $active): self
  176.     {
  177.         $this->active $active;
  178.         return $this;
  179.     }
  180.     public function getToken(): ?string
  181.     {
  182.         return $this->token;
  183.     }
  184.     public function setToken(string $token): self
  185.     {
  186.         $this->token $token;
  187.         return $this;
  188.     }
  189.     public function getTokens(): ?string
  190.     {
  191.         return $this->tokens;
  192.     }
  193.     public function setTokens(?string $tokens): self
  194.     {
  195.         $this->tokens $tokens;
  196.         return $this;
  197.     }
  198.     public function getCreatedAt(): ?\DateTimeInterface
  199.     {
  200.         return $this->created_at;
  201.     }
  202.     public function setCreatedAt(?\DateTimeInterface $created_at): self
  203.     {
  204.         $this->created_at $created_at;
  205.         return $this;
  206.     }
  207.     public function getUpdatedAt(): ?\DateTimeInterface
  208.     {
  209.         return $this->updated_at;
  210.     }
  211.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  212.     {
  213.         $this->updated_at $updated_at;
  214.         return $this;
  215.     }
  216.     public function getPhoto(): ?string
  217.     {
  218.         return $this->photo;
  219.     }
  220.     public function setPhoto(?string $photo): self
  221.     {
  222.         $this->photo $photo;
  223.         return $this;
  224.     }
  225. }