1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\DBAL\Types\BillingTypeType; |
8
|
|
|
use Application\DBAL\Types\BookingStatusType; |
9
|
|
|
use Application\DBAL\Types\RelationshipType; |
10
|
|
|
use Application\Repository\LogRepository; |
11
|
|
|
use Application\Repository\UserRepository; |
12
|
|
|
use Application\Service\Role; |
13
|
|
|
use Application\Traits\HasAddress; |
14
|
|
|
use Application\Traits\HasDoorAccess; |
15
|
|
|
use Application\Traits\HasIban; |
16
|
|
|
use Application\Traits\HasRemarks; |
17
|
|
|
use Cake\Chronos\Chronos; |
18
|
|
|
use Cake\Chronos\Date; |
19
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
20
|
|
|
use Doctrine\Common\Collections\Collection; |
21
|
|
|
use Doctrine\ORM\Mapping as ORM; |
22
|
|
|
use Ecodev\Felix\Api\Exception; |
23
|
|
|
use Ecodev\Felix\Model\CurrentUser; |
24
|
|
|
use Ecodev\Felix\Model\Traits\HasInternalRemarks; |
25
|
|
|
use Ecodev\Felix\Model\Traits\HasPassword; |
26
|
|
|
use GraphQL\Doctrine\Annotation as API; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* User |
30
|
|
|
* |
31
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\UserRepository") |
32
|
|
|
* @ORM\HasLifecycleCallbacks |
33
|
|
|
* @ORM\AssociationOverrides({ |
34
|
|
|
* @ORM\AssociationOverride(name="owner", inversedBy="users") |
35
|
|
|
* }) |
36
|
|
|
* @API\Sorting({ |
37
|
|
|
* "Application\Api\Input\Sorting\Age", |
38
|
|
|
* "Application\Api\Input\Sorting\Balance", |
39
|
|
|
* }) |
40
|
|
|
* @API\Filters({ |
41
|
|
|
* @API\Filter(field="custom", operator="Application\Api\Input\Operator\HasBookingWithTaggedBookableOperatorType", type="id"), |
42
|
|
|
* @API\Filter(field="custom", operator="Application\Api\Input\Operator\HasBookingWithBookableOperatorType", type="id"), |
43
|
|
|
* @API\Filter(field="balance", operator="Application\Api\Input\Operator\AccountBalance\EqualOperatorType", type="Money"), |
44
|
|
|
* @API\Filter(field="balance", operator="Application\Api\Input\Operator\AccountBalance\GreaterOperatorType", type="Money"), |
45
|
|
|
* @API\Filter(field="balance", operator="Application\Api\Input\Operator\AccountBalance\GreaterOrEqualOperatorType", type="Money"), |
46
|
|
|
* @API\Filter(field="balance", operator="Application\Api\Input\Operator\AccountBalance\LessOperatorType", type="Money"), |
47
|
|
|
* @API\Filter(field="balance", operator="Application\Api\Input\Operator\AccountBalance\LessOrEqualOperatorType", type="Money"), |
48
|
|
|
* }) |
49
|
|
|
*/ |
50
|
|
|
class User extends AbstractModel implements \Ecodev\Felix\Model\User |
51
|
|
|
{ |
52
|
|
|
const ROLE_ANONYMOUS = 'anonymous'; |
53
|
|
|
const ROLE_BOOKING_ONLY = 'booking_only'; |
54
|
|
|
const ROLE_INDIVIDUAL = 'individual'; |
55
|
|
|
const ROLE_MEMBER = 'member'; |
56
|
|
|
const ROLE_TRAINER = 'trainer'; |
57
|
|
|
const ROLE_RESPONSIBLE = 'responsible'; |
58
|
|
|
const ROLE_ADMINISTRATOR = 'administrator'; |
59
|
|
|
|
60
|
|
|
const STATUS_INACTIVE = 'inactive'; |
61
|
|
|
const STATUS_NEW = 'new'; |
62
|
|
|
const STATUS_ACTIVE = 'active'; |
63
|
|
|
const STATUS_ARCHIVED = 'archived'; |
64
|
|
|
|
65
|
|
|
use HasDoorAccess; |
66
|
|
|
use HasRemarks; |
67
|
|
|
use HasInternalRemarks; |
68
|
|
|
use HasAddress; |
69
|
|
|
use HasIban; |
70
|
|
|
use HasPassword; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var User |
74
|
|
|
*/ |
75
|
|
|
private static $currentUser; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Set currently logged in user |
79
|
|
|
* WARNING: this method should only be called from \Application\Authentication\AuthenticationListener |
80
|
|
|
* |
81
|
|
|
* @param \Application\Model\User $user |
82
|
|
|
*/ |
83
|
201 |
|
public static function setCurrent(?self $user): void |
84
|
|
|
{ |
85
|
201 |
|
self::$currentUser = $user; |
86
|
|
|
|
87
|
|
|
// Initalize ACL filter with current user if a logged in one exists |
88
|
|
|
/** @var UserRepository $userRepository */ |
89
|
201 |
|
$userRepository = _em()->getRepository(self::class); |
90
|
201 |
|
$aclFilter = $userRepository->getAclFilter(); |
91
|
201 |
|
$aclFilter->setUser($user); |
92
|
|
|
|
93
|
201 |
|
CurrentUser::set($user); |
94
|
201 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns currently logged user or null |
98
|
|
|
*/ |
99
|
78 |
|
public static function getCurrent(): ?self |
100
|
|
|
{ |
101
|
78 |
|
return self::$currentUser; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var null|string |
106
|
|
|
* |
107
|
|
|
* @ORM\Column(type="string", length=50, nullable=true, unique=true) |
108
|
|
|
*/ |
109
|
|
|
private $login; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var string |
113
|
|
|
* @ORM\Column(type="string", length=191) |
114
|
|
|
*/ |
115
|
|
|
private $firstName = ''; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var string |
119
|
|
|
* @ORM\Column(type="string", length=191) |
120
|
|
|
*/ |
121
|
|
|
private $lastName = ''; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @var null|string |
125
|
|
|
* @ORM\Column(type="string", length=191, nullable=true, unique=true) |
126
|
|
|
*/ |
127
|
|
|
private $email; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var string |
131
|
|
|
* @ORM\Column(type="UserRole", options={"default" = User::ROLE_INDIVIDUAL}) |
132
|
|
|
*/ |
133
|
|
|
private $role = self::ROLE_INDIVIDUAL; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var string |
137
|
|
|
* @ORM\Column(type="UserStatus", options={"default" = User::STATUS_NEW}) |
138
|
|
|
*/ |
139
|
|
|
private $status = self::STATUS_NEW; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @var null|Chronos |
143
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
144
|
|
|
*/ |
145
|
|
|
private $welcomeSessionDate; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @var null|Chronos |
149
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
150
|
|
|
*/ |
151
|
|
|
private $resignDate; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @var int sex |
155
|
|
|
* @ORM\Column(type="smallint", options={"default" = 0})) |
156
|
|
|
*/ |
157
|
|
|
private $sex = 0; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @var string |
161
|
|
|
* @ORM\Column(type="string", length=25, options={"default" = ""}) |
162
|
|
|
*/ |
163
|
|
|
private $phone = ''; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @var string |
167
|
|
|
* @ORM\Column(type="string", length=25, options={"default" = ""}) |
168
|
|
|
*/ |
169
|
|
|
private $mobilePhone = ''; |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @var string |
173
|
|
|
* @ORM\Column(type="string", length=25, options={"default" = ""}) |
174
|
|
|
*/ |
175
|
|
|
private $swissSailing = ''; |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @var string |
179
|
|
|
* @ORM\Column(type="SwissSailingType", nullable=true) |
180
|
|
|
*/ |
181
|
|
|
private $swissSailingType; |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @var string |
185
|
|
|
* @ORM\Column(type="SwissWindsurfType", nullable=true) |
186
|
|
|
*/ |
187
|
|
|
private $swissWindsurfType; |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @var null|Date |
191
|
|
|
* @ORM\Column(type="date", nullable=true) |
192
|
|
|
*/ |
193
|
|
|
private $birthday; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @var bool |
197
|
|
|
* @ORM\Column(type="boolean", options={"default" = 0}) |
198
|
|
|
*/ |
199
|
|
|
private $termsAgreement = false; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @var bool |
203
|
|
|
* @ORM\Column(type="boolean", options={"default" = 0}) |
204
|
|
|
*/ |
205
|
|
|
private $hasInsurance = false; |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @var bool |
209
|
|
|
* @ORM\Column(type="boolean", options={"default" = 0}) |
210
|
|
|
*/ |
211
|
|
|
private $receivesNewsletter = false; |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @var string |
215
|
|
|
* @ORM\Column(type="Relationship", options={"default" = RelationshipType::HOUSEHOLDER}) |
216
|
|
|
*/ |
217
|
|
|
private $familyRelationship = RelationshipType::HOUSEHOLDER; |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @var string |
221
|
|
|
* @ORM\Column(type="BillingType", options={"default" = BillingTypeType::ELECTRONIC}) |
222
|
|
|
*/ |
223
|
|
|
private $billingType = BillingTypeType::ELECTRONIC; |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @var Collection |
227
|
|
|
* @ORM\OneToMany(targetEntity="Booking", mappedBy="owner") |
228
|
|
|
*/ |
229
|
|
|
private $bookings; |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @var Collection |
233
|
|
|
* @ORM\ManyToMany(targetEntity="License", mappedBy="users") |
234
|
|
|
*/ |
235
|
|
|
private $licenses; |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @var Collection |
239
|
|
|
* @ORM\ManyToMany(targetEntity="UserTag", mappedBy="users") |
240
|
|
|
*/ |
241
|
|
|
private $userTags; |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @var Collection |
245
|
|
|
* @ORM\OneToMany(targetEntity="Message", mappedBy="recipient") |
246
|
|
|
*/ |
247
|
|
|
private $messages; |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* There is actually 0 to 1 account, never more. And this is |
251
|
|
|
* enforced by DB unique constraints |
252
|
|
|
* |
253
|
|
|
* @var Collection |
254
|
|
|
* @ORM\OneToMany(targetEntity="Account", mappedBy="owner") |
255
|
|
|
*/ |
256
|
|
|
private $accounts; |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @var Collection |
260
|
|
|
* @ORM\OneToMany(targetEntity="User", mappedBy="owner") |
261
|
|
|
*/ |
262
|
|
|
private $users; |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Constructor |
266
|
|
|
* |
267
|
|
|
* @param string $role role for new user |
268
|
|
|
*/ |
269
|
55 |
|
public function __construct(string $role = self::ROLE_INDIVIDUAL) |
270
|
|
|
{ |
271
|
55 |
|
$this->role = $role; |
272
|
55 |
|
$this->bookings = new ArrayCollection(); |
273
|
55 |
|
$this->accounts = new ArrayCollection(); |
274
|
55 |
|
$this->licenses = new ArrayCollection(); |
275
|
55 |
|
$this->userTags = new ArrayCollection(); |
276
|
55 |
|
$this->messages = new ArrayCollection(); |
277
|
55 |
|
$this->users = new ArrayCollection(); |
278
|
55 |
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Set login (eg: johndoe) |
282
|
|
|
* |
283
|
|
|
* @API\Input(type="Login") |
284
|
|
|
*/ |
285
|
4 |
|
public function setLogin(string $login): void |
286
|
|
|
{ |
287
|
4 |
|
$this->login = $login; |
288
|
4 |
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Get login (eg: johndoe) |
292
|
|
|
* |
293
|
|
|
* @API\Field(type="?Login") |
294
|
|
|
*/ |
295
|
26 |
|
public function getLogin(): ?string |
296
|
|
|
{ |
297
|
26 |
|
return $this->login; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Set first name |
302
|
|
|
* |
303
|
|
|
* @param string $firstName |
304
|
|
|
*/ |
305
|
10 |
|
public function setFirstName($firstName): void |
306
|
|
|
{ |
307
|
10 |
|
$this->firstName = $firstName; |
308
|
10 |
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Get first name |
312
|
|
|
*/ |
313
|
19 |
|
public function getFirstName(): string |
314
|
|
|
{ |
315
|
19 |
|
return (string) $this->firstName; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Set last name |
320
|
|
|
* |
321
|
|
|
* @param string $lastName |
322
|
|
|
*/ |
323
|
10 |
|
public function setLastName($lastName): void |
324
|
|
|
{ |
325
|
10 |
|
$this->lastName = $lastName; |
326
|
10 |
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Get last name |
330
|
|
|
*/ |
331
|
13 |
|
public function getLastName(): string |
332
|
|
|
{ |
333
|
13 |
|
return (string) $this->lastName; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Get full name |
338
|
|
|
*/ |
339
|
13 |
|
public function getName(): string |
340
|
|
|
{ |
341
|
13 |
|
return implode(' ', [$this->getFirstName(), $this->getLastName()]); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Set email |
346
|
|
|
* |
347
|
|
|
* @API\Input(type="?Email") |
348
|
|
|
*/ |
349
|
5 |
|
public function setEmail(?string $email): void |
350
|
|
|
{ |
351
|
5 |
|
$this->email = $email; |
352
|
5 |
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Get email |
356
|
|
|
* |
357
|
|
|
* @API\Field(type="?Email") |
358
|
|
|
*/ |
359
|
11 |
|
public function getEmail(): ?string |
360
|
|
|
{ |
361
|
11 |
|
return $this->email; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* Get the user role |
366
|
|
|
* |
367
|
|
|
* @API\Field(type="UserRole") |
368
|
|
|
*/ |
369
|
81 |
|
public function getRole(): string |
370
|
|
|
{ |
371
|
81 |
|
return $this->role; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Sets the user role |
376
|
|
|
* |
377
|
|
|
* @API\Input(type="UserRole") |
378
|
|
|
*/ |
379
|
7 |
|
public function setRole(string $role): void |
380
|
|
|
{ |
381
|
7 |
|
if (!Role::canUpdate(self::getCurrent(), $this->role, $role)) { |
382
|
3 |
|
$currentRole = self::getCurrent() ? self::getCurrent()->getRole() : self::ROLE_ANONYMOUS; |
383
|
|
|
|
384
|
3 |
|
throw new Exception($currentRole . ' is not allowed to change role from ' . $this->role . ' to ' . $role); |
385
|
|
|
} |
386
|
|
|
|
387
|
4 |
|
$this->role = $role; |
388
|
4 |
|
} |
389
|
|
|
|
390
|
5 |
|
public function setOwner(?self $owner = null): void |
391
|
|
|
{ |
392
|
5 |
|
if ($owner && $owner !== $this) { |
393
|
1 |
|
if ($owner->getOwner() && $owner !== $owner->getOwner()) { |
394
|
|
|
throw new Exception('This user cannot be owned by a user who is himself owned by somebody else'); |
395
|
|
|
} |
396
|
|
|
|
397
|
1 |
|
if ($this->users->count()) { |
398
|
|
|
throw new Exception('This user owns other users, so he cannot himself be owned by somebody else'); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|
402
|
5 |
|
if ($this->getOwner()) { |
403
|
2 |
|
$this->getOwner()->getEmail(); // Trigger lazy loading |
404
|
2 |
|
$this->getOwner()->users->removeElement($this); |
405
|
|
|
} |
406
|
|
|
|
407
|
5 |
|
parent::setOwner($owner); |
408
|
|
|
|
409
|
5 |
|
if ($this->getOwner()) { |
410
|
1 |
|
$this->getOwner()->getEmail(); // Trigger lazy loading |
411
|
1 |
|
$this->getOwner()->users->add($this); |
412
|
1 |
|
$this->setStatus($this->getOwner()->getStatus()); |
413
|
|
|
} |
414
|
5 |
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @API\Field(type="Application\Api\Enum\UserStatusType") |
418
|
|
|
*/ |
419
|
3 |
|
public function getStatus(): string |
420
|
|
|
{ |
421
|
3 |
|
return $this->status; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* @API\Input(type="Application\Api\Enum\UserStatusType") |
426
|
|
|
*/ |
427
|
10 |
|
public function setStatus(string $newStatus): void |
428
|
|
|
{ |
429
|
10 |
|
if ($newStatus === self::STATUS_ARCHIVED && $this->status !== self::STATUS_ARCHIVED) { |
430
|
1 |
|
$this->setResignDate(Chronos::NOW()); |
431
|
9 |
|
} elseif ($this->status === self::STATUS_ARCHIVED && $newStatus !== self::STATUS_ARCHIVED) { |
432
|
|
|
$this->setResignDate(null); |
433
|
|
|
} |
434
|
|
|
|
435
|
10 |
|
$this->status = $newStatus; |
436
|
10 |
|
$this->revokeToken(); |
437
|
|
|
|
438
|
10 |
|
foreach ($this->users as $user) { |
439
|
1 |
|
if ($user !== $this) { |
440
|
|
|
$user->setStatus($newStatus); |
441
|
|
|
} |
442
|
|
|
} |
443
|
10 |
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Whether this user is a family owner or not |
447
|
|
|
* |
448
|
|
|
* This is used for our internal logic and should |
449
|
|
|
* NEVER be related to `familyRelationship`. That field |
450
|
|
|
* is purely informative for humans. |
451
|
|
|
*/ |
452
|
1 |
|
public function isFamilyOwner(): bool |
453
|
|
|
{ |
454
|
1 |
|
return !$this->getOwner() || $this->getOwner() === $this; |
455
|
|
|
} |
456
|
|
|
|
457
|
1 |
|
public function initialize(): void |
458
|
|
|
{ |
459
|
1 |
|
$this->role = self::ROLE_MEMBER; // Bypass security |
460
|
1 |
|
$this->setStatus(self::STATUS_NEW); |
461
|
1 |
|
} |
462
|
|
|
|
463
|
|
|
public function getPhone(): string |
464
|
|
|
{ |
465
|
|
|
return $this->phone; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
public function setPhone(string $phone): void |
469
|
|
|
{ |
470
|
|
|
$this->phone = $phone; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
public function getMobilePhone(): string |
474
|
|
|
{ |
475
|
|
|
return $this->mobilePhone; |
476
|
|
|
} |
477
|
|
|
|
478
|
1 |
|
public function setMobilePhone(string $mobilePhone): void |
479
|
|
|
{ |
480
|
1 |
|
$this->mobilePhone = $mobilePhone; |
481
|
1 |
|
} |
482
|
|
|
|
483
|
|
|
public function getBirthday(): ?Date |
484
|
|
|
{ |
485
|
|
|
return $this->birthday; |
486
|
|
|
} |
487
|
|
|
|
488
|
1 |
|
public function setBirthday(?Date $birthday): void |
489
|
|
|
{ |
490
|
1 |
|
$this->birthday = $birthday; |
491
|
1 |
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* return null|int |
495
|
|
|
*/ |
496
|
|
|
public function getAge(): ?int |
497
|
|
|
{ |
498
|
|
|
if ($this->birthday) { |
499
|
|
|
return (new Date())->diffInYears($this->birthday); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
return null; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Get bookings |
507
|
|
|
*/ |
508
|
3 |
|
public function getBookings(): Collection |
509
|
|
|
{ |
510
|
3 |
|
return $this->bookings; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* Get active bookings (confirmed and non-terminated) |
515
|
|
|
* |
516
|
|
|
* @API\Exclude |
517
|
|
|
*/ |
518
|
2 |
|
public function getRunningBookings(): Collection |
519
|
|
|
{ |
520
|
2 |
|
return $this->bookings->filter(function (Booking $booking) { |
521
|
2 |
|
return $booking->getStatus() === BookingStatusType::BOOKED && $booking->getEndDate() === null; |
522
|
2 |
|
}); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* Notify the user that it has a new booking. |
527
|
|
|
* This should only be called by Booking::setResponsible() |
528
|
|
|
*/ |
529
|
16 |
|
public function bookingAdded(Booking $booking): void |
530
|
|
|
{ |
531
|
16 |
|
$this->bookings->add($booking); |
532
|
16 |
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Notify the user that it has a booking was removed. |
536
|
|
|
* This should only be called by Booking::setResponsible() |
537
|
|
|
*/ |
538
|
4 |
|
public function bookingRemoved(Booking $booking): void |
539
|
|
|
{ |
540
|
4 |
|
$this->bookings->removeElement($booking); |
541
|
4 |
|
} |
542
|
|
|
|
543
|
2 |
|
public function getLicenses(): Collection |
544
|
|
|
{ |
545
|
2 |
|
return $this->licenses; |
546
|
|
|
} |
547
|
|
|
|
548
|
1 |
|
public function getUserTags(): Collection |
549
|
|
|
{ |
550
|
1 |
|
return $this->userTags; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* Notify the user that it has a new license. |
555
|
|
|
* This should only be called by License::addUser() |
556
|
|
|
*/ |
557
|
1 |
|
public function licenseAdded(License $license): void |
558
|
|
|
{ |
559
|
1 |
|
$this->licenses->add($license); |
560
|
1 |
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* Notify the user that it a license was removed. |
564
|
|
|
* This should only be called by License::removeUser() |
565
|
|
|
*/ |
566
|
1 |
|
public function licenseRemoved(License $license): void |
567
|
|
|
{ |
568
|
1 |
|
$this->licenses->removeElement($license); |
569
|
1 |
|
} |
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Notify the user that it has a new userTag. |
573
|
|
|
* This should only be called by UserTag::addUser() |
574
|
|
|
*/ |
575
|
1 |
|
public function userTagAdded(UserTag $userTag): void |
576
|
|
|
{ |
577
|
1 |
|
$this->userTags->add($userTag); |
578
|
1 |
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Notify the user that a userTag was removed. |
582
|
|
|
* This should only be called by UserTag::removeUser() |
583
|
|
|
*/ |
584
|
1 |
|
public function userTagRemoved(UserTag $userTag): void |
585
|
|
|
{ |
586
|
1 |
|
$this->userTags->removeElement($userTag); |
587
|
1 |
|
} |
588
|
|
|
|
589
|
|
|
public function isTermsAgreement(): bool |
590
|
|
|
{ |
591
|
|
|
return $this->termsAgreement; |
592
|
|
|
} |
593
|
|
|
|
594
|
1 |
|
public function setTermsAgreement(bool $termsAgreement): void |
595
|
|
|
{ |
596
|
1 |
|
$this->termsAgreement = $termsAgreement; |
597
|
1 |
|
} |
598
|
|
|
|
599
|
|
|
public function hasInsurance(): bool |
600
|
|
|
{ |
601
|
|
|
return $this->hasInsurance; |
602
|
|
|
} |
603
|
|
|
|
604
|
1 |
|
public function setHasInsurance(bool $hasInsurance): void |
605
|
|
|
{ |
606
|
1 |
|
$this->hasInsurance = $hasInsurance; |
607
|
1 |
|
} |
608
|
|
|
|
609
|
|
|
public function getWelcomeSessionDate(): ?Chronos |
610
|
|
|
{ |
611
|
|
|
return $this->welcomeSessionDate; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
public function setWelcomeSessionDate(?Chronos $welcomeSessionDate): void |
615
|
|
|
{ |
616
|
|
|
$this->welcomeSessionDate = $welcomeSessionDate; |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
public function getResignDate(): ?Chronos |
620
|
|
|
{ |
621
|
|
|
return $this->resignDate; |
622
|
|
|
} |
623
|
|
|
|
624
|
1 |
|
public function setResignDate(?Chronos $resignDate): void |
625
|
|
|
{ |
626
|
1 |
|
$this->resignDate = $resignDate; |
627
|
1 |
|
} |
628
|
|
|
|
629
|
|
|
public function getReceivesNewsletter(): bool |
630
|
|
|
{ |
631
|
|
|
return $this->receivesNewsletter; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
public function setReceivesNewsletter(bool $receivesNewsletter): void |
635
|
|
|
{ |
636
|
|
|
$this->receivesNewsletter = $receivesNewsletter; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Get the sex |
641
|
|
|
* |
642
|
|
|
* @API\Field(type="Sex") |
643
|
|
|
*/ |
644
|
|
|
public function getSex(): int |
645
|
|
|
{ |
646
|
|
|
return $this->sex; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Set the sex |
651
|
|
|
* |
652
|
|
|
* @API\Input(type="Sex") |
653
|
|
|
*/ |
654
|
|
|
public function setSex(int $sex): void |
655
|
|
|
{ |
656
|
|
|
$this->sex = $sex; |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
660
|
|
|
* Get the Swiss Sailing licence number |
661
|
|
|
*/ |
662
|
|
|
public function getSwissSailing(): string |
663
|
|
|
{ |
664
|
|
|
return $this->swissSailing; |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
public function setSwissSailing(string $swissSailing): void |
668
|
|
|
{ |
669
|
|
|
$this->swissSailing = $swissSailing; |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* Get the Swiss Sailing licence type |
674
|
|
|
* |
675
|
|
|
* @API\Field(type="?SwissSailingType") |
676
|
|
|
*/ |
677
|
|
|
public function getSwissSailingType(): ?string |
678
|
|
|
{ |
679
|
|
|
return $this->swissSailingType; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* Set the Swiss Sailing licence type |
684
|
|
|
* |
685
|
|
|
* @API\Input(type="?SwissSailingType") |
686
|
|
|
*/ |
687
|
|
|
public function setSwissSailingType(?string $swissSailingType): void |
688
|
|
|
{ |
689
|
|
|
$this->swissSailingType = $swissSailingType; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* Get the Swiss Windsurf licence type |
694
|
|
|
* |
695
|
|
|
* @API\Field(type="?SwissWindsurfType") |
696
|
|
|
*/ |
697
|
|
|
public function getSwissWindsurfType(): ?string |
698
|
|
|
{ |
699
|
|
|
return $this->swissWindsurfType; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
/** |
703
|
|
|
* Set the Swiss Windsurf licence type |
704
|
|
|
* |
705
|
|
|
* @API\Input(type="?SwissWindsurfType") |
706
|
|
|
*/ |
707
|
|
|
public function setSwissWindsurfType(?string $swissWindsurfType): void |
708
|
|
|
{ |
709
|
|
|
$this->swissWindsurfType = $swissWindsurfType; |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* Get the first login date |
714
|
|
|
*/ |
715
|
|
|
public function getFirstLogin(): ?Chronos |
716
|
|
|
{ |
717
|
|
|
/** @var LogRepository $logRepository */ |
718
|
|
|
$logRepository = _em()->getRepository(Log::class); |
719
|
|
|
|
720
|
|
|
return $logRepository->getLoginDate($this, true); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
/** |
724
|
|
|
* Get the last login date |
725
|
|
|
*/ |
726
|
|
|
public function getLastLogin(): ?Chronos |
727
|
|
|
{ |
728
|
|
|
/** @var LogRepository $logRepository */ |
729
|
|
|
$logRepository = _em()->getRepository(Log::class); |
730
|
|
|
|
731
|
|
|
return $logRepository->getLoginDate($this, false); |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
/** |
735
|
|
|
* @API\Field(type="Relationship") |
736
|
|
|
*/ |
737
|
1 |
|
public function getFamilyRelationship(): string |
738
|
|
|
{ |
739
|
1 |
|
return $this->familyRelationship; |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
/** |
743
|
|
|
* @API\Input(type="Relationship") |
744
|
|
|
*/ |
745
|
1 |
|
public function setFamilyRelationship(string $familyRelationship): void |
746
|
|
|
{ |
747
|
1 |
|
$this->familyRelationship = $familyRelationship; |
748
|
1 |
|
} |
749
|
|
|
|
750
|
|
|
/** |
751
|
|
|
* @API\Field(type="BillingType") |
752
|
|
|
*/ |
753
|
|
|
public function getBillingType(): string |
754
|
|
|
{ |
755
|
|
|
return $this->billingType; |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
/** |
759
|
|
|
* @API\Input(type="BillingType") |
760
|
|
|
*/ |
761
|
|
|
public function setBillingType(string $billingType): void |
762
|
|
|
{ |
763
|
|
|
$this->billingType = $billingType; |
764
|
|
|
} |
765
|
|
|
|
766
|
|
|
/** |
767
|
|
|
* Get the user transaction account |
768
|
|
|
*/ |
769
|
28 |
|
public function getAccount(): ?Account |
770
|
|
|
{ |
771
|
28 |
|
if ($this->getOwner() && $this->getOwner() !== $this) { |
772
|
7 |
|
return $this->getOwner()->getAccount(); |
773
|
|
|
} |
774
|
|
|
|
775
|
28 |
|
return $this->accounts->count() ? $this->accounts->first() : null; |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* Notify the user that it has a new account |
780
|
|
|
* This should only be called by Account::setOwner() |
781
|
|
|
*/ |
782
|
14 |
|
public function accountAdded(Account $account): void |
783
|
|
|
{ |
784
|
14 |
|
$this->accounts->clear(); |
785
|
14 |
|
$this->accounts->add($account); |
786
|
14 |
|
} |
787
|
|
|
|
788
|
|
|
/** |
789
|
|
|
* Notify the user that a account was removed |
790
|
|
|
* This should only be called by Account::setOwner() |
791
|
|
|
*/ |
792
|
1 |
|
public function accountRemoved(): void |
793
|
|
|
{ |
794
|
1 |
|
$this->accounts->clear(); |
795
|
1 |
|
} |
796
|
|
|
|
797
|
|
|
/** |
798
|
|
|
* Get messages sent to the user |
799
|
|
|
*/ |
800
|
1 |
|
public function getMessages(): Collection |
801
|
|
|
{ |
802
|
1 |
|
return $this->messages; |
803
|
|
|
} |
804
|
|
|
|
805
|
|
|
/** |
806
|
|
|
* Notify the user that it has a new message |
807
|
|
|
* This should only be called by Message::setRecipient() |
808
|
|
|
*/ |
809
|
8 |
|
public function messageAdded(Message $message): void |
810
|
|
|
{ |
811
|
8 |
|
$this->messages->add($message); |
812
|
8 |
|
} |
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* Notify the user that a message was removed |
816
|
|
|
* This should only be called by Message::setRecipient() |
817
|
|
|
*/ |
818
|
1 |
|
public function messageRemoved(Message $message): void |
819
|
|
|
{ |
820
|
1 |
|
$this->messages->removeElement($message); |
821
|
1 |
|
} |
822
|
|
|
|
823
|
|
|
/** |
824
|
|
|
* Check if the user can *really* open a door |
825
|
|
|
* This also takes into account the user status and role |
826
|
|
|
* |
827
|
|
|
* @API\Field(args={@API\Argument(name="door", type="?Application\Api\Enum\DoorType")}) |
828
|
|
|
* |
829
|
|
|
* @param null|string $door a particular door, or null for any |
830
|
|
|
*/ |
831
|
6 |
|
public function getCanOpenDoor(?string $door = null): bool |
832
|
|
|
{ |
833
|
6 |
|
$allowedStatus = [self::STATUS_ACTIVE]; |
834
|
6 |
|
$allowedRoles = [self::ROLE_INDIVIDUAL, self::ROLE_MEMBER, self::ROLE_TRAINER, self::ROLE_RESPONSIBLE, self::ROLE_ADMINISTRATOR]; |
835
|
|
|
|
836
|
6 |
|
if ($door && !$this->$door) { |
837
|
3 |
|
return false; |
838
|
|
|
} |
839
|
|
|
|
840
|
6 |
|
if (!in_array($this->status, $allowedStatus, true) || !in_array($this->role, $allowedRoles, true)) { |
841
|
2 |
|
return false; |
842
|
|
|
} |
843
|
|
|
|
844
|
4 |
|
return true; |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
/** |
848
|
|
|
* Override parent to prevents users created from administration to be family of the administrator |
849
|
|
|
* |
850
|
|
|
* The owner must be explicitly set for all users. |
851
|
|
|
*/ |
852
|
3 |
|
protected function getOwnerForCreation(): ?self |
853
|
|
|
{ |
854
|
3 |
|
return null; |
855
|
|
|
} |
856
|
|
|
} |
857
|
|
|
|