1 <?php 
declare(strict_types
=1); 
   4  * this file is part of the rapsys packbundle package. 
   6  * (c) raphaël gertz <symfony@rapsys.eu> 
   8  * for the full copyright and license information, please view the license 
   9  * file that was distributed with this source code. 
  12 namespace Rapsys\UserBundle\Entity
; 
  14 use Doctrine\Common\Collections\ArrayCollection
; 
  15 use Symfony\Component\Security\Core\User\UserInterface
; 
  17 use Rapsys\UserBundle\Entity\Civility
; 
  18 use Rapsys\UserBundle\Entity\Group
; 
  23 class User 
implements UserInterface
, \Serializable 
{ 
  80          * @var ArrayCollection 
  87         public function __construct() { 
  88                 $this->active 
= false; 
  89                 $this->disabled 
= false; 
  90                 $this->groups 
= new ArrayCollection(); 
  98         public function getId(): int { 
 105          * @param string $mail 
 109         public function setMail(string $mail) { 
 120         public function getMail(): ?string { 
 127          * @param string $pseudonym 
 131         public function setPseudonym(string $pseudonym) { 
 132                 $this->pseudonym 
= $pseudonym; 
 142         public function getPseudonym(): ?string { 
 143                 return $this->pseudonym
; 
 149          * @param string $forename 
 153         public function setForename(string $forename) { 
 154                 $this->forename 
= $forename; 
 164         public function getForename(): ?string { 
 165                 return $this->forename
; 
 171          * @param string $surname 
 175         public function setSurname(string $surname) { 
 176                 $this->surname 
= $surname; 
 186         public function getSurname(): ?string { 
 187                 return $this->surname
; 
 193          * @param string $password 
 197         public function setPassword(string $password) { 
 198                 $this->password 
= $password; 
 210         public function getPassword(): ?string { 
 211                 return $this->password
; 
 217          * @param bool $active 
 221         public function setActive(bool $active) { 
 222                 $this->active 
= $active; 
 232         public function getActive(): bool { 
 233                 return $this->active
; 
 239          * @param bool $disabled 
 243         public function setDisabled(bool $disabled) { 
 244                 $this->disabled 
= $disabled; 
 254         public function getDisabled(): bool { 
 255                 return $this->disabled
; 
 261          * @param \DateTime $created 
 265         public function setCreated(\DateTime 
$created) { 
 266                 $this->created 
= $created; 
 276         public function getCreated(): \DateTime 
{ 
 277                 return $this->created
; 
 283          * @param \DateTime $updated 
 287         public function setUpdated(\DateTime 
$updated) { 
 288                 $this->updated 
= $updated; 
 298         public function getUpdated(): \DateTime 
{ 
 299                 return $this->updated
; 
 305         public function setCivility(Civility 
$civility) { 
 306                 $this->civility 
= $civility; 
 314         public function getCivility(): ?Civility 
{ 
 315                 return $this->civility
; 
 321          * @param Group $group 
 325         public function addGroup(Group 
$group) { 
 326                 $this->groups
[] = $group; 
 334          * @param Group $group 
 336         public function removeGroup(Group 
$group) { 
 337                 $this->groups
->removeElement($group); 
 343          * @return ArrayCollection 
 345         public function getGroups(): ArrayCollection 
{ 
 346                 return $this->groups
; 
 352         public function getRoles(): array { 
 353                 //Get the unique roles list by id 
 354                 return array_unique(array_reduce( 
 355                         //Cast groups as array 
 356                         $this->groups
->toArray(), 
 357                         //Reduce to an array of id => group tuples 
 358                         function ($array, $group) { 
 359                                 $array[$group->getId()] = $group->getRole(); 
 362                         //Init with empty array 
 363                         //XXX: on registration, add each group present in rapsys_user.default.group array to user 
 364                         //XXX: see vendor/rapsys/userbundle/Controller/DefaultController.php +450 
 372         public function getRole(): ?string { 
 374                 $roles = $this->getRoles(); 
 376                 //With roles array empty 
 382                 //Return the role with max id 
 383                 //XXX: should be rewriten if it change in your configuration 
 384                 return $roles[array_reduce( 
 386                         function($cur, $id) { 
 387                                 if ($cur === null || $id > $cur) { 
 399         public function getSalt(): ?string { 
 400                 //No salt required with bcrypt 
 407         public function getUsername(): string { 
 414         public function eraseCredentials(): void {} 
 416         public function serialize(): string { 
 428         public function unserialize($serialized) { 
 437                 ) = unserialize($serialized); 
 441          * Check if account is activated 
 443          * It was from deprecated AdvancedUserInterface, see if it's used anymore 
 445          * @see vendor/symfony/security-core/User/AdvancedUserInterface.php 
 447         public function isActivated(): bool { 
 448                 return $this->active
; 
 452          * Check if account is disabled 
 454          * It was from deprecated AdvancedUserInterface, see if it's used anymore 
 456          * @see vendor/symfony/security-core/User/AdvancedUserInterface.php 
 458         public function isDisabled(): bool { 
 459                 return $this->disabled
; 
 465         public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs 
$eventArgs) { 
 466                 //Check that we have an user instance 
 467                 if (($user = $eventArgs->getEntity()) instanceof User
) { 
 469                         $user->setUpdated(new \
DateTime('now')); 
 474          * Returns a string representation of the user 
 478         public function __toString(): string { 
 479                 return $this->civility
.' '.$this->forename
.' '.$this->surname
;