c21ca5f96d4c32fae0525cbc83efdf3ee161f4d2
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Domain / Model / BackendUser.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Domain\Model;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * This model represents a back-end user.
32 *
33 * @api
34 */
35 class BackendUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
36
37 /**
38 * @var string
39 * @validate notEmpty
40 */
41 protected $userName = '';
42
43 /**
44 * @var boolean
45 */
46 protected $isAdministrator = FALSE;
47
48 /**
49 * @var boolean
50 */
51 protected $isDisabled = FALSE;
52
53 /**
54 * @var \DateTime|NULL
55 */
56 protected $startDateAndTime = NULL;
57
58 /**
59 * @var \DateTime|NULL
60 */
61 protected $endDateAndTime = NULL;
62
63 /**
64 * @var string
65 */
66 protected $email = '';
67
68 /**
69 * @var string
70 */
71 protected $realName = '';
72
73 /**
74 * @var \DateTime|NULL
75 */
76 protected $lastLoginDateAndTime;
77
78 /**
79 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileMount>
80 */
81 protected $fileMounts = NULL;
82
83 /**
84 * @var boolean
85 */
86 protected $ipLockIsDisabled = FALSE;
87
88 /**
89 * Constructs this backend user
90 */
91 public function __construct() {
92 $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
93 }
94
95 /**
96 * Initialize object
97 *
98 * @return void
99 */
100 public function initializeObject() {
101 $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
102 }
103
104 /**
105 * Gets the user name.
106 *
107 * @return string the user name, will not be empty
108 */
109 public function getUserName() {
110 return $this->userName;
111 }
112
113 /**
114 * Sets the user name.
115 *
116 * @param string $userName the user name to set, must not be empty
117 * @return void
118 */
119 public function setUserName($userName) {
120 $this->userName = $userName;
121 }
122
123 /**
124 * Checks whether this user is an administrator.
125 *
126 * @return boolean whether this user is an administrator
127 */
128 public function getIsAdministrator() {
129 return $this->isAdministrator;
130 }
131
132 /**
133 * Sets whether this user should be an administrator.
134 *
135 * @param boolean $isAdministrator whether this user should be an administrator
136 * @return void
137 */
138 public function setIsAdministrator($isAdministrator) {
139 $this->isAdministrator = $isAdministrator;
140 }
141
142 /**
143 * Checks whether this user is disabled.
144 *
145 * @return boolean whether this user is disabled
146 */
147 public function getIsDisabled() {
148 return $this->isDisabled;
149 }
150
151 /**
152 * Sets whether this user is disabled.
153 *
154 * @param boolean $isDisabled whether this user is disabled
155 * @return void
156 */
157 public function setIsDisabled($isDisabled) {
158 $this->isDisabled = $isDisabled;
159 }
160
161 /**
162 * Returns the point in time from which this user is enabled.
163 *
164 * @return \DateTime|NULL the start date and time
165 */
166 public function getStartDateAndTime() {
167 return $this->startDateAndTime;
168 }
169
170 /**
171 * Sets the point in time from which this user is enabled.
172 *
173 * @param \DateTime|NULL $dateAndTime the start date and time
174 * @return void
175 */
176 public function setStartDateAndTime(\DateTime $dateAndTime = NULL) {
177 $this->startDateAndTime = $dateAndTime;
178 }
179
180 /**
181 * Returns the point in time before which this user is enabled.
182 *
183 * @return \DateTime|NULL the end date and time
184 */
185 public function getEndDateAndTime() {
186 return $this->endDateAndTime;
187 }
188
189 /**
190 * Sets the point in time before which this user is enabled.
191 *
192 * @param \DateTime|NULL $dateAndTime the end date and time
193 * @return void
194 */
195 public function setEndDateAndTime(\DateTime $dateAndTime = NULL) {
196 $this->endDateAndTime = $dateAndTime;
197 }
198
199 /**
200 * Gets the e-mail address of this user.
201 *
202 * @return string the e-mail address, might be empty
203 */
204 public function getEmail() {
205 return $this->email;
206 }
207
208 /**
209 * Sets the e-mail address of this user.
210 *
211 * @param string $email the e-mail address, may be empty
212 * @return void
213 */
214 public function setEmail($email) {
215 $this->email = $email;
216 }
217
218 /**
219 * Returns this user's real name.
220 *
221 * @return string the real name. might be empty
222 */
223 public function getRealName() {
224 return $this->realName;
225 }
226
227 /**
228 * Sets this user's real name.
229 *
230 * @param string $name the user's real name, may be empty.
231 */
232 public function setRealName($name) {
233 $this->realName = $name;
234 }
235
236 /**
237 * Checks whether this user is currently activated.
238 *
239 * This function takes the "disabled" flag, the start date/time and the end date/time into account.
240 *
241 * @return boolean whether this user is currently activated
242 */
243 public function isActivated() {
244 return !$this->getIsDisabled() && $this->isActivatedViaStartDateAndTime() && $this->isActivatedViaEndDateAndTime();
245 }
246
247 /**
248 * Checks whether this user is activated as far as the start date and time is concerned.
249 *
250 * @return boolean whether this user is activated as far as the start date and time is concerned
251 */
252 protected function isActivatedViaStartDateAndTime() {
253 if ($this->getStartDateAndTime() === NULL) {
254 return TRUE;
255 }
256 $now = new \DateTime('now');
257 return $this->getStartDateAndTime() <= $now;
258 }
259
260 /**
261 * Checks whether this user is activated as far as the end date and time is concerned.
262 *
263 * @return boolean whether this user is activated as far as the end date and time is concerned
264 */
265 protected function isActivatedViaEndDateAndTime() {
266 if ($this->getEndDateAndTime() === NULL) {
267 return TRUE;
268 }
269 $now = new \DateTime('now');
270 return $now <= $this->getEndDateAndTime();
271 }
272
273 /**
274 * Sets whether the IP lock for this user is disabled.
275 *
276 * @param boolean $disableIpLock whether the IP lock for this user is disabled
277 * @return void
278 */
279 public function setIpLockIsDisabled($disableIpLock) {
280 $this->ipLockIsDisabled = $disableIpLock;
281 }
282
283 /**
284 * Checks whether the IP lock for this user is disabled.
285 *
286 * @return boolean whether the IP lock for this user is disabled
287 */
288 public function getIpLockIsDisabled() {
289 return $this->ipLockIsDisabled;
290 }
291
292 /**
293 * Gets this user's last login date and time.
294 *
295 * @return \DateTime|NULL this user's last login date and time, will be NULL if this user has never logged in before
296 */
297 public function getLastLoginDateAndTime() {
298 return $this->lastLoginDateAndTime;
299 }
300
301 /**
302 * Sets this user's last login date and time.
303 *
304 * @param \DateTime|NULL $dateAndTime this user's last login date and time
305 * @return void
306 */
307 public function setLastLoginDateAndTime(\DateTime $dateAndTime = NULL) {
308 $this->lastLoginDateAndTime = $dateAndTime;
309 }
310
311 /**
312 * Setter for the file mounts
313 *
314 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $fileMounts
315 * @return void
316 */
317 public function setFileMounts(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $fileMounts) {
318 $this->fileMounts = $fileMounts;
319 }
320
321 /**
322 * Adds a file mount to this backend user
323 *
324 * @param \TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount
325 * @return void
326 */
327 public function addFileMount(\TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount) {
328 $this->fileMounts->attach($fileMount);
329 }
330
331 /**
332 * Removes file mount from this backend user
333 *
334 * @param \TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount
335 * @return void
336 */
337 public function removeFileMount(\TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount) {
338 $this->fileMounts->detach($fileMount);
339 }
340
341 /**
342 * Remove all file mounts from this backend user
343 *
344 * @return void
345 */
346 public function removeAllFileMounts() {
347 $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
348 }
349
350 /**
351 * Getter of file mounts
352 *
353 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
354 */
355 public function getFileMounts() {
356 return $this->fileMounts;
357 }
358 }
359
360 ?>