src/Entity/User.php line 19

Open in your IDE?
  1. <?php 
  2. namespace App\Entity;
  3. use Symfony\Component\Security\Core\User\UserInterface;
  4. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  5. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  6. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  7. use Knp\DoctrineBehaviors\Model as ORMBehaviors;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait as Blameable;
  10. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait as Timestampable;
  11. /**
  12.  * @ORM\Table(name="users")
  13.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  14.  * @UniqueEntity(fields={"username"}, message="username.duplicated")
  15.  */
  16. class User implements UserInterface\SerializableTimestampableInterfaceBlameableInterface
  17. {
  18.     use Blameable;
  19.     use Timestampable;
  20.         
  21.     /**
  22.      * @ORM\Column(type="integer")
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue(strategy="AUTO")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, nullable=true)
  29.      */
  30.     private $firstName;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $lastName;
  35.     /**
  36.      * @ORM\Column(type="string", length=50, unique=true)
  37.      */
  38.     private $username;
  39.     /**
  40.      * @ORM\Column(type="string", length=64, nullable=true)
  41.      */
  42.     private $password;
  43.     /**
  44.      * @ORM\Column(type="json")
  45.      */
  46.     private $roles;
  47.     /**
  48.      * @ORM\Column(type="string", length=255, unique=true, nullable=true)
  49.      */
  50.     private $email;
  51.     /**
  52.      * @ORM\Column(name="is_active", type="boolean")
  53.      */
  54.     private $isActive;
  55.     /**
  56.      * @ORM\ManyToOne(targetEntity="Printer")
  57.      * @ORM\JoinColumn(name="printer", referencedColumnName="id", nullable=true)
  58.      */
  59.     private $printer;
  60.     public function __toString()
  61.     {
  62.         return $this->isActive $this->firstName." ".$this->lastName $this->username;
  63.     }
  64.     public function __construct()
  65.     {
  66.         $this->isActive true;
  67.         // may not be needed, see section on salt below
  68.         // If so use this -> $this->salt = md5(uniqid(null, true));
  69.     }
  70.     public function getUserIdentifier()
  71.     {
  72.         return $this->getUsername();
  73.     }
  74.     public function getUsername()
  75.     {
  76.         return $this->username;
  77.     }
  78.     public function getSalt()
  79.     {
  80.         // you *may* need a real salt depending on your encoder
  81.         // see section on salt below
  82.         return null;
  83.     }
  84.     public function getPassword()
  85.     {
  86.         return $this->password;
  87.     }
  88.     public function getRoles()
  89.     {
  90.         return $this->roles;
  91.     }
  92.     public function eraseCredentials()
  93.     {
  94.     }
  95.     /** @see \Serializable::serialize() */
  96.     public function serialize()
  97.     {
  98.         return serialize(array(
  99.             $this->id,
  100.             $this->firstName,
  101.             $this->lastName,
  102.             $this->username,
  103.             $this->password,
  104.             $this->roles,
  105.             $this->printer,
  106.             // see section on salt below
  107.             // $this->salt,
  108.         ));
  109.     }
  110.     /** @see \Serializable::unserialize() */
  111.     public function unserialize($serialized)
  112.     {
  113.         list (
  114.             $this->id,
  115.             $this->firstName,
  116.             $this->lastName,
  117.             $this->username,
  118.             $this->password,
  119.             $this->roles,
  120.             $this->printer,
  121.             // see section on salt below
  122.             // $this->salt
  123.         ) = unserialize($serialized);
  124.     }
  125.     /**
  126.      * Get id
  127.      *
  128.      * @return integer
  129.      */
  130.     public function getId()
  131.     {
  132.         return $this->id;
  133.     }
  134.     /**
  135.      * Set firstName
  136.      *
  137.      * @param string $firstName
  138.      *
  139.      * @return User
  140.      */
  141.     public function setFirstName($firstName)
  142.     {
  143.         $this->firstName $firstName;
  144.         return $this;
  145.     }
  146.     /**
  147.      * Get firstName
  148.      *
  149.      * @return string
  150.      */
  151.     public function getFirstName()
  152.     {
  153.         return $this->firstName;
  154.     }
  155.     /**
  156.      * Set lastName
  157.      *
  158.      * @param string $lastName
  159.      *
  160.      * @return User
  161.      */
  162.     public function setLastName($lastName)
  163.     {
  164.         $this->lastName $lastName;
  165.         return $this;
  166.     }
  167.     /**
  168.      * Get lastName
  169.      *
  170.      * @return string
  171.      */
  172.     public function getLastName()
  173.     {
  174.         return $this->lastName;
  175.     }
  176.     /**
  177.      * Set username
  178.      *
  179.      * @param string $username
  180.      *
  181.      * @return User
  182.      */
  183.     public function setUsername($username)
  184.     {
  185.         $this->username $username;
  186.         return $this;
  187.     }
  188.     /**
  189.      * Set password
  190.      *
  191.      * @param string $password
  192.      *
  193.      * @return User
  194.      */
  195.     public function setPassword($password)
  196.     {
  197.         $this->password $password;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Set roles
  202.      *
  203.      * @param array $roles
  204.      *
  205.      * @return User
  206.      */
  207.     public function setRoles($roles)
  208.     {
  209.         $this->roles $roles;
  210.         return $this;
  211.     }
  212.     /**
  213.      * Set email
  214.      *
  215.      * @param string $email
  216.      *
  217.      * @return User
  218.      */
  219.     public function setEmail($email)
  220.     {
  221.         $this->email $email;
  222.         return $this;
  223.     }
  224.     /**
  225.      * Get email
  226.      *
  227.      * @return string
  228.      */
  229.     public function getEmail()
  230.     {
  231.         return $this->email;
  232.     }
  233.     /**
  234.      * Set isActive
  235.      *
  236.      * @param boolean $isActive
  237.      *
  238.      * @return User
  239.      */
  240.     public function setIsActive($isActive)
  241.     {
  242.         $this->isActive $isActive;
  243.         return $this;
  244.     }
  245.     /**
  246.      * Get isActive
  247.      *
  248.      * @return boolean
  249.      */
  250.     public function getIsActive()
  251.     {
  252.         return $this->isActive;
  253.     }
  254.     /**
  255.      * Set printer
  256.      *
  257.      * @param \App\Entity\Printer $printer
  258.      *
  259.      * @return User
  260.      */
  261.     public function setPrinter(\App\Entity\Printer $printer null)
  262.     {
  263.         $this->printer $printer;
  264.         return $this;
  265.     }
  266.     /**
  267.      * Get printer
  268.      *
  269.      * @return \App\Entity\Printer
  270.      */
  271.     public function getPrinter()
  272.     {
  273.         return $this->printer;
  274.     }
  275. }