1 <?php 
declare(strict_types
=1); 
   4  * This file is part of the Rapsys UserBundle 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\Collection
; 
  15 use Doctrine\Common\Collections\ArrayCollection
; 
  16 use Doctrine\ORM\Event\PreUpdateEventArgs
; 
  18 use Rapsys\UserBundle\Entity\User
; 
  27         protected ?int $id = null; 
  32         protected \DateTime 
$created; 
  37         protected \DateTime 
$updated; 
  42         protected Collection 
$users; 
  47          * @param string $title The group name 
  49         public function __construct(protected string $title) { 
  51                 $this->created 
= new \
DateTime('now'); 
  52                 $this->updated 
= new \
DateTime('now'); 
  55                 $this->users 
= new ArrayCollection(); 
  63         public function getId(): ?int { 
  70          * @param string $title The group name 
  74         public function setTitle(string $title): Group 
{ 
  75                 $this->title 
= $title; 
  85         public function getTitle(): string { 
  92          * @param \DateTime $created 
  96         public function setCreated(\DateTime 
$created): Group 
{ 
  97                 $this->created 
= $created; 
 107         public function getCreated(): \DateTime 
{ 
 108                 return $this->created
; 
 114          * @param \DateTime $updated 
 118         public function setUpdated(\DateTime 
$updated): Group 
{ 
 119                 $this->updated 
= $updated; 
 129         public function getUpdated(): \DateTime 
{ 
 130                 return $this->updated
; 
 140         public function addUser(User 
$user) { 
 141                 $this->users
[] = $user; 
 151         public function removeUser(User 
$user) { 
 152                 $this->users
->removeElement($user); 
 158          * @return ArrayCollection 
 160         public function getUsers(): ArrayCollection 
{ 
 167         public function preUpdate(PreUpdateEventArgs 
$eventArgs) { 
 168                 //Check that we have a group instance 
 169                 if (($user = $eventArgs->getObject()) instanceof Group
) { 
 171                         $user->setUpdated(new \
DateTime('now')); 
 176          * Returns a string representation of the group 
 180         public function __toString(): string { 
 189         public function getRole(): string { 
 190                 //XXX: $prefix = 'ROLE_' set in Role*Voter classes 
 191                 return 'ROLE_'.strtoupper($this->title
);