src/Entity/User.php line 24

Open in your IDE?
  1. <?php
  2. // src/Entity/User.php
  3. namespace App\Entity;
  4. use Doctrine\DBAL\Types\Types;
  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. use JMS\Serializer\Annotation as Serializer;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  14.  * @ORM\Table(name="lf_users")
  15.  * @UniqueEntity(fields="email", message="Email already taken")
  16.  * @UniqueEntity(fields="username", message="Username already taken")
  17.  * @ORM\HasLifecycleCallbacks()
  18.  */
  19. class User implements UserInterface
  20. {
  21.     /**
  22.      * @ORM\PrePersist
  23.      */
  24.     public function prePersist()
  25.     {
  26.         $this->dateCreated = new \DateTime();
  27.     }
  28.     /**
  29.      * @ORM\Id
  30.      * @ORM\Column(type="integer")
  31.      * @ORM\GeneratedValue(strategy="AUTO")
  32.      */
  33.     private $id;
  34.     /**
  35.      * @var datetime
  36.      * @ORM\Column(name="date_created", type="datetime", nullable=true)
  37.      */
  38.     protected $dateCreated;
  39.     /**
  40.      * @ORM\Column(type="string", length=190, unique=true)
  41.      * @Assert\NotBlank()
  42.      * @Assert\Email()
  43.      */
  44.     private $email;
  45.     /**
  46.      * @ORM\Column(type="string", length=190, nullable=true)
  47.      */
  48.     private $username;
  49.     /**
  50.      * @Assert\Length(max=4096)
  51.      */
  52.     private $plainPassword;
  53.     /**
  54.      * The below length depends on the "algorithm" you use for encoding
  55.      * the password, but this works well with bcrypt.
  56.      *
  57.      * @ORM\Column(type="string", length=64)
  58.      */
  59.     private $password;
  60.     /**
  61.      * @ORM\Column(type="string", length=190, nullable=true)
  62.      * @Assert\NotBlank()
  63.      */
  64.     private $lastName;
  65.     /**
  66.      * @ORM\Column(type="string", length=190, nullable=true)
  67.      * @Assert\NotBlank()
  68.      */
  69.     private $firstName;
  70.     /**
  71.      * @ORM\Column(type="string", length=30, nullable=true)
  72.      */
  73.     private $phone;
  74.     /**
  75.      * @ORM\Column(type="text", nullable=true)
  76.      */
  77.     private $tokenReset;
  78.     /**
  79.      * @ORM\Column(type="string", length=190, nullable=true)
  80.      */
  81.     private $status;
  82.     /**
  83.      * @ORM\Column(type="array")
  84.      */
  85.     private $roles;
  86.     /**
  87.      * @ORM\Column(type="string")
  88.      * @Serializer\Groups({"auth-token"})
  89.      */
  90.     protected $device;
  91.     /**
  92.      * @var positionsGps[]
  93.      * @ORM\OneToMany(targetEntity="App\Entity\PositionGps", mappedBy="user")
  94.      */
  95.     protected $positionsGps;
  96.     /**
  97.      * @var hobits[]
  98.      * @ORM\OneToMany(targetEntity="App\Entity\Hobit", mappedBy="user")
  99.      */
  100.     protected $hobits;
  101.     public function __construct()
  102.     {
  103.         $this->roles = array('ROLE_USER');
  104.         $this->positionsGps = new ArrayCollection();
  105.         $this->hobits = new ArrayCollection();
  106.     }
  107.     // other properties and methods
  108.     public function getEmail()
  109.     {
  110.         return $this->email;
  111.     }
  112.     public function setEmail($email)
  113.     {
  114.         $this->email $email;
  115.     }
  116.     public function getUsername()
  117.     {
  118.         return $this->username;
  119.     }
  120.     public function setUsername($username)
  121.     {
  122.         $this->username $username;
  123.     }
  124.     public function getPlainPassword()
  125.     {
  126.         return $this->plainPassword;
  127.     }
  128.     public function setPlainPassword($password)
  129.     {
  130.         $this->plainPassword $password;
  131.     }
  132.     public function getPassword()
  133.     {
  134.         return $this->password;
  135.     }
  136.     public function setPassword($password)
  137.     {
  138.         $this->password $password;
  139.     }
  140.     public function getSalt()
  141.     {
  142.         // The bcrypt and argon2i algorithms don't require a separate salt.
  143.         // You *may* need a real salt if you choose a different encoder.
  144.         return null;
  145.     }
  146.     public function getRoles()
  147.     {
  148.         return $this->roles;
  149.     }
  150.     public function eraseCredentials()
  151.     {
  152.     }
  153.     public function getId(): ?int
  154.     {
  155.         return $this->id;
  156.     }
  157.     public function getLastName(): ?string
  158.     {
  159.         return $this->lastName;
  160.     }
  161.     public function setLastName(?string $lastName): self
  162.     {
  163.         $this->lastName $lastName;
  164.         return $this;
  165.     }
  166.     public function getFirstName(): ?string
  167.     {
  168.         return $this->firstName;
  169.     }
  170.     public function setFirstName(?string $firstName): self
  171.     {
  172.         $this->firstName $firstName;
  173.         return $this;
  174.     }
  175.     public function setRoles(array $roles): self
  176.     {
  177.         $this->roles $roles;
  178.         return $this;
  179.     }
  180.     /**
  181.      * Get roleTranslate
  182.      *
  183.      * @return integer
  184.      */
  185.     public function getRoleMain()
  186.     {
  187.         $main "";
  188.         foreach ($this->getRoles() as $role) {
  189.             if($role != "ROLE_USER"){
  190.                 $main .= $role;
  191.             }
  192.         }
  193.         return $main;
  194.     }
  195.     public function getPhone(): ?string
  196.     {
  197.         return $this->phone;
  198.     }
  199.     public function setPhone(?string $phone): self
  200.     {
  201.         $this->phone $phone;
  202.         return $this;
  203.     }
  204.     public function getTokenReset(): ?string
  205.     {
  206.         return $this->tokenReset;
  207.     }
  208.     public function setTokenReset(?string $tokenReset): self
  209.     {
  210.         $this->tokenReset $tokenReset;
  211.         return $this;
  212.     }
  213.     public function getStatus(): ?string
  214.     {
  215.         return $this->status;
  216.     }
  217.     public function setStatus(?string $status): self
  218.     {
  219.         $this->status $status;
  220.         return $this;
  221.     }
  222.     public function addRole($role)
  223.     {
  224.         $role strtoupper($role);
  225.         if ($role === "ROLE_DEFAULT") {
  226.             return $this;
  227.         }
  228.         if (!in_array($role$this->rolestrue)) {
  229.             $this->roles[] = $role;
  230.         }
  231.         return $this;
  232.     }
  233.     public function getDateCreated(): ?\DateTimeInterface
  234.     {
  235.         return $this->dateCreated;
  236.     }
  237.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  238.     {
  239.         $this->dateCreated $dateCreated;
  240.         return $this;
  241.     }
  242.     public function getDevice(): ?string
  243.     {
  244.         return $this->device;
  245.     }
  246.     public function setDevice(string $device): self
  247.     {
  248.         $this->device $device;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection<int, PositionGps>
  253.      */
  254.     public function getPositionsGps(): Collection
  255.     {
  256.         return $this->positionsGps;
  257.     }
  258.     public function addPositionsGp(PositionGps $positionsGp): self
  259.     {
  260.         if (!$this->positionsGps->contains($positionsGp)) {
  261.             $this->positionsGps->add($positionsGp);
  262.             $positionsGp->setUser($this);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removePositionsGp(PositionGps $positionsGp): self
  267.     {
  268.         if ($this->positionsGps->removeElement($positionsGp)) {
  269.             // set the owning side to null (unless already changed)
  270.             if ($positionsGp->getUser() === $this) {
  271.                 $positionsGp->setUser(null);
  272.             }
  273.         }
  274.         return $this;
  275.     }
  276.     /**
  277.      * @return Collection<int, Hobit>
  278.      */
  279.     public function getHobits(): Collection
  280.     {
  281.         return $this->hobits;
  282.     }
  283.     public function addHobit(Hobit $hobit): self
  284.     {
  285.         if (!$this->hobits->contains($hobit)) {
  286.             $this->hobits->add($hobit);
  287.             $hobit->setUser($this);
  288.         }
  289.         return $this;
  290.     }
  291.     public function removeHobit(Hobit $hobit): self
  292.     {
  293.         if ($this->hobits->removeElement($hobit)) {
  294.             // set the owning side to null (unless already changed)
  295.             if ($hobit->getUser() === $this) {
  296.                 $hobit->setUser(null);
  297.             }
  298.         }
  299.         return $this;
  300.     }
  301. }