]> Raphaël G. Git Repositories - userbundle/blob - Entity/Group.php
Add strict
[userbundle] / Entity / Group.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys PackBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\UserBundle\Entity;
13
14 use Doctrine\Common\Collections\ArrayCollection;
15
16 use Rapsys\UserBundle\Entity\User;
17
18 /**
19 * Group
20 */
21 class Group {
22 /**
23 * @var integer
24 */
25 protected $id;
26
27 /**
28 * @var string
29 */
30 protected $title;
31
32 /**
33 * @var \DateTime
34 */
35 protected $created;
36
37 /**
38 * @var \DateTime
39 */
40 protected $updated;
41
42 /**
43 * @var ArrayCollection
44 */
45 protected $users;
46
47 /**
48 * Constructor
49 *
50 * @param string $title The group name
51 */
52 public function __construct(string $title) {
53 $this->title = (string) $title;
54 $this->users = new ArrayCollection();
55 }
56
57 /**
58 * Get id
59 *
60 * @return integer
61 */
62 public function getId(): int {
63 return $this->id;
64 }
65
66 /**
67 * Set title
68 *
69 * @param string $title The group name
70 *
71 * @return User
72 */
73 public function setTitle(string $title) {
74 $this->title = $title;
75
76 return $this;
77 }
78
79 /**
80 * Get title
81 *
82 * @return string
83 */
84 public function getTitle(): ?string {
85 return $this->title;
86 }
87
88 /**
89 * Set created
90 *
91 * @param \DateTime $created
92 *
93 * @return User
94 */
95 public function setCreated(\DateTime $created) {
96 $this->created = $created;
97
98 return $this;
99 }
100
101 /**
102 * Get created
103 *
104 * @return \DateTime
105 */
106 public function getCreated(): \DateTime {
107 return $this->created;
108 }
109
110 /**
111 * Set updated
112 *
113 * @param \DateTime $updated
114 *
115 * @return User
116 */
117 public function setUpdated(\DateTime $updated) {
118 $this->updated = $updated;
119
120 return $this;
121 }
122
123 /**
124 * Get updated
125 *
126 * @return \DateTime
127 */
128 public function getUpdated(): \DateTime {
129 return $this->updated;
130 }
131
132 /**
133 * Add user
134 *
135 * @param User $user
136 *
137 * @return Group
138 */
139 public function addUser(User $user) {
140 $this->users[] = $user;
141
142 return $this;
143 }
144
145 /**
146 * Remove user
147 *
148 * @param User $user
149 */
150 public function removeUser(User $user) {
151 $this->users->removeElement($user);
152 }
153
154 /**
155 * Get users
156 *
157 * @return ArrayCollection
158 */
159 public function getUsers(): ArrayCollection {
160 return $this->users;
161 }
162
163 /**
164 * Returns a string representation of the group
165 *
166 * @return string
167 */
168 public function __toString(): string {
169 return $this->title;
170 }
171
172 /**
173 * Get role
174 *
175 * @return string
176 */
177 public function getRole(): string {
178 return 'ROLE_'.strtoupper($this->title);
179 }
180 }