lastActivity; } /** * @param \DateTime $lastActivity */ public function setLastActivity($lastActivity) { $this->lastActivity = $lastActivity; } /** * @return boolean */ public function isActiveNow() { $delay = new \DateTime('5 minutes ago'); return ( $this->getLastActivity() > $delay ); } /** * @ORM\ManyToMany(targetEntity="App\Entity\Film", mappedBy="usersWantToView") * @var \Doctrine\Common\Collections\Collection */ private $films; /** * @ORM\ManyToMany(targetEntity="App\Entity\Film", mappedBy="usersWhoSeen") * @var \Doctrine\Common\Collections\Collection */ private $filmsVus; /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set username * * @param string $username * * @return User */ public function setUsername($username) { $this->username = $username; return $this; } /** * Get username * * @return string */ public function getUsername() { return $this->username; } /** * @param bool $activated */ public function setActivated($activated) { $this->isActive = $activated; } /** * @return bool */ public function getActivated() { return $this->isActive; } /** * @return string */ public function getPrenom() { return $this->prenom; } /** * @param string $prenom */ public function setPrenom($prenom) { $this->prenom = $prenom; } /** * @return string */ public function getNom() { return $this->nom; } /** * @param string $nom */ public function setNom($nom) { $this->nom = $nom; } /** * @return string */ public function getMail() { return $this->mail; } /** * @param string $mail */ public function setMail($mail) { $this->mail = $mail; } /** * Set password * * @param string $password * * @return User */ public function setPassword($password) { $this->password = $password; return $this; } /** * Get password * * @return string */ public function getPassword() { return $this->password; } /** * Set salt * * @param string $salt * * @return User */ public function setSalt($salt) { $this->salt = $salt; return $this; } /** * Get salt * * @return string */ public function getSalt() { return $this->salt; } /** * Get token * * @return string */ public function getToken() { return $this->token; } /** * Set token * * @return User */ public function setToken($token) { //$this->token = hash("sha512", uniqid()); $this->token = $token; $this->setTokenValidity(new \DateTime()); return $this; } /** * Get token_validity * * @return \DateTime */ public function getTokenValidity() { return $this->tokenValidity; } /** * Set token * * @param \DateTime $tokenValidity * * @return User */ private function setTokenValidity(\DateTime $tokenValidity) { $this->tokenValidity = $tokenValidity; return $this; } /** * Is ValidToken * * @return boolean * */ public function isValidToken() { $expire = $this->getTokenValidity()->modify('+1 hour'); return ( $expire > new \DateTime('now') ); } /** * Set roles * * @param array $roles * * @return User */ public function setRoles($roles) { $this->roles = $roles; return $this; } /** * Get roles * * @return array */ public function getRoles() { return $this->roles; } public function eraseCredentials() { } /** * Constructor */ public function __construct() { $this->films = new \Doctrine\Common\Collections\ArrayCollection(); //$this->setToken(); $this->setLastActivity(new \DateTime('now')); $this->setActivated(true); } /////////////////////////////////////////////////////////////// /** * Add film * * @param \App\Entity\Film $film * * @return User */ public function addFilm(\App\Entity\Film $film) { $this->films[] = $film; return $this; } /** * Remove film * * @param \App\Entity\Film $film */ public function removeFilm(\App\Entity\Film $film) { $this->films->removeElement($film); } /** * Get films * * @return \Doctrine\Common\Collections\Collection */ public function getFilms() { return $this->films; } /////////////////////////////////////////////////////////////////////////// /** * Add film * * @param \App\Entity\Film $film * * @return User */ public function addFilmVu(\App\Entity\Film $film) { $this->filmsVus[] = $film; return $this; } /** * Remove film * * @param \App\Entity\Film $film */ public function removeFilmVu(\App\Entity\Film $film) { $this->filmsVus->removeElement($film); } /** * Get films * * @return \Doctrine\Common\Collections\Collection */ public function getFilmsVus() { return $this->filmsVus; } /** * Get nomComplet * @return string */ public function getNomComplet() { if ($this->prenom == null && $this->nom == null) { return $this->getUsername(); } else return $this->getPrenom()." ".$this->getNom(); } public function isAccountNonExpired() { return true; } public function isAccountNonLocked() { return true; } public function isCredentialsNonExpired() { return true; } public function isEnabled() { return $this->isActive; } /** @see \Serializable::serialize() */ public function serialize() { return serialize(array( $this->id, $this->username, $this->password, $this->isActive, // see section on salt below // $this->salt, )); } /** @see \Serializable::unserialize() */ public function unserialize($serialized) { list ( $this->id, $this->username, $this->password, $this->isActive, // see section on salt below // $this->salt ) = unserialize($serialized, array('allowed_classes' => false)); } /** * @param \App\Entity\Film $film * @return boolean */ public function wantToSee(Film $film) { return $this->getFilms()->contains($film); } /** * @param \App\Entity\Film $film * @return boolean */ public function haveSeen(Film $film) { return $this->getFilmsVus()->contains($film); } }