|
1
|
|
|
<?php |
|
2
|
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace BristolSU\ControlDB\Models; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use BristolSU\ControlDB\AdditionalProperties\HasAdditionalProperties; |
|
8
|
|
|
use BristolSU\ControlDB\Traits\DataUserTrait; |
|
9
|
|
|
use DateTime; |
|
10
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
11
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Handles attributes belonging to a user |
|
15
|
|
|
*/ |
|
|
|
|
|
|
16
|
|
|
class DataUser extends Model implements \BristolSU\ControlDB\Contracts\Models\DataUser |
|
17
|
|
|
{ |
|
18
|
|
|
use SoftDeletes, HasAdditionalProperties, DataUserTrait { |
|
19
|
|
|
setFirstName as baseSetFirstName; |
|
20
|
|
|
setLastName as baseSetLastName; |
|
21
|
|
|
setEmail as baseSetEmail; |
|
22
|
|
|
setDob as baseSetDob; |
|
23
|
|
|
setPreferredName as baseSetPreferredName; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* The table to use |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $table = 'control_data_user'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Attributes that are fillable |
|
35
|
|
|
* |
|
36
|
|
|
* @var array |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $fillable = [ |
|
39
|
|
|
'first_name', 'last_name', 'email', 'dob', 'preferred_name' |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Casted attributes |
|
44
|
|
|
* |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $casts = [ |
|
48
|
|
|
'dob' => 'datetime' |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get the ID of the user |
|
53
|
|
|
* |
|
54
|
|
|
* @return int |
|
55
|
|
|
*/ |
|
56
|
35 |
|
public function id(): int |
|
57
|
|
|
{ |
|
58
|
35 |
|
return $this->id; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the first name for the user |
|
63
|
|
|
* |
|
64
|
|
|
* @return string|null |
|
65
|
|
|
*/ |
|
66
|
16 |
|
public function firstName(): ?string |
|
67
|
|
|
{ |
|
68
|
16 |
|
return $this->first_name; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the last name for the user |
|
73
|
|
|
* |
|
74
|
|
|
* @return string|null |
|
75
|
|
|
*/ |
|
76
|
16 |
|
public function lastName(): ?string |
|
77
|
|
|
{ |
|
78
|
16 |
|
return $this->last_name; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the email for the user |
|
83
|
|
|
* |
|
84
|
|
|
* @return string|null |
|
85
|
|
|
*/ |
|
86
|
16 |
|
public function email(): ?string |
|
87
|
|
|
{ |
|
88
|
16 |
|
return $this->email; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get the date of birth for the user |
|
93
|
|
|
* |
|
94
|
|
|
* @return DateTime|null |
|
95
|
|
|
*/ |
|
96
|
13 |
|
public function dob(): ?DateTime |
|
97
|
|
|
{ |
|
98
|
13 |
|
return $this->dob; |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get the preferred name for the user |
|
103
|
|
|
* |
|
104
|
|
|
* @return string|null |
|
105
|
|
|
*/ |
|
106
|
16 |
|
public function preferredName(): ?string |
|
107
|
|
|
{ |
|
108
|
16 |
|
return $this->preferred_name; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Set the users first name |
|
113
|
|
|
* |
|
114
|
|
|
* @param string|null $firstName |
|
|
|
|
|
|
115
|
|
|
*/ |
|
|
|
|
|
|
116
|
2 |
|
public function setFirstName(?string $firstName): void |
|
117
|
|
|
{ |
|
118
|
2 |
|
$this->baseSetFirstName($firstName); |
|
119
|
2 |
|
$this->refresh(); |
|
120
|
2 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Set the users last name |
|
124
|
|
|
* |
|
125
|
|
|
* @param string|null $lastName |
|
|
|
|
|
|
126
|
|
|
*/ |
|
|
|
|
|
|
127
|
2 |
|
public function setLastName(?string $lastName): void |
|
128
|
|
|
{ |
|
129
|
2 |
|
$this->baseSetLastName($lastName); |
|
130
|
2 |
|
$this->refresh(); |
|
131
|
2 |
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set the users email |
|
135
|
|
|
* |
|
136
|
|
|
* @param string|null $email |
|
|
|
|
|
|
137
|
|
|
*/ |
|
|
|
|
|
|
138
|
2 |
|
public function setEmail(?string $email): void |
|
139
|
|
|
{ |
|
140
|
2 |
|
$this->baseSetEmail($email); |
|
141
|
2 |
|
$this->refresh(); |
|
142
|
2 |
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Set the date of birth attribute |
|
146
|
|
|
* |
|
147
|
|
|
* @param DateTime|null $dob |
|
|
|
|
|
|
148
|
|
|
*/ |
|
|
|
|
|
|
149
|
2 |
|
public function setDob(?DateTime $dob): void |
|
150
|
|
|
{ |
|
151
|
2 |
|
$this->baseSetDob($dob); |
|
152
|
2 |
|
$this->refresh(); |
|
153
|
2 |
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Set the preferred name for the user |
|
157
|
|
|
* |
|
158
|
|
|
* @param string|null $name |
|
|
|
|
|
|
159
|
|
|
*/ |
|
|
|
|
|
|
160
|
2 |
|
public function setPreferredName(?string $name): void |
|
161
|
|
|
{ |
|
162
|
2 |
|
$this->baseSetPreferredName($name); |
|
163
|
2 |
|
$this->refresh(); |
|
164
|
2 |
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|