X-Git-Url: https://git.rapsys.eu/userbundle/blobdiff_plain/55beb067dbd20e192fb31ca0a5027d678bc4b233..92df56260494a1a27a5c509493200ac8594d50d8:/Entity/Group.php?ds=inline diff --git a/Entity/Group.php b/Entity/Group.php index dad79b0..188e1bc 100644 --- a/Entity/Group.php +++ b/Entity/Group.php @@ -1,8 +1,24 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ -// src/Rapsys/UserBundle/Entity/Group.php namespace Rapsys\UserBundle\Entity; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\ORM\Event\PreUpdateEventArgs; + +use Rapsys\UserBundle\Entity\User; + +/** + * Group + */ class Group { /** * @var integer @@ -12,7 +28,7 @@ class Group { /** * @var string */ - protected $role; + protected $title; /** * @var \DateTime @@ -25,50 +41,49 @@ class Group { protected $updated; /** - * @var \Doctrine\Common\Collections\Collection + * @var ArrayCollection */ protected $users; /** * Constructor - * @param string $role The role name + * + * @param string $title The group name */ - public function __construct(string $role) { - $this->role = (string) $role; - $this->users = new \Doctrine\Common\Collections\ArrayCollection(); + public function __construct(string $title) { + $this->title = $title; + $this->users = new ArrayCollection(); } /** - * Set role - * - * @param string $role + * Get id * - * @return User + * @return integer */ - public function setRole($role) { - $this->role = $role; - - return $this; + public function getId(): int { + return $this->id; } /** - * Get role + * Set title * - * @return string + * @param string $title The group name + * + * @return Group */ - public function getRole() { - return $this->role; + public function setTitle(string $title): Group { + $this->title = $title; + + return $this; } /** - * Returns a string representation of the role. - * - * @xxx Replace the deprecated "extends \Symfony\Component\Security\Core\Role\Role" + * Get title * * @return string */ - public function __toString(): string { - return $this->role; + public function getTitle(): ?string { + return $this->title; } /** @@ -76,9 +91,9 @@ class Group { * * @param \DateTime $created * - * @return User + * @return Group */ - public function setCreated($created) { + public function setCreated(\DateTime $created): Group { $this->created = $created; return $this; @@ -89,7 +104,7 @@ class Group { * * @return \DateTime */ - public function getCreated() { + public function getCreated(): \DateTime { return $this->created; } @@ -98,9 +113,9 @@ class Group { * * @param \DateTime $updated * - * @return User + * @return Group */ - public function setUpdated($updated) { + public function setUpdated(\DateTime $updated): Group { $this->updated = $updated; return $this; @@ -111,18 +126,18 @@ class Group { * * @return \DateTime */ - public function getUpdated() { + public function getUpdated(): \DateTime { return $this->updated; } /** * Add user * - * @param \Rapsys\UserBundle\Entity\User $user + * @param User $user * * @return Group */ - public function addUser(\Rapsys\UserBundle\Entity\User $user) { + public function addUser(User $user) { $this->users[] = $user; return $this; @@ -131,18 +146,47 @@ class Group { /** * Remove user * - * @param \Rapsys\UserBundle\Entity\User $user + * @param User $user */ - public function removeUser(\Rapsys\UserBundle\Entity\User $user) { + public function removeUser(User $user) { $this->users->removeElement($user); } /** * Get users * - * @return \Doctrine\Common\Collections\Collection + * @return ArrayCollection */ - public function getUsers() { + public function getUsers(): ArrayCollection { return $this->users; } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs) { + //Check that we have a group instance + if (($user = $eventArgs->getEntity()) instanceof Group) { + //Set updated value + $user->setUpdated(new \DateTime('now')); + } + } + + /** + * Returns a string representation of the group + * + * @return string + */ + public function __toString(): string { + return $this->title; + } + + /** + * Get role + * + * @return string + */ + public function getRole(): string { + return 'ROLE_'.strtoupper($this->title); + } }