src/Entity/Users.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use \Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use OlaSoft\Common;
  9. use App\Repository\UsersRepository;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\UsersRepository")
  12.  * @UniqueEntity(fields="email", message="Un utilisateur existe déjà avec ce compte email.")
  13.  * @ORM\AttributeOverrides({
  14.  *      @ORM\AttributeOverride(name="email",
  15.  *          column=@ORM\Column(
  16.  *              name     = "email",
  17.  *              length   = 191,
  18.  *              unique   = true
  19.  *          )
  20.  *      )
  21.  * })
  22.  */
  23. class Users implements UserInterface, \Serializable
  24. {
  25.     private $em;
  26.     public function __construct(){
  27.         $this->createdAt = new \DateTime;
  28.         $this->isEnabled false;
  29.         $this->profiles = new ArrayCollection();
  30.     }
  31.     /**
  32.      * @ORM\Column(name="id", type="integer")
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="AUTO")
  35.      */
  36.     private $id;
  37.     /**
  38.      * @ORM\Column(name="fName", type="string", length=255, nullable=true)
  39.      */
  40.     private $fName;
  41.     /**
  42.      * @ORM\Column(name="lName", type="string", length=255, nullable=true)
  43.      */
  44.     private $lName;
  45.     /**
  46.      * @var string
  47.      *
  48.      * @ORM\Column(name="phone", type="string", length=255, nullable=true)
  49.      */
  50.     private $phone;
  51.     /**
  52.      * @ORM\Column(name="email", type="string", length=255, unique=true)
  53.      */
  54.     private $email;
  55.     /**
  56.      * @ORM\Column(name="createdAt", type="datetime",nullable=true))
  57.      */
  58.     private $createdAt;
  59.     /**
  60.      * @ORM\Column(name="lastLogin", type="datetime",nullable=true))
  61.      */
  62.     private $lastLogin;
  63.     /**
  64.      * @var string
  65.      *
  66.      * @ORM\Column(name="password", type="string", length=255,nullable=true))
  67.      */
  68.     private $password;
  69.     /**
  70.      * @ORM\Column(name="token", type="string", length=255, nullable=true))
  71.      */
  72.     private $token;
  73.     /**
  74.      * @ORM\Column(name="sex", type="boolean", nullable=true)
  75.      */
  76.     private $sex;
  77.     /**
  78.      * @ORM\Column(name="isEnabled", type="boolean", nullable=true)
  79.      */
  80.     private $isEnabled;
  81.     /**
  82.      * @ORM\ManyToOne(targetEntity="App\Entity\Profiles", inversedBy="users")
  83.      */
  84.     private $profile;
  85.     public function eraseCredentials() {}
  86.     public function getRoles() {
  87.         return $this->profile ? [$this->profile->getRole()] : ['ROLE_USER'];
  88.     }
  89.     public function getSalt() {
  90.         $salt '';
  91.         return null;
  92.     }
  93.     public function getUsername() {
  94.         return $this->email;
  95.     }
  96.     public function getPassword()
  97.     {
  98.         return $this->password;
  99.     }
  100.     public function serialize()
  101.     {
  102.         return serialize(array(
  103.             $this->id,
  104.             $this->email,
  105.             $this->password,
  106.         ));
  107.     }
  108.     public function unserialize($serialized)
  109.     {
  110.         list (
  111.             $this->id,
  112.             $this->email,
  113.             $this->password,
  114.         ) = unserialize($serialized, array('allowed_classes' => false));
  115.     }
  116.     public function getId(): ?int
  117.     {
  118.         return $this->id;
  119.     }
  120.     public function getFName(): ?string
  121.     {
  122.         return $this->fName;
  123.     }
  124.     public function setFName(?string $fName): self
  125.     {
  126.         $this->fName $fName;
  127.         return $this;
  128.     }
  129.     public function getLName(): ?string
  130.     {
  131.         return $this->lName;
  132.     }
  133.     public function setLName(?string $lName): self
  134.     {
  135.         $this->lName $lName;
  136.         return $this;
  137.     }
  138.     public function getName(): ?string
  139.     {
  140.         return $this->lName.' '.$this->fName;
  141.     }
  142.     public function getPhone(): ?string
  143.     {
  144.         return $this->phone;
  145.     }
  146.     public function setPhone(?string $phone): self
  147.     {
  148.         $this->phone $phone;
  149.         return $this;
  150.     }
  151.     public function getCreatedAt(): ?\DateTimeInterface
  152.     {
  153.         return $this->createdAt;
  154.     }
  155.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  156.     {
  157.         $this->createdAt $createdAt;
  158.         return $this;
  159.     }
  160.     public function getLastLogin(): ?\DateTimeInterface
  161.     {
  162.         return $this->lastLogin;
  163.     }
  164.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  165.     {
  166.         $this->lastLogin $lastLogin;
  167.         return $this;
  168.     }
  169.     public function setPassword(?string $password null): self
  170.     {
  171.         $this->password $password password_hash($passwordPASSWORD_BCRYPT, array('cost' => 12)) : null;
  172.         return $this;
  173.     }
  174.     public function getToken(): ?string
  175.     {
  176.         return $this->token;
  177.     }
  178.     public function setToken(?string $token): self
  179.     {
  180.         $this->token $token;
  181.         return $this;
  182.     }
  183.     public function getSex(): ?bool
  184.     {
  185.         return $this->sex;
  186.     }
  187.     public function setSex(?bool $sex): self
  188.     {
  189.         $this->sex $sex;
  190.         return $this;
  191.     }
  192.     public function getIsEnabled(): ?bool
  193.     {
  194.         return $this->isEnabled;
  195.     }
  196.     public function setIsEnabled(?bool $isEnabled): self
  197.     {
  198.         $this->isEnabled $isEnabled;
  199.         return $this;
  200.     }
  201.     public function getEmail(): ?string
  202.     {
  203.         return $this->email;
  204.     }
  205.     public function setEmail(string $email): self
  206.     {
  207.         $this->email $email;
  208.         return $this;
  209.     }
  210.     public function getProfile(): ?Profiles
  211.     {
  212.         return $this->profile;
  213.     }
  214.     public function setProfile(?Profiles $profile): self
  215.     {
  216.         $this->profile $profile;
  217.         return $this;
  218.     }
  219.     public function __toString()
  220.     {
  221.         return $this->fName." ".$this->lName;
  222.     }
  223. }