[FEATURE] Add userGroups to backendUser model
[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 \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup>
50 */
51 protected $backendUserGroups = NULL;
52
53 /**
54 * @var boolean
55 */
56 protected $isDisabled = FALSE;
57
58 /**
59 * @var \DateTime|NULL
60 */
61 protected $startDateAndTime = NULL;
62
63 /**
64 * @var \DateTime|NULL
65 */
66 protected $endDateAndTime = NULL;
67
68 /**
69 * @var string
70 */
71 protected $email = '';
72
73 /**
74 * @var string
75 */
76 protected $realName = '';
77
78 /**
79 * @var \DateTime|NULL
80 */
81 protected $lastLoginDateAndTime;
82
83 /**
84 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileMount>
85 */
86 protected $fileMounts = NULL;
87
88 /**
89 * @var boolean
90 */
91 protected $ipLockIsDisabled = FALSE;
92
93 /**
94 * Constructs this backend user
95 */
96 public function __construct() {
97 $this->initializeObject();
98 }
99
100 /**
101 * Initialize object
102 *
103 * @return void
104 */
105 public function initializeObject() {
106 $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
107 $this->backendUserGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
108 }
109
110 /**
111 * Gets the user name.
112 *
113 * @return string the user name, will not be empty
114 */
115 public function getUserName() {
116 return $this->userName;
117 }
118
119 /**
120 * Sets the user name.
121 *
122 * @param string $userName the user name to set, must not be empty
123 * @return void
124 */
125 public function setUserName($userName) {
126 $this->userName = $userName;
127 }
128
129 /**
130 * Checks whether this user is an administrator.
131 *
132 * @return boolean whether this user is an administrator
133 */
134 public function getIsAdministrator() {
135 return $this->isAdministrator;
136 }
137
138 /**
139 * Sets whether this user should be an administrator.
140 *
141 * @param boolean $isAdministrator whether this user should be an administrator
142 * @return void
143 */
144 public function setIsAdministrator($isAdministrator) {
145 $this->isAdministrator = $isAdministrator;
146 }
147
148 /**
149 * Getter for the backend user groups
150 *
151 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup>
152 */
153 public function getBackendUserGroups() {
154 return $this->backendUserGroups;
155 }
156
157 /**
158 * Setter for the backend user groups
159 *
160 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $backendUserGroups
161 * @return void
162 */
163 public function setBackendUserGroups(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $backendUserGroups) {
164 $this->backendUserGroups = $backendUserGroups;
165 }
166
167 /**
168 * Adds a backend user group to this backend user
169 *
170 * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup
171 * @return void
172 */
173 public function addBackendUserGroup(\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup) {
174 $this->backendUserGroups->attach($backendUserGroup);
175 }
176
177 /**
178 * Removes backend user group from this backend user
179 *
180 * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup
181 * @return void
182 */
183 public function removeBackendUserGroup(\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup) {
184 $this->backendUserGroups->detach($backendUserGroup);
185 }
186
187 /**
188 * Remove all backend user groups from this backend user
189 *
190 * @return void
191 */
192 public function removeAllBackendUserGroups() {
193 $this->backendUserGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
194 }
195
196 /**
197 * Checks whether this user is disabled.
198 *
199 * @return boolean whether this user is disabled
200 */
201 public function getIsDisabled() {
202 return $this->isDisabled;
203 }
204
205 /**
206 * Sets whether this user is disabled.
207 *
208 * @param boolean $isDisabled whether this user is disabled
209 * @return void
210 */
211 public function setIsDisabled($isDisabled) {
212 $this->isDisabled = $isDisabled;
213 }
214
215 /**
216 * Returns the point in time from which this user is enabled.
217 *
218 * @return \DateTime|NULL the start date and time
219 */
220 public function getStartDateAndTime() {
221 return $this->startDateAndTime;
222 }
223
224 /**
225 * Sets the point in time from which this user is enabled.
226 *
227 * @param \DateTime|NULL $dateAndTime the start date and time
228 * @return void
229 */
230 public function setStartDateAndTime(\DateTime $dateAndTime = NULL) {
231 $this->startDateAndTime = $dateAndTime;
232 }
233
234 /**
235 * Returns the point in time before which this user is enabled.
236 *
237 * @return \DateTime|NULL the end date and time
238 */
239 public function getEndDateAndTime() {
240 return $this->endDateAndTime;
241 }
242
243 /**
244 * Sets the point in time before which this user is enabled.
245 *
246 * @param \DateTime|NULL $dateAndTime the end date and time
247 * @return void
248 */
249 public function setEndDateAndTime(\DateTime $dateAndTime = NULL) {
250 $this->endDateAndTime = $dateAndTime;
251 }
252
253 /**
254 * Gets the e-mail address of this user.
255 *
256 * @return string the e-mail address, might be empty
257 */
258 public function getEmail() {
259 return $this->email;
260 }
261
262 /**
263 * Sets the e-mail address of this user.
264 *
265 * @param string $email the e-mail address, may be empty
266 * @return void
267 */
268 public function setEmail($email) {
269 $this->email = $email;
270 }
271
272 /**
273 * Returns this user's real name.
274 *
275 * @return string the real name. might be empty
276 */
277 public function getRealName() {
278 return $this->realName;
279 }
280
281 /**
282 * Sets this user's real name.
283 *
284 * @param string $name the user's real name, may be empty.
285 */
286 public function setRealName($name) {
287 $this->realName = $name;
288 }
289
290 /**
291 * Checks whether this user is currently activated.
292 *
293 * This function takes the "disabled" flag, the start date/time and the end date/time into account.
294 *
295 * @return boolean whether this user is currently activated
296 */
297 public function isActivated() {
298 return !$this->getIsDisabled() && $this->isActivatedViaStartDateAndTime() && $this->isActivatedViaEndDateAndTime();
299 }
300
301 /**
302 * Checks whether this user is activated as far as the start date and time is concerned.
303 *
304 * @return boolean whether this user is activated as far as the start date and time is concerned
305 */
306 protected function isActivatedViaStartDateAndTime() {
307 if ($this->getStartDateAndTime() === NULL) {
308 return TRUE;
309 }
310 $now = new \DateTime('now');
311 return $this->getStartDateAndTime() <= $now;
312 }
313
314 /**
315 * Checks whether this user is activated as far as the end date and time is concerned.
316 *
317 * @return boolean whether this user is activated as far as the end date and time is concerned
318 */
319 protected function isActivatedViaEndDateAndTime() {
320 if ($this->getEndDateAndTime() === NULL) {
321 return TRUE;
322 }
323 $now = new \DateTime('now');
324 return $now <= $this->getEndDateAndTime();
325 }
326
327 /**
328 * Sets whether the IP lock for this user is disabled.
329 *
330 * @param boolean $disableIpLock whether the IP lock for this user is disabled
331 * @return void
332 */
333 public function setIpLockIsDisabled($disableIpLock) {
334 $this->ipLockIsDisabled = $disableIpLock;
335 }
336
337 /**
338 * Checks whether the IP lock for this user is disabled.
339 *
340 * @return boolean whether the IP lock for this user is disabled
341 */
342 public function getIpLockIsDisabled() {
343 return $this->ipLockIsDisabled;
344 }
345
346 /**
347 * Gets this user's last login date and time.
348 *
349 * @return \DateTime|NULL this user's last login date and time, will be NULL if this user has never logged in before
350 */
351 public function getLastLoginDateAndTime() {
352 return $this->lastLoginDateAndTime;
353 }
354
355 /**
356 * Sets this user's last login date and time.
357 *
358 * @param \DateTime|NULL $dateAndTime this user's last login date and time
359 * @return void
360 */
361 public function setLastLoginDateAndTime(\DateTime $dateAndTime = NULL) {
362 $this->lastLoginDateAndTime = $dateAndTime;
363 }
364
365 /**
366 * Setter for the file mounts
367 *
368 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $fileMounts
369 * @return void
370 */
371 public function setFileMounts(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $fileMounts) {
372 $this->fileMounts = $fileMounts;
373 }
374
375 /**
376 * Adds a file mount to this backend user
377 *
378 * @param \TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount
379 * @return void
380 */
381 public function addFileMount(\TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount) {
382 $this->fileMounts->attach($fileMount);
383 }
384
385 /**
386 * Removes file mount from this backend user
387 *
388 * @param \TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount
389 * @return void
390 */
391 public function removeFileMount(\TYPO3\CMS\Extbase\Domain\Model\FileMount $fileMount) {
392 $this->fileMounts->detach($fileMount);
393 }
394
395 /**
396 * Remove all file mounts from this backend user
397 *
398 * @return void
399 */
400 public function removeAllFileMounts() {
401 $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
402 }
403
404 /**
405 * Getter of file mounts
406 *
407 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
408 */
409 public function getFileMounts() {
410 return $this->fileMounts;
411 }
412 }
413
414 ?>