3 // src/Rapsys/UserBundle/Entity/User.php 
   4 namespace Rapsys\UserBundle\Entity
; 
   6 use Rapsys\UserBundle\Entity\Group
; 
   7 use Symfony\Component\Security\Core\User\UserInterface
; 
   8 use Doctrine\Common\Collections\ArrayCollection
; 
   9 use Rapsys\UserBundle\Entity\Title
; 
  11 class User 
implements UserInterface
, \Serializable 
{ 
  58          * @var \Rapsys\UserBundle\Entity\Title 
  63          * @var \Doctrine\Common\Collections\Collection 
  70         public function __construct() { 
  71                 $this->active 
= false; 
  72                 $this->groups 
= new ArrayCollection(); 
  80         public function getId() { 
  91         public function setMail($mail) { 
 102         public function getMail() { 
 109          * @param string $pseudonym 
 113         public function setPseudonym($pseudonym) { 
 114                 $this->pseudonym 
= $pseudonym; 
 124         public function getPseudonym() { 
 125                 return $this->pseudonym
; 
 131          * @param string $forename 
 135         public function setForename($forename) { 
 136                 $this->forename 
= $forename; 
 146         public function getForename() { 
 147                 return $this->forename
; 
 153          * @param string $surname 
 157         public function setSurname($surname) { 
 158                 $this->surname 
= $surname; 
 168         public function getSurname() { 
 169                 return $this->surname
; 
 175          * @param string $password 
 179         public function setPassword($password) { 
 180                 $this->password 
= $password; 
 192         public function getPassword() { 
 193                 return $this->password
; 
 199          * @param bool $active 
 203         public function setActive($active) { 
 204                 $this->active 
= $active; 
 214         public function getActive() { 
 215                 return $this->active
; 
 221          * @param \DateTime $created 
 225         public function setCreated($created) { 
 226                 $this->created 
= $created; 
 236         public function getCreated() { 
 237                 return $this->created
; 
 243          * @param \DateTime $updated 
 247         public function setUpdated($updated) { 
 248                 $this->updated 
= $updated; 
 258         public function getUpdated() { 
 259                 return $this->updated
; 
 265         public function setTitle(Title 
$title) { 
 266                 $this->title 
= $title; 
 274         public function getTitle(): Title 
{ 
 281          * @param \Rapsys\UserBundle\Entity\Group $group 
 285         public function addGroup(Group 
$group) { 
 286                 $this->groups
[] = $group; 
 294          * @param \Rapsys\UserBundle\Entity\Group $group 
 296         public function removeGroup(Group 
$group) { 
 297                 $this->groups
->removeElement($group); 
 303          * @return \Doctrine\Common\Collections\Collection 
 305         public function getGroups() { 
 306                 return $this->groups
; 
 312         public function getRoles() { 
 313                 //Get the unique roles list by id 
 314                 return array_unique(array_reduce( 
 315                         //Cast groups as array 
 316                         $this->groups
->toArray(), 
 317                         //Reduce to an array of id => group tuples 
 318                         function ($array, $group) { 
 319                                 $array[$group->getId()] = $group->getRole(); 
 322                         //Init with ROLE_USER 
 323                         //XXX: we assume that ROLE_USER has id 1 in database 
 328         public function getRole() { 
 330                 $roles = $this->getRoles(); 
 332                 //Return the role with max id 
 333                 //XXX: should be rewriten if it change in your configuration 
 334                 return $roles[array_reduce( 
 336                         function($cur, $id) { 
 349         public function getSalt() { 
 350                 //No salt required with bcrypt 
 357         public function getUsername() { 
 364         public function eraseCredentials() {} 
 366         public function serialize(): string { 
 377         public function unserialize($serialized) { 
 385                 ) = unserialize($serialized); 
 388         //XXX: was from vendor/symfony/security-core/User/AdvancedUserInterface.php, see if it's used anymore 
 389         public function isEnabled() { 
 390                 return $this->active
; 
 394          * Returns a string representation of the user 
 398         public function __toString(): string { 
 399                 return $this->title
.' '.$this->forename
.' '.$this->surname
;