<?php
// src/Entity/User.php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use JMS\Serializer\Annotation as Serializer;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="lf_users")
* @UniqueEntity(fields="email", message="Email already taken")
* @UniqueEntity(fields="username", message="Username already taken")
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface
{
/**
* @ORM\PrePersist
*/
public function prePersist()
{
$this->dateCreated = new \DateTime();
}
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var datetime
* @ORM\Column(name="date_created", type="datetime", nullable=true)
*/
protected $dateCreated;
/**
* @ORM\Column(type="string", length=190, unique=true)
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="string", length=190, nullable=true)
*/
private $username;
/**
* @Assert\Length(max=4096)
*/
private $plainPassword;
/**
* The below length depends on the "algorithm" you use for encoding
* the password, but this works well with bcrypt.
*
* @ORM\Column(type="string", length=64)
*/
private $password;
/**
* @ORM\Column(type="string", length=190, nullable=true)
* @Assert\NotBlank()
*/
private $lastName;
/**
* @ORM\Column(type="string", length=190, nullable=true)
* @Assert\NotBlank()
*/
private $firstName;
/**
* @ORM\Column(type="string", length=30, nullable=true)
*/
private $phone;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $tokenReset;
/**
* @ORM\Column(type="string", length=190, nullable=true)
*/
private $status;
/**
* @ORM\Column(type="array")
*/
private $roles;
/**
* @ORM\Column(type="string")
* @Serializer\Groups({"auth-token"})
*/
protected $device;
/**
* @var positionsGps[]
* @ORM\OneToMany(targetEntity="App\Entity\PositionGps", mappedBy="user")
*/
protected $positionsGps;
/**
* @var hobits[]
* @ORM\OneToMany(targetEntity="App\Entity\Hobit", mappedBy="user")
*/
protected $hobits;
public function __construct()
{
$this->roles = array('ROLE_USER');
$this->positionsGps = new ArrayCollection();
$this->hobits = new ArrayCollection();
}
// other properties and methods
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getSalt()
{
// The bcrypt and argon2i algorithms don't require a separate salt.
// You *may* need a real salt if you choose a different encoder.
return null;
}
public function getRoles()
{
return $this->roles;
}
public function eraseCredentials()
{
}
public function getId(): ?int
{
return $this->id;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* Get roleTranslate
*
* @return integer
*/
public function getRoleMain()
{
$main = "";
foreach ($this->getRoles() as $role) {
if($role != "ROLE_USER"){
$main .= $role;
}
}
return $main;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getTokenReset(): ?string
{
return $this->tokenReset;
}
public function setTokenReset(?string $tokenReset): self
{
$this->tokenReset = $tokenReset;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function addRole($role)
{
$role = strtoupper($role);
if ($role === "ROLE_DEFAULT") {
return $this;
}
if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
public function getDateCreated(): ?\DateTimeInterface
{
return $this->dateCreated;
}
public function setDateCreated(\DateTimeInterface $dateCreated): self
{
$this->dateCreated = $dateCreated;
return $this;
}
public function getDevice(): ?string
{
return $this->device;
}
public function setDevice(string $device): self
{
$this->device = $device;
return $this;
}
/**
* @return Collection<int, PositionGps>
*/
public function getPositionsGps(): Collection
{
return $this->positionsGps;
}
public function addPositionsGp(PositionGps $positionsGp): self
{
if (!$this->positionsGps->contains($positionsGp)) {
$this->positionsGps->add($positionsGp);
$positionsGp->setUser($this);
}
return $this;
}
public function removePositionsGp(PositionGps $positionsGp): self
{
if ($this->positionsGps->removeElement($positionsGp)) {
// set the owning side to null (unless already changed)
if ($positionsGp->getUser() === $this) {
$positionsGp->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Hobit>
*/
public function getHobits(): Collection
{
return $this->hobits;
}
public function addHobit(Hobit $hobit): self
{
if (!$this->hobits->contains($hobit)) {
$this->hobits->add($hobit);
$hobit->setUser($this);
}
return $this;
}
public function removeHobit(Hobit $hobit): self
{
if ($this->hobits->removeElement($hobit)) {
// set the owning side to null (unless already changed)
if ($hobit->getUser() === $this) {
$hobit->setUser(null);
}
}
return $this;
}
}