src/Entity/User.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use App\Entity\LastActivity;
  6. /**
  7.  * @ORM\Table(name="es_user")
  8.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  9.  * @ORM\HasLifecycleCallbacks()
  10.  */
  11. class User implements UserInterface\Serializable {
  12.     /**
  13.      * @ORM\Column(name="id", type="integer")
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue(strategy="AUTO")
  16.      */
  17.     public $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $username;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $password;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, unique=true)
  28.      */
  29.     public $email;
  30.     /**
  31.      * @ORM\Column(name="is_active", type="boolean")
  32.      */
  33.     private $isActive true;
  34.     /**
  35.      * @ORM\Column(name="role", type="string", length=50)
  36.      */
  37.     private $role 'ROLE_USER';
  38.     /**
  39.      * @ORM\Column(name="role_req", type="boolean")
  40.      */
  41.     private $roleReq false;
  42.     /**
  43.      * @ORM\Column(name="role_req_sprava", type="string", length=255, nullable=true)
  44.      */
  45.     private $roleReqSprava;
  46.     /**
  47.      * @ORM\Column(type="datetime")
  48.      */
  49.     protected $created;
  50.     /**
  51.      * @ORM\Column(type="datetime")
  52.      */
  53.     protected $edited;
  54.     /**
  55.      * @ORM\Column(type="datetime", nullable=true)
  56.      */
  57.     protected $passwordChanged;
  58.     protected $lastActivity;
  59.     public function __construct() {
  60.         //$this->isActive = true;
  61.         // may not be needed, see section on salt below
  62.         // $this->salt = md5(uniqid('', true));
  63.     }
  64.     /** @ORM\PrePersist()
  65.      */
  66.     public function preCreated() {
  67.         $this->created = new \DateTime('now');
  68.     }
  69.     /** @ORM\PrePersist()
  70.      * @ORM\PreUpdate()
  71.      */
  72.     public function preEdited() {
  73.         $this->edited = new \DateTime('now');
  74.         //$this->roleReq = true;
  75.     }
  76.     public function getUsername() {
  77.         return $this->username;
  78.     }
  79.     public function getSalt() {
  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.         return $this->password;
  86.     }
  87.     public function getRoles() {
  88.         return [$this->role];
  89. //        return ['ROLE_USER'];
  90.     }
  91.     public function eraseCredentials() {
  92.     }
  93.     /** @see \Serializable::serialize() */
  94.     public function serialize() {
  95.         return serialize([
  96.             $this->id,
  97.             $this->username,
  98.             $this->password,
  99.             // see section on salt below
  100.             // $this->salt,
  101.         ]);
  102.     }
  103.     /** @see \Serializable::unserialize() */
  104.     public function unserialize($serialized) {
  105.         list (
  106.             $this->id,
  107.             $this->username,
  108.             $this->password,
  109.             // see section on salt below
  110.             // $this->salt
  111.             ) = unserialize($serialized, ['allowed_classes' => false]);
  112.     }
  113.     /**
  114.      * Get id
  115.      *
  116.      * @return integer
  117.      */
  118.     public function getId() {
  119.         return $this->id;
  120.     }
  121.     /**
  122.      * Set username
  123.      *
  124.      * @param string $username
  125.      *
  126.      * @return User
  127.      */
  128.     public function setUsername($username) {
  129.         $this->username $username;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Set password
  134.      *
  135.      * @param string $password
  136.      *
  137.      * @return User
  138.      */
  139.     public function setPassword($password) {
  140.         if ($password !== $this->getPassword()) {
  141.             $this->passwordChanged = new \DateTime('now');
  142.         }
  143.         $this->password $password;
  144.         return $this;
  145.     }
  146.     /**
  147.      * Set email
  148.      *
  149.      * @param string $email
  150.      *
  151.      * @return User
  152.      */
  153.     public function setEmail($email) {
  154.         $this->email $email;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get email
  159.      *
  160.      * @return string
  161.      */
  162.     public function getEmail() {
  163.         return $this->email;
  164.     }
  165.     /**
  166.      * Set isActive
  167.      *
  168.      * @param boolean $isActive
  169.      *
  170.      * @return User
  171.      */
  172.     public function setIsActive($isActive) {
  173.         $this->isActive $isActive;
  174.         return $this;
  175.     }
  176.     /**
  177.      * Get isActive
  178.      *
  179.      * @return boolean
  180.      */
  181.     public function getIsActive() {
  182.         return $this->isActive;
  183.     }
  184.     /**
  185.      * Set role
  186.      *
  187.      * @param string $role
  188.      *
  189.      * @return User
  190.      */
  191.     public function setRole($role) {
  192.         $this->role $role;
  193.         return $this;
  194.     }
  195.     /**
  196.      * Get role
  197.      *
  198.      * @return string
  199.      */
  200.     public function getRole() {
  201.         return $this->role;
  202.     }
  203.     /**
  204.      * Set role
  205.      *
  206.      * @param string $roleReq
  207.      *
  208.      * @return User
  209.      */
  210.     public function setRoleReq($roleReq) {
  211.         $this->roleReq $roleReq;
  212.         return $this;
  213.     }
  214.     /**
  215.      * Get roleReq
  216.      *
  217.      * @return boolean
  218.      */
  219.     public function getRoleReq() {
  220.         return $this->roleReq;
  221.     }
  222.     /**
  223.      * Set role
  224.      *
  225.      * @param string $roleReqSprava
  226.      *
  227.      * @return User
  228.      */
  229.     public function setRoleReqSprava($roleReqSprava) {
  230.         $this->roleReqSprava $roleReqSprava;
  231.         return $this;
  232.     }
  233.     /**
  234.      * Get roleReqSprava
  235.      *
  236.      * @return string
  237.      */
  238.     public function getRoleReqSprava() {
  239.         return $this->roleReqSprava;
  240.     }
  241.     /**
  242.      * Set created
  243.      *
  244.      * @param \DateTime $created
  245.      *
  246.      * @return User
  247.      */
  248.     public function setCreated($created) {
  249.         $this->created $created;
  250.         return $this;
  251.     }
  252.     /**
  253.      * Get created
  254.      *
  255.      * @return \DateTime
  256.      */
  257.     public function getCreated() {
  258.         return $this->created;
  259.     }
  260.     /**
  261.      * Set edited
  262.      *
  263.      * @param \DateTime $edited
  264.      *
  265.      * @return User
  266.      */
  267.     public function setEdited($edited) {
  268.         $this->edited $edited;
  269.         return $this;
  270.     }
  271.     /**
  272.      * Get edited
  273.      *
  274.      * @return \DateTime
  275.      */
  276.     public function getEdited() {
  277.         return $this->edited;
  278.     }
  279.     /**
  280.      * Set passwordChanged
  281.      *
  282.      * @param \DateTime $passwordChanged
  283.      *
  284.      * @return User
  285.      */
  286.     public function setPasswordChanged($passwordChanged) {
  287.         $this->passwordChanged $passwordChanged;
  288.         return $this;
  289.     }
  290.     /**
  291.      * Get passwordChanged
  292.      *
  293.      * @return \DateTime
  294.      */
  295.     public function getPasswordChanged() {
  296.         return $this->passwordChanged;
  297.     }
  298.     /**
  299.      * @return bool whether the user is active or not
  300.      */
  301.     public function isActiveNow() {
  302.         $delay = new \DateTime('2 minutes ago');
  303.         return ($this->getlastActivity() > $delay);
  304.     }
  305.     /**
  306.      * Set lastActivity
  307.      *
  308.      * @ param\Datetime $lastActivity
  309.      * @ return User
  310.      */
  311.     public function setLastActivity() {
  312.         //$this->lastActivity = $lastActivity;
  313.         $this->lastActivity = new LastActivity();
  314.         $this->lastActivity->setTime();
  315.         return $this;
  316.     }
  317.     /**
  318.      * Get lastActivity
  319.      *
  320.      * @ return \DateTime
  321.      * -- /
  322.      * public function getLastActivity()
  323.      * {
  324.      * return $this->lastActivity;
  325.      * }
  326.      */
  327. }