]> Raphaƫl G. Git Repositories - userbundle/blob - Entity/User.php
Change homepage route to index
[userbundle] / Entity / User.php
1 <?php
2
3 // src/Rapsys/UserBundle/Entity/User.php
4 namespace Rapsys\UserBundle\Entity;
5
6 use Rapsys\UserBundle\Entity\Group;
7 use Symfony\Component\Security\Core\User\UserInterface;
8 use Doctrine\Common\Collections\ArrayCollection;
9
10 class User implements UserInterface, \Serializable {
11 /**
12 * @var integer
13 */
14 protected $id;
15
16 /**
17 * @var string
18 */
19 protected $mail;
20
21 /**
22 * @var string
23 */
24 protected $pseudonym;
25
26 /**
27 * @var string
28 */
29 protected $forename;
30
31 /**
32 * @var string
33 */
34 protected $surname;
35
36 /**
37 * @var string
38 */
39 protected $password;
40
41 /**
42 * @var bool
43 */
44 protected $active;
45
46 /**
47 * @var \DateTime
48 */
49 protected $created;
50
51 /**
52 * @var \DateTime
53 */
54 protected $updated;
55
56 /**
57 * @var \Rapsys\UserBundle\Entity\Title
58 */
59 protected $title;
60
61 /**
62 * @var \Doctrine\Common\Collections\Collection
63 */
64 protected $groups;
65
66 /**
67 * User constructor.
68 */
69 public function __construct() {
70 $this->active = false;
71 $this->groups = new ArrayCollection();
72 }
73
74 /**
75 * Get id
76 *
77 * @return integer
78 */
79 public function getId() {
80 return $this->id;
81 }
82
83 /**
84 * Set mail
85 *
86 * @param string $mail
87 *
88 * @return User
89 */
90 public function setMail($mail) {
91 $this->mail = $mail;
92
93 return $this;
94 }
95
96 /**
97 * Get mail
98 *
99 * @return string
100 */
101 public function getMail() {
102 return $this->mail;
103 }
104
105 /**
106 * Set pseudonym
107 *
108 * @param string $pseudonym
109 *
110 * @return User
111 */
112 public function setPseudonym($pseudonym) {
113 $this->pseudonym = $pseudonym;
114
115 return $this;
116 }
117
118 /**
119 * Get pseudonym
120 *
121 * @return string
122 */
123 public function getPseudonym() {
124 return $this->pseudonym;
125 }
126
127 /**
128 * Set forename
129 *
130 * @param string $forename
131 *
132 * @return User
133 */
134 public function setForename($forename) {
135 $this->forename = $forename;
136
137 return $this;
138 }
139
140 /**
141 * Get forename
142 *
143 * @return string
144 */
145 public function getForename() {
146 return $this->forename;
147 }
148
149 /**
150 * Set surname
151 *
152 * @param string $surname
153 *
154 * @return User
155 */
156 public function setSurname($surname) {
157 $this->surname = $surname;
158
159 return $this;
160 }
161
162 /**
163 * Get surname
164 *
165 * @return string
166 */
167 public function getSurname() {
168 return $this->surname;
169 }
170
171 /**
172 * Set password
173 *
174 * @param string $password
175 *
176 * @return User
177 */
178 public function setPassword($password) {
179 $this->password = $password;
180
181 return $this;
182 }
183
184 /**
185 * Get password
186 *
187 * @return string
188 */
189 public function getPassword() {
190 return $this->password;
191 }
192
193 /**
194 * Set active
195 *
196 * @param bool $active
197 *
198 * @return User
199 */
200 public function setActive($active) {
201 $this->active = $active;
202
203 return $this;
204 }
205
206 /**
207 * Get active
208 *
209 * @return bool
210 */
211 public function getActive() {
212 return $this->active;
213 }
214
215 /**
216 * Set created
217 *
218 * @param \DateTime $created
219 *
220 * @return User
221 */
222 public function setCreated($created) {
223 $this->created = $created;
224
225 return $this;
226 }
227
228 /**
229 * Get created
230 *
231 * @return \DateTime
232 */
233 public function getCreated() {
234 return $this->created;
235 }
236
237 /**
238 * Set updated
239 *
240 * @param \DateTime $updated
241 *
242 * @return User
243 */
244 public function setUpdated($updated) {
245 $this->updated = $updated;
246
247 return $this;
248 }
249
250 /**
251 * Get updated
252 *
253 * @return \DateTime
254 */
255 public function getUpdated() {
256 return $this->updated;
257 }
258
259 /**
260 * Set title
261 */
262 public function setTitle($title) {
263 $this->title = $title;
264
265 return $this;
266 }
267
268 /**
269 * Get title
270 */
271 public function getTitle() {
272 return $this->title;
273 }
274
275 /**
276 * Add group
277 *
278 * @param \Rapsys\UserBundle\Entity\Group $group
279 *
280 * @return User
281 */
282 public function addGroup(Group $group) {
283 $this->groups[] = $group;
284
285 return $this;
286 }
287
288 /**
289 * Remove group
290 *
291 * @param \Rapsys\UserBundle\Entity\Group $group
292 */
293 public function removeGroup(Group $group) {
294 $this->groups->removeElement($group);
295 }
296
297 /**
298 * Get groups
299 *
300 * @return \Doctrine\Common\Collections\Collection
301 */
302 public function getGroups() {
303 return $this->groups;
304 }
305
306 public function getRoles() {
307 $roles = [ 'ROLE_USER' ];
308
309 foreach($this->groups->toArray() as $group) {
310 $roles[] = $group->getRole();
311 }
312
313 return array_unique($roles);
314 }
315
316 public function getSalt() {
317 //No salt required with bcrypt
318 return null;
319 }
320
321 public function getUsername() {
322 return $this->mail;
323 }
324
325 public function eraseCredentials() {
326 }
327
328 public function serialize() {
329 return serialize(array(
330 $this->id,
331 $this->mail,
332 $this->password,
333 $this->active,
334 $this->created,
335 $this->updated
336 ));
337 }
338
339 public function unserialize($serialized) {
340 list(
341 $this->id,
342 $this->mail,
343 $this->password,
344 $this->active,
345 $this->created,
346 $this->updated
347 ) = unserialize($serialized);
348 }
349
350 //XXX: was from vendor/symfony/security-core/User/AdvancedUserInterface.php, see if it's used anymore
351 public function isEnabled() {
352 return $this->active;
353 }
354 }