src/Entity/Users/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Users;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Symfony\Component\Validator\Constraints AS Constraints;
  5. use Symfony\Component\Validator\Constraints AS Assert;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Doctrine\ORM\Mapping AS ORM;
  9. use Ramsey\Uuid\Uuid;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\Users\UserRepository")
  12.  * @ORM\Table(name="users_user")
  13.  * @ORM\HasLifecycleCallbacks()
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.     * @ORM\Id
  19.     * @ORM\GeneratedValue(strategy="AUTO")
  20.     * @ORM\Column(type="integer")
  21.     */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="uuid")
  25.      * @Assert\Uuid
  26.      */
  27.     protected $uuid;
  28.     /**
  29.      * @var \DateTime
  30.      *
  31.      * @ORM\Column(type="datetime", nullable=false)
  32.      * @Assert\NotBlank
  33.      */
  34.     private $created;
  35.     /**
  36.      * @var \DateTime
  37.      *
  38.      * @ORM\Column(type="datetime", nullable=true)
  39.      */
  40.     private $lastActive;
  41.     /**
  42.      * @ORM\Column(type="string", length=100, unique=true)
  43.      * @Constraints\Email()
  44.      * @Constraints\NotBlank()
  45.      */
  46.     private $email;
  47.     /**
  48.      * @ORM\Column(type="string", length=64, nullable=true)
  49.      */
  50.     private $password;
  51.     /**
  52.      * @ORM\Column(type="string", length=60, nullable=true)
  53.      */
  54.     private $name;
  55.     /**
  56.      * @ORM\ManyToOne(targetEntity=Group::class, inversedBy="users")
  57.      * @ORM\JoinColumn(nullable=false)
  58.      **/
  59.     private $group;
  60.     public function __construct()
  61.     {
  62.         // Generate UUID
  63.         $uuid Uuid::uuid1();
  64.         $this->setUuid($uuid->toString());
  65.         // Defaults
  66.         $this->created = new \DateTime();
  67.     }
  68.     public function getId()
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function setUuid($uuid)
  73.     {
  74.         $this->uuid $uuid;
  75.         return $this;
  76.     }
  77.     public function getUuid()
  78.     {
  79.         return $this->uuid;
  80.     }
  81.     public function getRoles() : array
  82.     {
  83.         return ['ROLE_USER'];
  84.     }
  85.     public function hasRole($role)
  86.     {
  87.         return in_array($role$this->getRoles());
  88.     }
  89.     public function getUserIdentifier() : string
  90.     {
  91.         return $this->email;
  92.     }
  93.     public function setPassword(string $password null)
  94.     {
  95.         $this->password $password;
  96.     }
  97.     public function getPassword(): ?string
  98.     {
  99.         return $this->password;
  100.     }
  101.     public function eraseCredentials()
  102.     {
  103.     }
  104.     public function setCreated(\DateTime $created)
  105.     {
  106.         $this->created $created;
  107.     }
  108.     public function getCreated()
  109.     {
  110.         return $this->created;
  111.     }
  112.     public function setLastActive(\DateTime $lastActive)
  113.     {
  114.         $this->lastActive $lastActive;
  115.     }
  116.     public function getLastActive()
  117.     {
  118.         return $this->lastActive;
  119.     }
  120.     public function getEmail()
  121.     {
  122.         return $this->email;
  123.     }
  124.     public function setEmail(string $email)
  125.     {
  126.         $this->email $email;
  127.     }
  128.     public function getName()
  129.     {
  130.         return $this->name;
  131.     }
  132.     public function setName(string $name null)
  133.     {
  134.         $this->name $name;
  135.     }
  136.     /**
  137.      * Get the value of group
  138.      */ 
  139.     public function getGroup()
  140.     {
  141.         return $this->group;
  142.     }
  143.     /**
  144.      * Set the value of group
  145.      *
  146.      * @return  self
  147.      */ 
  148.     public function setGroup($group)
  149.     {
  150.         $this->group $group;
  151.         return $this;
  152.     }
  153. }