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