1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the TYPO3 CMS project. |
5
|
|
|
* |
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
8
|
|
|
* of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please read the |
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* The TYPO3 project - inspiring people to share! |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace TYPO3\CMS\Extbase\Domain\Model; |
17
|
|
|
|
18
|
|
|
use TYPO3\CMS\Extbase\Annotation as Extbase; |
19
|
|
|
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* This model represents a back-end user. |
23
|
|
|
*/ |
24
|
|
|
class BackendUser extends AbstractEntity |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
* @Extbase\Validate("NotEmpty") |
29
|
|
|
*/ |
30
|
|
|
protected $userName = ''; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $description = ''; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
protected $isAdministrator = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
protected $isDisabled = false; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \DateTime|null |
49
|
|
|
*/ |
50
|
|
|
protected $startDateAndTime; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \DateTime|null |
54
|
|
|
*/ |
55
|
|
|
protected $endDateAndTime; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
protected $email = ''; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $realName = ''; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var \DateTime|null |
69
|
|
|
*/ |
70
|
|
|
protected $lastLoginDateAndTime; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Gets the user name. |
74
|
|
|
* |
75
|
|
|
* @return string the user name, will not be empty |
76
|
|
|
*/ |
77
|
|
|
public function getUserName() |
78
|
|
|
{ |
79
|
|
|
return $this->userName; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Sets the user name. |
84
|
|
|
* |
85
|
|
|
* @param string $userName the user name to set, must not be empty |
86
|
|
|
*/ |
87
|
|
|
public function setUserName($userName) |
88
|
|
|
{ |
89
|
|
|
$this->userName = $userName; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getDescription() |
96
|
|
|
{ |
97
|
|
|
return $this->description; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $description |
102
|
|
|
*/ |
103
|
|
|
public function setDescription($description) |
104
|
|
|
{ |
105
|
|
|
$this->description = $description; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Checks whether this user is an administrator. |
110
|
|
|
* |
111
|
|
|
* @return bool whether this user is an administrator |
112
|
|
|
*/ |
113
|
|
|
public function getIsAdministrator() |
114
|
|
|
{ |
115
|
|
|
return $this->isAdministrator; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Sets whether this user should be an administrator. |
120
|
|
|
* |
121
|
|
|
* @param bool $isAdministrator whether this user should be an administrator |
122
|
|
|
*/ |
123
|
|
|
public function setIsAdministrator($isAdministrator) |
124
|
|
|
{ |
125
|
|
|
$this->isAdministrator = $isAdministrator; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Checks whether this user is disabled. |
130
|
|
|
* |
131
|
|
|
* @return bool whether this user is disabled |
132
|
|
|
*/ |
133
|
|
|
public function getIsDisabled() |
134
|
|
|
{ |
135
|
|
|
return $this->isDisabled; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Sets whether this user is disabled. |
140
|
|
|
* |
141
|
|
|
* @param bool $isDisabled whether this user is disabled |
142
|
|
|
*/ |
143
|
|
|
public function setIsDisabled($isDisabled) |
144
|
|
|
{ |
145
|
|
|
$this->isDisabled = $isDisabled; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Returns the point in time from which this user is enabled. |
150
|
|
|
* |
151
|
|
|
* @return \DateTime|null the start date and time |
152
|
|
|
*/ |
153
|
|
|
public function getStartDateAndTime() |
154
|
|
|
{ |
155
|
|
|
return $this->startDateAndTime; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Sets the point in time from which this user is enabled. |
160
|
|
|
* |
161
|
|
|
* @param \DateTime|null $dateAndTime the start date and time |
162
|
|
|
*/ |
163
|
|
|
public function setStartDateAndTime(\DateTime $dateAndTime = null) |
164
|
|
|
{ |
165
|
|
|
$this->startDateAndTime = $dateAndTime; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns the point in time before which this user is enabled. |
170
|
|
|
* |
171
|
|
|
* @return \DateTime|null the end date and time |
172
|
|
|
*/ |
173
|
|
|
public function getEndDateAndTime() |
174
|
|
|
{ |
175
|
|
|
return $this->endDateAndTime; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Sets the point in time before which this user is enabled. |
180
|
|
|
* |
181
|
|
|
* @param \DateTime|null $dateAndTime the end date and time |
182
|
|
|
*/ |
183
|
|
|
public function setEndDateAndTime(\DateTime $dateAndTime = null) |
184
|
|
|
{ |
185
|
|
|
$this->endDateAndTime = $dateAndTime; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Gets the e-mail address of this user. |
190
|
|
|
* |
191
|
|
|
* @return string the e-mail address, might be empty |
192
|
|
|
*/ |
193
|
|
|
public function getEmail() |
194
|
|
|
{ |
195
|
|
|
return $this->email; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Sets the e-mail address of this user. |
200
|
|
|
* |
201
|
|
|
* @param string $email the e-mail address, may be empty |
202
|
|
|
*/ |
203
|
|
|
public function setEmail($email) |
204
|
|
|
{ |
205
|
|
|
$this->email = $email; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Returns this user's real name. |
210
|
|
|
* |
211
|
|
|
* @return string the real name. might be empty |
212
|
|
|
*/ |
213
|
|
|
public function getRealName() |
214
|
|
|
{ |
215
|
|
|
return $this->realName; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Sets this user's real name. |
220
|
|
|
* |
221
|
|
|
* @param string $name the user's real name, may be empty. |
222
|
|
|
*/ |
223
|
|
|
public function setRealName($name) |
224
|
|
|
{ |
225
|
|
|
$this->realName = $name; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Checks whether this user is currently activated. |
230
|
|
|
* |
231
|
|
|
* This function takes the "disabled" flag, the start date/time and the end date/time into account. |
232
|
|
|
* |
233
|
|
|
* @return bool whether this user is currently activated |
234
|
|
|
*/ |
235
|
|
|
public function isActivated() |
236
|
|
|
{ |
237
|
|
|
return !$this->getIsDisabled() && $this->isActivatedViaStartDateAndTime() && $this->isActivatedViaEndDateAndTime(); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Checks whether this user is activated as far as the start date and time is concerned. |
242
|
|
|
* |
243
|
|
|
* @return bool whether this user is activated as far as the start date and time is concerned |
244
|
|
|
*/ |
245
|
|
|
protected function isActivatedViaStartDateAndTime() |
246
|
|
|
{ |
247
|
|
|
if ($this->getStartDateAndTime() === null) { |
248
|
|
|
return true; |
249
|
|
|
} |
250
|
|
|
$now = new \DateTime('now'); |
251
|
|
|
return $this->getStartDateAndTime() <= $now; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Checks whether this user is activated as far as the end date and time is concerned. |
256
|
|
|
* |
257
|
|
|
* @return bool whether this user is activated as far as the end date and time is concerned |
258
|
|
|
*/ |
259
|
|
|
protected function isActivatedViaEndDateAndTime() |
260
|
|
|
{ |
261
|
|
|
if ($this->getEndDateAndTime() === null) { |
262
|
|
|
return true; |
263
|
|
|
} |
264
|
|
|
$now = new \DateTime('now'); |
265
|
|
|
return $now <= $this->getEndDateAndTime(); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Gets this user's last login date and time. |
270
|
|
|
* |
271
|
|
|
* @return \DateTime|null this user's last login date and time, will be NULL if this user has never logged in before |
272
|
|
|
*/ |
273
|
|
|
public function getLastLoginDateAndTime() |
274
|
|
|
{ |
275
|
|
|
return $this->lastLoginDateAndTime; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Sets this user's last login date and time. |
280
|
|
|
* |
281
|
|
|
* @param \DateTime|null $dateAndTime this user's last login date and time |
282
|
|
|
*/ |
283
|
|
|
public function setLastLoginDateAndTime(\DateTime $dateAndTime = null) |
284
|
|
|
{ |
285
|
|
|
$this->lastLoginDateAndTime = $dateAndTime; |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|