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\ArrayCollection
;
15 use Doctrine\ORM\Event\PreUpdateEventArgs
;
17 use Rapsys\UserBundle\Entity\User
;
44 * @var ArrayCollection
51 * @param string $title The group name
53 public function __construct(string $title) {
55 $this->title
= $title;
56 $this->created
= new \
DateTime('now');
57 $this->updated
= new \
DateTime('now');
58 $this->users
= new ArrayCollection();
66 public function getId(): int {
73 * @param string $title The group name
77 public function setTitle(string $title): Group
{
78 $this->title
= $title;
88 public function getTitle(): ?string {
95 * @param \DateTime $created
99 public function setCreated(\DateTime
$created): Group
{
100 $this->created
= $created;
110 public function getCreated(): \DateTime
{
111 return $this->created
;
117 * @param \DateTime $updated
121 public function setUpdated(\DateTime
$updated): Group
{
122 $this->updated
= $updated;
132 public function getUpdated(): \DateTime
{
133 return $this->updated
;
143 public function addUser(User
$user) {
144 $this->users
[] = $user;
154 public function removeUser(User
$user) {
155 $this->users
->removeElement($user);
161 * @return ArrayCollection
163 public function getUsers(): ArrayCollection
{
170 public function preUpdate(PreUpdateEventArgs
$eventArgs) {
171 //Check that we have a group instance
172 if (($user = $eventArgs->getObject()) instanceof Group
) {
174 $user->setUpdated(new \
DateTime('now'));
179 * Returns a string representation of the group
183 public function __toString(): string {
192 public function getRole(): string {
193 //XXX: $prefix = 'ROLE_' set in Role*Voter classes
194 return 'ROLE_'.strtoupper($this->title
);