|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace BristolSU\ControlDB\Traits; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use BristolSU\ControlDB\Contracts\Models\User; |
|
8
|
|
|
use DateTime; |
|
9
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Implements methods to the data user interface using repositories |
|
13
|
|
|
*/ |
|
|
|
|
|
|
14
|
|
|
trait DataUserTrait |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Get the user using the data user |
|
19
|
|
|
* |
|
20
|
|
|
* @return User|null |
|
21
|
|
|
*/ |
|
22
|
2 |
|
public function user(): ?User |
|
23
|
|
|
{ |
|
24
|
|
|
try { |
|
25
|
2 |
|
return app(\BristolSU\ControlDB\Contracts\Repositories\User::class)->getByDataProviderId($this->id()); |
|
|
|
|
|
|
26
|
1 |
|
} catch (ModelNotFoundException $e) { |
|
27
|
1 |
|
return null; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Set the users first name |
|
33
|
|
|
* |
|
34
|
|
|
* @param string|null $firstName |
|
|
|
|
|
|
35
|
|
|
*/ |
|
|
|
|
|
|
36
|
2 |
|
public function setFirstName(?string $firstName): void |
|
37
|
|
|
{ |
|
38
|
2 |
|
app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( |
|
39
|
2 |
|
$this->id(), $firstName, $this->lastName(), $this->email(), $this->dob(), $this->preferredName() |
|
|
|
|
|
|
40
|
|
|
); |
|
41
|
2 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Set the users last name |
|
45
|
|
|
* |
|
46
|
|
|
* @param string|null $lastName |
|
|
|
|
|
|
47
|
|
|
*/ |
|
|
|
|
|
|
48
|
2 |
|
public function setLastName(?string $lastName): void |
|
49
|
|
|
{ |
|
50
|
2 |
|
app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( |
|
51
|
2 |
|
$this->id(), $this->firstName(), $lastName, $this->email(), $this->dob(), $this->preferredName() |
|
|
|
|
|
|
52
|
|
|
); |
|
53
|
2 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set the users email |
|
57
|
|
|
* |
|
58
|
|
|
* @param string|null $email |
|
|
|
|
|
|
59
|
|
|
*/ |
|
|
|
|
|
|
60
|
2 |
|
public function setEmail(?string $email): void |
|
61
|
|
|
{ |
|
62
|
2 |
|
app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( |
|
63
|
2 |
|
$this->id(), $this->firstName(), $this->lastName(), $email, $this->dob(), $this->preferredName() |
|
64
|
|
|
); |
|
65
|
2 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Set the date of birth attribute |
|
69
|
|
|
* |
|
70
|
|
|
* @param DateTime|null $dob |
|
|
|
|
|
|
71
|
|
|
*/ |
|
|
|
|
|
|
72
|
2 |
|
public function setDob(?DateTime $dob): void |
|
73
|
|
|
{ |
|
74
|
2 |
|
app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( |
|
75
|
2 |
|
$this->id(), $this->firstName(), $this->lastName(), $this->email(), $dob, $this->preferredName() |
|
76
|
|
|
); |
|
77
|
2 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Set the preferred name for the user |
|
81
|
|
|
* |
|
82
|
|
|
* @param string|null $name |
|
|
|
|
|
|
83
|
|
|
*/ |
|
|
|
|
|
|
84
|
2 |
|
public function setPreferredName(?string $name): void |
|
85
|
|
|
{ |
|
86
|
2 |
|
app(\BristolSU\ControlDB\Contracts\Repositories\DataUser::class)->update( |
|
87
|
2 |
|
$this->id(), $this->firstName(), $this->lastName(), $this->email(), $this->dob(), $name |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
} |