|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oro\Bundle\UserBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\Common\Collections\Collection; |
|
7
|
|
|
use Doctrine\ORM\Event\PreUpdateEventArgs; |
|
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
9
|
|
|
|
|
10
|
|
|
use JMS\Serializer\Annotation as JMS; |
|
11
|
|
|
|
|
12
|
|
|
use Oro\Bundle\DataAuditBundle\Metadata\Annotation as Oro; |
|
13
|
|
|
use Oro\Bundle\EmailBundle\Entity\EmailOrigin; |
|
14
|
|
|
use Oro\Bundle\EmailBundle\Entity\EmailOwnerInterface; |
|
15
|
|
|
use Oro\Bundle\EmailBundle\Model\EmailHolderInterface; |
|
16
|
|
|
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config; |
|
17
|
|
|
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField; |
|
18
|
|
|
use Oro\Bundle\ImapBundle\Entity\UserEmailOrigin; |
|
19
|
|
|
use Oro\Bundle\ImapBundle\Form\Model\AccountTypeModel; |
|
20
|
|
|
use Oro\Bundle\LocaleBundle\Model\FullNameInterface; |
|
21
|
|
|
use Oro\Bundle\NotificationBundle\Entity\NotificationEmailInterface; |
|
22
|
|
|
use Oro\Bundle\OrganizationBundle\Entity\BusinessUnit; |
|
23
|
|
|
use Oro\Bundle\OrganizationBundle\Entity\OrganizationInterface; |
|
24
|
|
|
use Oro\Bundle\UserBundle\Model\ExtendUser; |
|
25
|
|
|
use Oro\Bundle\UserBundle\Security\AdvancedApiUserInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @SuppressWarnings(PHPMD.ExcessivePublicCount) |
|
29
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
|
30
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassLength) |
|
31
|
|
|
* |
|
32
|
|
|
* @ORM\Entity(repositoryClass="Oro\Bundle\UserBundle\Entity\Repository\UserRepository") |
|
33
|
|
|
* @ORM\Table(name="oro_user", indexes = { |
|
34
|
|
|
* @ORM\Index("user_first_name_last_name_idx", columns = {"first_name", "last_name"}) |
|
35
|
|
|
* }) |
|
36
|
|
|
* @ORM\HasLifecycleCallbacks() |
|
37
|
|
|
* @Oro\Loggable |
|
38
|
|
|
* @Config( |
|
39
|
|
|
* routeName="oro_user_index", |
|
40
|
|
|
* routeView="oro_user_view", |
|
41
|
|
|
* defaultValues={ |
|
42
|
|
|
* "entity"={ |
|
43
|
|
|
* "icon"="icon-user" |
|
44
|
|
|
* }, |
|
45
|
|
|
* "grouping"={ |
|
46
|
|
|
* "groups"={"dictionary"} |
|
47
|
|
|
* }, |
|
48
|
|
|
* "dictionary"={ |
|
49
|
|
|
* "virtual_fields"={"id"}, |
|
50
|
|
|
* "search_fields"={"firstName", "lastName"}, |
|
51
|
|
|
* "representation_field"="fullName", |
|
52
|
|
|
* "activity_support"="true" |
|
53
|
|
|
* }, |
|
54
|
|
|
* "ownership"={ |
|
55
|
|
|
* "owner_type"="BUSINESS_UNIT", |
|
56
|
|
|
* "owner_field_name"="owner", |
|
57
|
|
|
* "owner_column_name"="business_unit_owner_id", |
|
58
|
|
|
* "organization_field_name"="organization", |
|
59
|
|
|
* "organization_column_name"="organization_id" |
|
60
|
|
|
* }, |
|
61
|
|
|
* "dataaudit"={"auditable"=true}, |
|
62
|
|
|
* "security"={ |
|
63
|
|
|
* "type"="ACL", |
|
64
|
|
|
* "group_name"="" |
|
65
|
|
|
* }, |
|
66
|
|
|
* "form"={ |
|
67
|
|
|
* "form_type"="oro_user_select", |
|
68
|
|
|
* "grid_name"="users-select-grid" |
|
69
|
|
|
* }, |
|
70
|
|
|
* "grid"={ |
|
71
|
|
|
* "default"="users-grid", |
|
72
|
|
|
* "context"="users-for-context-grid" |
|
73
|
|
|
* }, |
|
74
|
|
|
* "tag"={ |
|
75
|
|
|
* "enabled"=true |
|
76
|
|
|
* } |
|
77
|
|
|
* } |
|
78
|
|
|
* ) |
|
79
|
|
|
* @JMS\ExclusionPolicy("ALL") |
|
80
|
|
|
*/ |
|
81
|
|
|
class User extends ExtendUser implements |
|
82
|
|
|
EmailOwnerInterface, |
|
83
|
|
|
EmailHolderInterface, |
|
84
|
|
|
FullNameInterface, |
|
85
|
|
|
NotificationEmailInterface, |
|
86
|
|
|
AdvancedApiUserInterface |
|
87
|
|
|
{ |
|
88
|
|
|
const ROLE_DEFAULT = 'ROLE_USER'; |
|
89
|
|
|
const ROLE_ADMINISTRATOR = 'ROLE_ADMINISTRATOR'; |
|
90
|
|
|
const ROLE_ANONYMOUS = 'IS_AUTHENTICATED_ANONYMOUSLY'; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @ORM\Id |
|
94
|
|
|
* @ORM\Column(type="integer") |
|
95
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
96
|
|
|
* @JMS\Type("integer") |
|
97
|
|
|
* @JMS\Expose |
|
98
|
|
|
*/ |
|
99
|
|
|
protected $id; |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @var string |
|
103
|
|
|
* |
|
104
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
|
105
|
|
|
* @JMS\Type("string") |
|
106
|
|
|
* @JMS\Expose |
|
107
|
|
|
* @Oro\Versioned |
|
108
|
|
|
* @ConfigField( |
|
109
|
|
|
* defaultValues={ |
|
110
|
|
|
* "dataaudit"={ |
|
111
|
|
|
* "auditable"=true |
|
112
|
|
|
* }, |
|
113
|
|
|
* "importexport"={ |
|
114
|
|
|
* "identity"=true |
|
115
|
|
|
* } |
|
116
|
|
|
* } |
|
117
|
|
|
* ) |
|
118
|
|
|
*/ |
|
119
|
|
|
protected $username; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @var string |
|
123
|
|
|
* |
|
124
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
|
125
|
|
|
* @JMS\Type("string") |
|
126
|
|
|
* @JMS\Expose |
|
127
|
|
|
* @Oro\Versioned |
|
128
|
|
|
* @ConfigField( |
|
129
|
|
|
* defaultValues={ |
|
130
|
|
|
* "dataaudit"={ |
|
131
|
|
|
* "auditable"=true |
|
132
|
|
|
* } |
|
133
|
|
|
* } |
|
134
|
|
|
* ) |
|
135
|
|
|
*/ |
|
136
|
|
|
protected $email; |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Name prefix |
|
140
|
|
|
* |
|
141
|
|
|
* @var string |
|
142
|
|
|
* |
|
143
|
|
|
* @ORM\Column(name="name_prefix", type="string", length=255, nullable=true) |
|
144
|
|
|
* @JMS\Type("string") |
|
145
|
|
|
* @JMS\Expose |
|
146
|
|
|
* @Oro\Versioned |
|
147
|
|
|
* @ConfigField( |
|
148
|
|
|
* defaultValues={ |
|
149
|
|
|
* "dataaudit"={ |
|
150
|
|
|
* "auditable"=true |
|
151
|
|
|
* } |
|
152
|
|
|
* } |
|
153
|
|
|
* ) |
|
154
|
|
|
*/ |
|
155
|
|
|
protected $namePrefix; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* First name |
|
159
|
|
|
* |
|
160
|
|
|
* @var string |
|
161
|
|
|
* |
|
162
|
|
|
* @ORM\Column(name="first_name", type="string", length=255, nullable=true) |
|
163
|
|
|
* @JMS\Type("string") |
|
164
|
|
|
* @JMS\Expose |
|
165
|
|
|
* @Oro\Versioned |
|
166
|
|
|
* @ConfigField( |
|
167
|
|
|
* defaultValues={ |
|
168
|
|
|
* "dataaudit"={ |
|
169
|
|
|
* "auditable"=true |
|
170
|
|
|
* } |
|
171
|
|
|
* } |
|
172
|
|
|
* ) |
|
173
|
|
|
*/ |
|
174
|
|
|
protected $firstName; |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Middle name |
|
178
|
|
|
* |
|
179
|
|
|
* @var string |
|
180
|
|
|
* |
|
181
|
|
|
* @ORM\Column(name="middle_name", type="string", length=255, nullable=true) |
|
182
|
|
|
* @JMS\Type("string") |
|
183
|
|
|
* @JMS\Expose |
|
184
|
|
|
* @Oro\Versioned |
|
185
|
|
|
* @ConfigField( |
|
186
|
|
|
* defaultValues={ |
|
187
|
|
|
* "dataaudit"={ |
|
188
|
|
|
* "auditable"=true |
|
189
|
|
|
* } |
|
190
|
|
|
* } |
|
191
|
|
|
* ) |
|
192
|
|
|
*/ |
|
193
|
|
|
protected $middleName; |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Last name |
|
197
|
|
|
* |
|
198
|
|
|
* @var string |
|
199
|
|
|
* |
|
200
|
|
|
* @ORM\Column(name="last_name", type="string", length=255, nullable=true) |
|
201
|
|
|
* @JMS\Type("string") |
|
202
|
|
|
* @JMS\Expose |
|
203
|
|
|
* @Oro\Versioned |
|
204
|
|
|
* @ConfigField( |
|
205
|
|
|
* defaultValues={ |
|
206
|
|
|
* "dataaudit"={ |
|
207
|
|
|
* "auditable"=true |
|
208
|
|
|
* } |
|
209
|
|
|
* } |
|
210
|
|
|
* ) |
|
211
|
|
|
*/ |
|
212
|
|
|
protected $lastName; |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Name suffix |
|
216
|
|
|
* |
|
217
|
|
|
* @var string |
|
218
|
|
|
* |
|
219
|
|
|
* @ORM\Column(name="name_suffix", type="string", length=255, nullable=true) |
|
220
|
|
|
* @JMS\Type("string") |
|
221
|
|
|
* @JMS\Expose |
|
222
|
|
|
* @Oro\Versioned |
|
223
|
|
|
* @ConfigField( |
|
224
|
|
|
* defaultValues={ |
|
225
|
|
|
* "dataaudit"={ |
|
226
|
|
|
* "auditable"=true |
|
227
|
|
|
* } |
|
228
|
|
|
* } |
|
229
|
|
|
* ) |
|
230
|
|
|
*/ |
|
231
|
|
|
protected $nameSuffix; |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @var Group[]|Collection |
|
235
|
|
|
* |
|
236
|
|
|
* @ORM\ManyToMany(targetEntity="Oro\Bundle\UserBundle\Entity\Group") |
|
237
|
|
|
* @ORM\JoinTable(name="oro_user_access_group", |
|
238
|
|
|
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")}, |
|
239
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id", onDelete="CASCADE")} |
|
240
|
|
|
* ) |
|
241
|
|
|
* @Oro\Versioned("getName") |
|
242
|
|
|
* @ConfigField( |
|
243
|
|
|
* defaultValues={ |
|
244
|
|
|
* "dataaudit"={ |
|
245
|
|
|
* "auditable"=true |
|
246
|
|
|
* } |
|
247
|
|
|
* } |
|
248
|
|
|
* ) |
|
249
|
|
|
*/ |
|
250
|
|
|
protected $groups; |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* @var \DateTime |
|
254
|
|
|
* |
|
255
|
|
|
* @ORM\Column(name="birthday", type="date", nullable=true) |
|
256
|
|
|
* @JMS\Type("DateTime") |
|
257
|
|
|
* @JMS\Expose |
|
258
|
|
|
* @Oro\Versioned |
|
259
|
|
|
* @ConfigField( |
|
260
|
|
|
* defaultValues={ |
|
261
|
|
|
* "dataaudit"={ |
|
262
|
|
|
* "auditable"=true |
|
263
|
|
|
* } |
|
264
|
|
|
* } |
|
265
|
|
|
* ) |
|
266
|
|
|
*/ |
|
267
|
|
|
protected $birthday; |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* @var bool |
|
271
|
|
|
* |
|
272
|
|
|
* @ORM\Column(type="boolean") |
|
273
|
|
|
* @JMS\Type("boolean") |
|
274
|
|
|
* @JMS\Expose |
|
275
|
|
|
* @Oro\Versioned |
|
276
|
|
|
* @ConfigField( |
|
277
|
|
|
* defaultValues={ |
|
278
|
|
|
* "dataaudit"={ |
|
279
|
|
|
* "auditable"=true |
|
280
|
|
|
* } |
|
281
|
|
|
* } |
|
282
|
|
|
* ) |
|
283
|
|
|
*/ |
|
284
|
|
|
protected $enabled = true; |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @var \DateTime |
|
288
|
|
|
* |
|
289
|
|
|
* @ORM\Column(name="last_login", type="datetime", nullable=true) |
|
290
|
|
|
* @JMS\Type("DateTime") |
|
291
|
|
|
* @JMS\Expose |
|
292
|
|
|
* @ConfigField( |
|
293
|
|
|
* defaultValues={ |
|
294
|
|
|
* "importexport"={ |
|
295
|
|
|
* "excluded"=true |
|
296
|
|
|
* } |
|
297
|
|
|
* } |
|
298
|
|
|
* ) |
|
299
|
|
|
*/ |
|
300
|
|
|
protected $lastLogin; |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* @var BusinessUnit |
|
304
|
|
|
* @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\BusinessUnit", cascade={"persist"}) |
|
305
|
|
|
* @ORM\JoinColumn(name="business_unit_owner_id", referencedColumnName="id", onDelete="SET NULL") |
|
306
|
|
|
* @ConfigField( |
|
307
|
|
|
* defaultValues={ |
|
308
|
|
|
* "importexport"={ |
|
309
|
|
|
* "excluded"=true |
|
310
|
|
|
* } |
|
311
|
|
|
* } |
|
312
|
|
|
* ) |
|
313
|
|
|
*/ |
|
314
|
|
|
protected $owner; |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* @var UserApi[]|Collection |
|
318
|
|
|
* |
|
319
|
|
|
* @ORM\OneToMany( |
|
320
|
|
|
* targetEntity="UserApi", mappedBy="user", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EXTRA_LAZY" |
|
321
|
|
|
* ) |
|
322
|
|
|
* @ConfigField( |
|
323
|
|
|
* defaultValues={ |
|
324
|
|
|
* "importexport"={ |
|
325
|
|
|
* "excluded"=true |
|
326
|
|
|
* }, |
|
327
|
|
|
* "email"={ |
|
328
|
|
|
* "available_in_template"=false |
|
329
|
|
|
* } |
|
330
|
|
|
* } |
|
331
|
|
|
* ) |
|
332
|
|
|
*/ |
|
333
|
|
|
protected $apiKeys; |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* @var Status[]|Collection |
|
337
|
|
|
* |
|
338
|
|
|
* @ORM\OneToMany(targetEntity="Status", mappedBy="user") |
|
339
|
|
|
* @ORM\OrderBy({"createdAt" = "DESC"}) |
|
340
|
|
|
*/ |
|
341
|
|
|
protected $statuses; |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @var Status |
|
345
|
|
|
* |
|
346
|
|
|
* @ORM\OneToOne(targetEntity="Status") |
|
347
|
|
|
* @ORM\JoinColumn(name="status_id", referencedColumnName="id", nullable=true) |
|
348
|
|
|
*/ |
|
349
|
|
|
protected $currentStatus; |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* @var Email[]|Collection |
|
353
|
|
|
* |
|
354
|
|
|
* @ORM\OneToMany(targetEntity="Email", mappedBy="user", orphanRemoval=true, cascade={"persist"}) |
|
355
|
|
|
* @ConfigField( |
|
356
|
|
|
* defaultValues={ |
|
357
|
|
|
* "dataaudit"={ |
|
358
|
|
|
* "auditable"=true |
|
359
|
|
|
* } |
|
360
|
|
|
* } |
|
361
|
|
|
* ) |
|
362
|
|
|
*/ |
|
363
|
|
|
protected $emails; |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @var BusinessUnit[]|Collection |
|
367
|
|
|
* |
|
368
|
|
|
* @ORM\ManyToMany(targetEntity="Oro\Bundle\OrganizationBundle\Entity\BusinessUnit", inversedBy="users") |
|
369
|
|
|
* @ORM\JoinTable(name="oro_user_business_unit", |
|
370
|
|
|
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")}, |
|
371
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="business_unit_id", referencedColumnName="id", onDelete="CASCADE")} |
|
372
|
|
|
* ) |
|
373
|
|
|
* @Oro\Versioned("getName") |
|
374
|
|
|
* @ConfigField( |
|
375
|
|
|
* defaultValues={ |
|
376
|
|
|
* "dataaudit"={ |
|
377
|
|
|
* "auditable"=true |
|
378
|
|
|
* } |
|
379
|
|
|
* } |
|
380
|
|
|
* ) |
|
381
|
|
|
*/ |
|
382
|
|
|
protected $businessUnits; |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* @var EmailOrigin[]|Collection |
|
386
|
|
|
* |
|
387
|
|
|
* @ORM\OneToMany( |
|
388
|
|
|
* targetEntity="Oro\Bundle\EmailBundle\Entity\EmailOrigin", mappedBy="owner", cascade={"persist", "remove"} |
|
389
|
|
|
* ) |
|
390
|
|
|
*/ |
|
391
|
|
|
protected $emailOrigins; |
|
392
|
|
|
|
|
393
|
|
|
/** |
|
394
|
|
|
* @var \DateTime $createdAt |
|
395
|
|
|
* |
|
396
|
|
|
* @ORM\Column(type="datetime") |
|
397
|
|
|
* @ConfigField( |
|
398
|
|
|
* defaultValues={ |
|
399
|
|
|
* "entity"={ |
|
400
|
|
|
* "label"="oro.ui.created_at" |
|
401
|
|
|
* } |
|
402
|
|
|
* } |
|
403
|
|
|
* ) |
|
404
|
|
|
*/ |
|
405
|
|
|
protected $createdAt; |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* @var AccountTypeModel |
|
409
|
|
|
*/ |
|
410
|
|
|
protected $imapAccountType; |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* @var \DateTime $updatedAt |
|
414
|
|
|
* |
|
415
|
|
|
* @ORM\Column(type="datetime") |
|
416
|
|
|
* @ConfigField( |
|
417
|
|
|
* defaultValues={ |
|
418
|
|
|
* "entity"={ |
|
419
|
|
|
* "label"="oro.ui.updated_at" |
|
420
|
|
|
* } |
|
421
|
|
|
* } |
|
422
|
|
|
* ) |
|
423
|
|
|
*/ |
|
424
|
|
|
protected $updatedAt; |
|
425
|
|
|
|
|
426
|
|
|
/** |
|
427
|
|
|
* @var OrganizationInterface |
|
428
|
|
|
* |
|
429
|
|
|
* Organization that user logged in |
|
430
|
|
|
*/ |
|
431
|
|
|
protected $currentOrganization; |
|
432
|
|
|
|
|
433
|
|
|
public function __construct() |
|
434
|
|
|
{ |
|
435
|
|
|
parent::__construct(); |
|
436
|
|
|
|
|
437
|
|
|
$this->statuses = new ArrayCollection(); |
|
438
|
|
|
$this->emails = new ArrayCollection(); |
|
439
|
|
|
$this->businessUnits = new ArrayCollection(); |
|
440
|
|
|
$this->emailOrigins = new ArrayCollection(); |
|
441
|
|
|
$this->apiKeys = new ArrayCollection(); |
|
442
|
|
|
$this->groups = new ArrayCollection(); |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* {@inheritdoc} |
|
447
|
|
|
*/ |
|
448
|
|
|
public function getClass() |
|
449
|
|
|
{ |
|
450
|
|
|
return __CLASS__; |
|
451
|
|
|
} |
|
452
|
|
|
|
|
453
|
|
|
/** |
|
454
|
|
|
* {@inheritdoc} |
|
455
|
|
|
*/ |
|
456
|
|
|
public function getEmailFields() |
|
457
|
|
|
{ |
|
458
|
|
|
return ['email']; |
|
459
|
|
|
} |
|
460
|
|
|
|
|
461
|
|
|
/** |
|
462
|
|
|
* {@inheritdoc} |
|
463
|
|
|
*/ |
|
464
|
|
|
public function getFirstName() |
|
465
|
|
|
{ |
|
466
|
|
|
return $this->firstName; |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* @param string $firstName [optional] New first name value. Null by default. |
|
471
|
|
|
* |
|
472
|
|
|
* @return User |
|
473
|
|
|
*/ |
|
474
|
|
|
public function setFirstName($firstName = null) |
|
475
|
|
|
{ |
|
476
|
|
|
$this->firstName = $firstName; |
|
477
|
|
|
|
|
478
|
|
|
return $this; |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
/** |
|
482
|
|
|
* {@inheritdoc} |
|
483
|
|
|
*/ |
|
484
|
|
|
public function getLastName() |
|
485
|
|
|
{ |
|
486
|
|
|
return $this->lastName; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
/** |
|
490
|
|
|
* @param string $lastName [optional] New last name value. Null by default. |
|
491
|
|
|
* |
|
492
|
|
|
* @return User |
|
493
|
|
|
*/ |
|
494
|
|
|
public function setLastName($lastName = null) |
|
495
|
|
|
{ |
|
496
|
|
|
$this->lastName = $lastName; |
|
497
|
|
|
|
|
498
|
|
|
return $this; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
/** |
|
502
|
|
|
* {@inheritdoc} |
|
503
|
|
|
*/ |
|
504
|
|
|
public function getMiddleName() |
|
505
|
|
|
{ |
|
506
|
|
|
return $this->middleName; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
/** |
|
510
|
|
|
* Set middle name |
|
511
|
|
|
* |
|
512
|
|
|
* @param string $middleName |
|
513
|
|
|
* |
|
514
|
|
|
* @return User |
|
515
|
|
|
*/ |
|
516
|
|
|
public function setMiddleName($middleName) |
|
517
|
|
|
{ |
|
518
|
|
|
$this->middleName = $middleName; |
|
519
|
|
|
|
|
520
|
|
|
return $this; |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
/** |
|
524
|
|
|
* {@inheritdoc} |
|
525
|
|
|
*/ |
|
526
|
|
|
public function getNamePrefix() |
|
527
|
|
|
{ |
|
528
|
|
|
return $this->namePrefix; |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* Set name prefix |
|
533
|
|
|
* |
|
534
|
|
|
* @param string $namePrefix |
|
535
|
|
|
* |
|
536
|
|
|
* @return User |
|
537
|
|
|
*/ |
|
538
|
|
|
public function setNamePrefix($namePrefix) |
|
539
|
|
|
{ |
|
540
|
|
|
$this->namePrefix = $namePrefix; |
|
541
|
|
|
|
|
542
|
|
|
return $this; |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* {@inheritdoc} |
|
547
|
|
|
*/ |
|
548
|
|
|
public function getNameSuffix() |
|
549
|
|
|
{ |
|
550
|
|
|
return $this->nameSuffix; |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* Set name suffix |
|
555
|
|
|
* |
|
556
|
|
|
* @param string $nameSuffix |
|
557
|
|
|
* |
|
558
|
|
|
* @return User |
|
559
|
|
|
*/ |
|
560
|
|
|
public function setNameSuffix($nameSuffix) |
|
561
|
|
|
{ |
|
562
|
|
|
$this->nameSuffix = $nameSuffix; |
|
563
|
|
|
|
|
564
|
|
|
return $this; |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* Return birthday |
|
569
|
|
|
* |
|
570
|
|
|
* @return \DateTime |
|
571
|
|
|
*/ |
|
572
|
|
|
public function getBirthday() |
|
573
|
|
|
{ |
|
574
|
|
|
return $this->birthday; |
|
575
|
|
|
} |
|
576
|
|
|
|
|
577
|
|
|
/** |
|
578
|
|
|
* |
|
579
|
|
|
* @param \DateTime $birthday [optional] New birthday value. Null by default. |
|
580
|
|
|
* |
|
581
|
|
|
* @return User |
|
582
|
|
|
*/ |
|
583
|
|
|
public function setBirthday(\DateTime $birthday = null) |
|
584
|
|
|
{ |
|
585
|
|
|
$this->birthday = $birthday; |
|
586
|
|
|
|
|
587
|
|
|
return $this; |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
/** |
|
591
|
|
|
* Get user created date/time |
|
592
|
|
|
* |
|
593
|
|
|
* @return \DateTime |
|
594
|
|
|
*/ |
|
595
|
|
|
public function getCreatedAt() |
|
596
|
|
|
{ |
|
597
|
|
|
return $this->createdAt; |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* @param \DateTime $createdAt |
|
602
|
|
|
* |
|
603
|
|
|
* @return User |
|
604
|
|
|
*/ |
|
605
|
|
|
public function setCreatedAt(\DateTime $createdAt) |
|
606
|
|
|
{ |
|
607
|
|
|
$this->createdAt = $createdAt; |
|
608
|
|
|
|
|
609
|
|
|
return $this; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
/** |
|
613
|
|
|
* Get user last update date/time |
|
614
|
|
|
* |
|
615
|
|
|
* @return \DateTime |
|
616
|
|
|
*/ |
|
617
|
|
|
public function getUpdatedAt() |
|
618
|
|
|
{ |
|
619
|
|
|
return $this->updatedAt; |
|
620
|
|
|
} |
|
621
|
|
|
|
|
622
|
|
|
/** |
|
623
|
|
|
* @param \DateTime $updatedAt |
|
624
|
|
|
* |
|
625
|
|
|
* @return User |
|
626
|
|
|
*/ |
|
627
|
|
|
public function setUpdatedAt(\DateTime $updatedAt) |
|
628
|
|
|
{ |
|
629
|
|
|
$this->updatedAt = $updatedAt; |
|
630
|
|
|
|
|
631
|
|
|
return $this; |
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
/** |
|
635
|
|
|
* {@inheritdoc} |
|
636
|
|
|
*/ |
|
637
|
|
|
public function getApiKeys() |
|
638
|
|
|
{ |
|
639
|
|
|
return $this->apiKeys; |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
/** |
|
643
|
|
|
* Add UserApi to User |
|
644
|
|
|
* |
|
645
|
|
|
* @param UserApi $api |
|
646
|
|
|
* |
|
647
|
|
|
* @return User |
|
648
|
|
|
*/ |
|
649
|
|
|
public function addApiKey(UserApi $api) |
|
650
|
|
|
{ |
|
651
|
|
|
if (!$this->apiKeys->contains($api)) { |
|
652
|
|
|
$this->apiKeys->add($api); |
|
653
|
|
|
$api->setUser($this); |
|
654
|
|
|
} |
|
655
|
|
|
|
|
656
|
|
|
return $this; |
|
657
|
|
|
} |
|
658
|
|
|
|
|
659
|
|
|
/** |
|
660
|
|
|
* Delete UserApi from User |
|
661
|
|
|
* |
|
662
|
|
|
* @param UserApi $api |
|
663
|
|
|
* |
|
664
|
|
|
* @return User |
|
665
|
|
|
*/ |
|
666
|
|
|
public function removeApiKey(UserApi $api) |
|
667
|
|
|
{ |
|
668
|
|
|
if ($this->apiKeys->contains($api)) { |
|
669
|
|
|
$this->apiKeys->removeElement($api); |
|
670
|
|
|
} |
|
671
|
|
|
|
|
672
|
|
|
return $this; |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
/** |
|
676
|
|
|
* Returns the true Collection of Roles. |
|
677
|
|
|
* |
|
678
|
|
|
* @deprecated since 1.8 |
|
679
|
|
|
* |
|
680
|
|
|
* @return Collection |
|
681
|
|
|
*/ |
|
682
|
|
|
public function getRolesCollection() |
|
683
|
|
|
{ |
|
684
|
|
|
return $this->roles; |
|
|
|
|
|
|
685
|
|
|
} |
|
686
|
|
|
|
|
687
|
|
|
/** |
|
688
|
|
|
* Directly set the Collection of Roles. |
|
689
|
|
|
* |
|
690
|
|
|
* @deprecated since 1.8 |
|
691
|
|
|
* |
|
692
|
|
|
* @param Collection $collection |
|
693
|
|
|
* |
|
694
|
|
|
* @return User |
|
695
|
|
|
* @throws \InvalidArgumentException |
|
696
|
|
|
*/ |
|
697
|
|
|
public function setRolesCollection($collection) |
|
698
|
|
|
{ |
|
699
|
|
|
if (!$collection instanceof Collection) { |
|
700
|
|
|
throw new \InvalidArgumentException( |
|
701
|
|
|
'$collection must be an instance of Doctrine\Common\Collections\Collection' |
|
702
|
|
|
); |
|
703
|
|
|
} |
|
704
|
|
|
$this->roles = $collection; |
|
705
|
|
|
|
|
706
|
|
|
return $this; |
|
707
|
|
|
} |
|
708
|
|
|
|
|
709
|
|
|
/** |
|
710
|
|
|
* Pre persist event listener |
|
711
|
|
|
* |
|
712
|
|
|
* @ORM\PrePersist |
|
713
|
|
|
*/ |
|
714
|
|
|
public function beforeSave() |
|
715
|
|
|
{ |
|
716
|
|
|
$this->createdAt = new \DateTime('now', new \DateTimeZone('UTC')); |
|
717
|
|
|
$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC')); |
|
718
|
|
|
$this->loginCount = 0; |
|
719
|
|
|
} |
|
720
|
|
|
|
|
721
|
|
|
/** |
|
722
|
|
|
* Invoked before the entity is updated. |
|
723
|
|
|
* |
|
724
|
|
|
* @ORM\PreUpdate |
|
725
|
|
|
* |
|
726
|
|
|
* @param PreUpdateEventArgs $event |
|
727
|
|
|
*/ |
|
728
|
|
|
public function preUpdate(PreUpdateEventArgs $event) |
|
729
|
|
|
{ |
|
730
|
|
|
$excludedFields = ['lastLogin', 'loginCount']; |
|
731
|
|
|
|
|
732
|
|
|
if (array_diff_key($event->getEntityChangeSet(), array_flip($excludedFields))) { |
|
733
|
|
|
$this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC')); |
|
734
|
|
|
} |
|
735
|
|
|
} |
|
736
|
|
|
|
|
737
|
|
|
/** |
|
738
|
|
|
* Get User Statuses |
|
739
|
|
|
* |
|
740
|
|
|
* @return Status[]|Collection |
|
741
|
|
|
*/ |
|
742
|
|
|
public function getStatuses() |
|
743
|
|
|
{ |
|
744
|
|
|
return $this->statuses; |
|
745
|
|
|
} |
|
746
|
|
|
|
|
747
|
|
|
/** |
|
748
|
|
|
* Add Status to User |
|
749
|
|
|
* |
|
750
|
|
|
* @param Status $status |
|
751
|
|
|
* |
|
752
|
|
|
* @return User |
|
753
|
|
|
*/ |
|
754
|
|
|
public function addStatus(Status $status) |
|
755
|
|
|
{ |
|
756
|
|
|
if (!$this->statuses->contains($status)) { |
|
757
|
|
|
$this->statuses->add($status); |
|
758
|
|
|
} |
|
759
|
|
|
|
|
760
|
|
|
return $this; |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
/** |
|
764
|
|
|
* Get Current Status |
|
765
|
|
|
* |
|
766
|
|
|
* @return Status |
|
767
|
|
|
*/ |
|
768
|
|
|
public function getCurrentStatus() |
|
769
|
|
|
{ |
|
770
|
|
|
return $this->currentStatus; |
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
|
/** |
|
774
|
|
|
* Set User Current Status |
|
775
|
|
|
* |
|
776
|
|
|
* @param Status $status |
|
777
|
|
|
* |
|
778
|
|
|
* @return User |
|
779
|
|
|
*/ |
|
780
|
|
|
public function setCurrentStatus(Status $status = null) |
|
781
|
|
|
{ |
|
782
|
|
|
$this->currentStatus = $status; |
|
783
|
|
|
|
|
784
|
|
|
return $this; |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
/** |
|
788
|
|
|
* Get User Emails |
|
789
|
|
|
* |
|
790
|
|
|
* @return Email[]|Collection |
|
791
|
|
|
*/ |
|
792
|
|
|
public function getEmails() |
|
793
|
|
|
{ |
|
794
|
|
|
return $this->emails; |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
/** |
|
798
|
|
|
* Add Email to User |
|
799
|
|
|
* |
|
800
|
|
|
* @param Email $email |
|
801
|
|
|
* |
|
802
|
|
|
* @return User |
|
803
|
|
|
*/ |
|
804
|
|
|
public function addEmail(Email $email) |
|
805
|
|
|
{ |
|
806
|
|
|
if (!$this->emails->contains($email)) { |
|
807
|
|
|
$this->emails->add($email); |
|
808
|
|
|
$email->setUser($this); |
|
809
|
|
|
} |
|
810
|
|
|
|
|
811
|
|
|
return $this; |
|
812
|
|
|
} |
|
813
|
|
|
|
|
814
|
|
|
/** |
|
815
|
|
|
* Delete Email from User |
|
816
|
|
|
* |
|
817
|
|
|
* @param Email $email |
|
818
|
|
|
* |
|
819
|
|
|
* @return User |
|
820
|
|
|
*/ |
|
821
|
|
|
public function removeEmail(Email $email) |
|
822
|
|
|
{ |
|
823
|
|
|
if ($this->emails->contains($email)) { |
|
824
|
|
|
$this->emails->removeElement($email); |
|
825
|
|
|
} |
|
826
|
|
|
|
|
827
|
|
|
return $this; |
|
828
|
|
|
} |
|
829
|
|
|
|
|
830
|
|
|
/** |
|
831
|
|
|
* {@inheritdoc} |
|
832
|
|
|
*/ |
|
833
|
|
|
public function getId() |
|
834
|
|
|
{ |
|
835
|
|
|
return $this->id; |
|
836
|
|
|
} |
|
837
|
|
|
|
|
838
|
|
|
/** |
|
839
|
|
|
* @param int $id |
|
840
|
|
|
* |
|
841
|
|
|
* @return User |
|
842
|
|
|
*/ |
|
843
|
|
|
public function setId($id) |
|
844
|
|
|
{ |
|
845
|
|
|
$this->id = $id; |
|
846
|
|
|
|
|
847
|
|
|
return $this; |
|
848
|
|
|
} |
|
849
|
|
|
|
|
850
|
|
|
/** |
|
851
|
|
|
* @param BusinessUnit $businessUnit |
|
852
|
|
|
* |
|
853
|
|
|
* @return User |
|
854
|
|
|
*/ |
|
855
|
|
|
public function addBusinessUnit(BusinessUnit $businessUnit) |
|
856
|
|
|
{ |
|
857
|
|
|
if (!$this->getBusinessUnits()->contains($businessUnit)) { |
|
858
|
|
|
$this->getBusinessUnits()->add($businessUnit); |
|
859
|
|
|
} |
|
860
|
|
|
|
|
861
|
|
|
return $this; |
|
862
|
|
|
} |
|
863
|
|
|
|
|
864
|
|
|
/** |
|
865
|
|
|
* @return Collection |
|
866
|
|
|
*/ |
|
867
|
|
|
public function getBusinessUnits() |
|
868
|
|
|
{ |
|
869
|
|
|
$this->businessUnits = $this->businessUnits ?: new ArrayCollection(); |
|
870
|
|
|
|
|
871
|
|
|
return $this->businessUnits; |
|
|
|
|
|
|
872
|
|
|
} |
|
873
|
|
|
|
|
874
|
|
|
/** |
|
875
|
|
|
* @param Collection $businessUnits |
|
876
|
|
|
* |
|
877
|
|
|
* @return User |
|
878
|
|
|
*/ |
|
879
|
|
|
public function setBusinessUnits(Collection $businessUnits) |
|
880
|
|
|
{ |
|
881
|
|
|
$this->businessUnits = $businessUnits; |
|
882
|
|
|
|
|
883
|
|
|
return $this; |
|
884
|
|
|
} |
|
885
|
|
|
|
|
886
|
|
|
/** |
|
887
|
|
|
* @param BusinessUnit $businessUnit |
|
888
|
|
|
* |
|
889
|
|
|
* @return User |
|
890
|
|
|
*/ |
|
891
|
|
|
public function removeBusinessUnit(BusinessUnit $businessUnit) |
|
892
|
|
|
{ |
|
893
|
|
|
if ($this->getBusinessUnits()->contains($businessUnit)) { |
|
894
|
|
|
$this->getBusinessUnits()->removeElement($businessUnit); |
|
895
|
|
|
} |
|
896
|
|
|
|
|
897
|
|
|
return $this; |
|
898
|
|
|
} |
|
899
|
|
|
|
|
900
|
|
|
/** |
|
901
|
|
|
* @return BusinessUnit |
|
902
|
|
|
*/ |
|
903
|
|
|
public function getOwner() |
|
904
|
|
|
{ |
|
905
|
|
|
return $this->owner; |
|
906
|
|
|
} |
|
907
|
|
|
|
|
908
|
|
|
/** |
|
909
|
|
|
* @param BusinessUnit $owningBusinessUnit |
|
910
|
|
|
* |
|
911
|
|
|
* @return User |
|
912
|
|
|
*/ |
|
913
|
|
|
public function setOwner($owningBusinessUnit) |
|
914
|
|
|
{ |
|
915
|
|
|
$this->owner = $owningBusinessUnit; |
|
916
|
|
|
|
|
917
|
|
|
return $this; |
|
918
|
|
|
} |
|
919
|
|
|
|
|
920
|
|
|
/** |
|
921
|
|
|
* {@inheritdoc} |
|
922
|
|
|
*/ |
|
923
|
|
|
public function getNotificationEmails() |
|
924
|
|
|
{ |
|
925
|
|
|
return new ArrayCollection([$this->getEmail()]); |
|
926
|
|
|
} |
|
927
|
|
|
|
|
928
|
|
|
/** |
|
929
|
|
|
* {@inheritDoc} |
|
930
|
|
|
*/ |
|
931
|
|
|
public function getEmail() |
|
932
|
|
|
{ |
|
933
|
|
|
return $this->email; |
|
934
|
|
|
} |
|
935
|
|
|
|
|
936
|
|
|
/** |
|
937
|
|
|
* @param string $email New email value |
|
938
|
|
|
* |
|
939
|
|
|
* @return User |
|
940
|
|
|
*/ |
|
941
|
|
|
public function setEmail($email) |
|
942
|
|
|
{ |
|
943
|
|
|
$this->email = $email; |
|
944
|
|
|
|
|
945
|
|
|
return $this; |
|
946
|
|
|
} |
|
947
|
|
|
|
|
948
|
|
|
/** |
|
949
|
|
|
* Set IMAP configuration |
|
950
|
|
|
* |
|
951
|
|
|
* @param UserEmailOrigin $imapConfiguration |
|
952
|
|
|
* |
|
953
|
|
|
* @return User |
|
954
|
|
|
*/ |
|
955
|
|
|
public function setImapConfiguration($imapConfiguration = null) |
|
956
|
|
|
{ |
|
957
|
|
|
$currentImapConfiguration = $this->getImapConfiguration(); |
|
958
|
|
|
if ($currentImapConfiguration && |
|
959
|
|
|
(null === $imapConfiguration || $currentImapConfiguration->getId() !== $imapConfiguration->getId()) |
|
960
|
|
|
) { |
|
961
|
|
|
// deactivate current IMAP configuration and remove a reference to it |
|
962
|
|
|
$currentImapConfiguration->setActive(false); |
|
963
|
|
|
$this->removeEmailOrigin($currentImapConfiguration); |
|
964
|
|
|
} |
|
965
|
|
|
if (null !== $imapConfiguration && null !== $imapConfiguration->getUser()) { |
|
966
|
|
|
$this->addEmailOrigin($imapConfiguration); |
|
967
|
|
|
} |
|
968
|
|
|
|
|
969
|
|
|
return $this; |
|
970
|
|
|
} |
|
971
|
|
|
|
|
972
|
|
|
/** |
|
973
|
|
|
* Get IMAP configuration |
|
974
|
|
|
* |
|
975
|
|
|
* @return UserEmailOrigin |
|
976
|
|
|
*/ |
|
977
|
|
|
public function getImapConfiguration() |
|
978
|
|
|
{ |
|
979
|
|
|
$items = $this->emailOrigins->filter( |
|
980
|
|
|
function ($item) { |
|
981
|
|
|
return |
|
982
|
|
|
($item instanceof UserEmailOrigin) |
|
983
|
|
|
&& $item->isActive() |
|
984
|
|
|
&& !$item->getMailbox() |
|
985
|
|
|
&& (!$this->currentOrganization || $item->getOrganization() === $this->currentOrganization); |
|
986
|
|
|
} |
|
987
|
|
|
); |
|
988
|
|
|
|
|
989
|
|
|
return $items->isEmpty() |
|
990
|
|
|
? null |
|
991
|
|
|
: $items->first(); |
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
/** |
|
995
|
|
|
* @param AccountTypeModel|null $accountTypeModel |
|
996
|
|
|
*/ |
|
997
|
|
|
public function setImapAccountType(AccountTypeModel $accountTypeModel = null) |
|
998
|
|
|
{ |
|
999
|
|
|
$this->imapAccountType = $accountTypeModel; |
|
1000
|
|
|
if ($accountTypeModel instanceof AccountTypeModel) { |
|
1001
|
|
|
$this->setImapConfiguration($accountTypeModel->getUserEmailOrigin()); |
|
1002
|
|
|
} |
|
1003
|
|
|
} |
|
1004
|
|
|
|
|
1005
|
|
|
/** |
|
1006
|
|
|
* @return AccountTypeModel |
|
1007
|
|
|
*/ |
|
1008
|
|
View Code Duplication |
public function getImapAccountType() |
|
1009
|
|
|
{ |
|
1010
|
|
|
if ($this->imapAccountType === null) { |
|
1011
|
|
|
/** @var UserEmailOrigin $userEmailOrigin */ |
|
1012
|
|
|
$userEmailOrigin = $this->getImapConfiguration(); |
|
1013
|
|
|
$accountTypeModel = null; |
|
1014
|
|
|
if ($userEmailOrigin) { |
|
1015
|
|
|
$accountTypeModel = new AccountTypeModel(); |
|
1016
|
|
|
if ($userEmailOrigin->getAccessToken() && $userEmailOrigin->getAccessToken() !== '') { |
|
1017
|
|
|
$accountTypeModel->setAccountType(AccountTypeModel::ACCOUNT_TYPE_GMAIL); |
|
1018
|
|
|
$accountTypeModel->setUserEmailOrigin($userEmailOrigin); |
|
1019
|
|
|
} else { |
|
1020
|
|
|
$accountTypeModel->setAccountType(AccountTypeModel::ACCOUNT_TYPE_OTHER); |
|
1021
|
|
|
$accountTypeModel->setUserEmailOrigin($userEmailOrigin); |
|
1022
|
|
|
} |
|
1023
|
|
|
} |
|
1024
|
|
|
|
|
1025
|
|
|
if ($accountTypeModel) { |
|
1026
|
|
|
return $accountTypeModel; |
|
1027
|
|
|
} |
|
1028
|
|
|
} |
|
1029
|
|
|
|
|
1030
|
|
|
return $this->imapAccountType; |
|
1031
|
|
|
} |
|
1032
|
|
|
|
|
1033
|
|
|
/** |
|
1034
|
|
|
* Delete email origin |
|
1035
|
|
|
* |
|
1036
|
|
|
* @param EmailOrigin $emailOrigin |
|
1037
|
|
|
* |
|
1038
|
|
|
* @return User |
|
1039
|
|
|
*/ |
|
1040
|
|
|
public function removeEmailOrigin(EmailOrigin $emailOrigin) |
|
1041
|
|
|
{ |
|
1042
|
|
|
$this->emailOrigins->removeElement($emailOrigin); |
|
1043
|
|
|
|
|
1044
|
|
|
return $this; |
|
1045
|
|
|
} |
|
1046
|
|
|
|
|
1047
|
|
|
/** |
|
1048
|
|
|
* Add email origin |
|
1049
|
|
|
* |
|
1050
|
|
|
* @param EmailOrigin $emailOrigin |
|
1051
|
|
|
* |
|
1052
|
|
|
* @return User |
|
1053
|
|
|
*/ |
|
1054
|
|
|
public function addEmailOrigin(EmailOrigin $emailOrigin) |
|
1055
|
|
|
{ |
|
1056
|
|
|
$this->emailOrigins->add($emailOrigin); |
|
1057
|
|
|
|
|
1058
|
|
|
$emailOrigin->setOwner($this); |
|
1059
|
|
|
|
|
1060
|
|
|
return $this; |
|
1061
|
|
|
} |
|
1062
|
|
|
|
|
1063
|
|
|
/** |
|
1064
|
|
|
* Get email origins assigned to user |
|
1065
|
|
|
* |
|
1066
|
|
|
* @return EmailOrigin[]|ArrayCollection |
|
1067
|
|
|
*/ |
|
1068
|
|
|
public function getEmailOrigins() |
|
1069
|
|
|
{ |
|
1070
|
|
|
return $this->emailOrigins; |
|
1071
|
|
|
} |
|
1072
|
|
|
|
|
1073
|
|
|
/** |
|
1074
|
|
|
* Gets the groups granted to the user |
|
1075
|
|
|
* |
|
1076
|
|
|
* @return Collection |
|
1077
|
|
|
*/ |
|
1078
|
|
|
public function getGroups() |
|
1079
|
|
|
{ |
|
1080
|
|
|
return $this->groups; |
|
|
|
|
|
|
1081
|
|
|
} |
|
1082
|
|
|
|
|
1083
|
|
|
/** |
|
1084
|
|
|
* @param string $name |
|
1085
|
|
|
* |
|
1086
|
|
|
* @return bool |
|
1087
|
|
|
*/ |
|
1088
|
|
|
public function hasGroup($name) |
|
1089
|
|
|
{ |
|
1090
|
|
|
return (bool)$this |
|
1091
|
|
|
->getGroups() |
|
1092
|
|
|
->filter( |
|
1093
|
|
|
function (Group $group) use ($name) { |
|
1094
|
|
|
return $group->getName() === $name; |
|
1095
|
|
|
} |
|
1096
|
|
|
) |
|
1097
|
|
|
->count(); |
|
1098
|
|
|
} |
|
1099
|
|
|
|
|
1100
|
|
|
/** |
|
1101
|
|
|
* @return array |
|
1102
|
|
|
*/ |
|
1103
|
|
|
public function getGroupNames() |
|
1104
|
|
|
{ |
|
1105
|
|
|
return $this |
|
1106
|
|
|
->getGroups() |
|
1107
|
|
|
->map( |
|
1108
|
|
|
function (Group $group) { |
|
1109
|
|
|
return $group->getName(); |
|
1110
|
|
|
} |
|
1111
|
|
|
) |
|
1112
|
|
|
->toArray(); |
|
1113
|
|
|
} |
|
1114
|
|
|
|
|
1115
|
|
|
/** |
|
1116
|
|
|
* @param Group $group |
|
1117
|
|
|
* |
|
1118
|
|
|
* @return User |
|
1119
|
|
|
*/ |
|
1120
|
|
|
public function addGroup(Group $group) |
|
1121
|
|
|
{ |
|
1122
|
|
|
if (!$this->getGroups()->contains($group)) { |
|
1123
|
|
|
$this->getGroups()->add($group); |
|
1124
|
|
|
} |
|
1125
|
|
|
|
|
1126
|
|
|
return $this; |
|
1127
|
|
|
} |
|
1128
|
|
|
|
|
1129
|
|
|
/** |
|
1130
|
|
|
* @param Group $group |
|
1131
|
|
|
* |
|
1132
|
|
|
* @return User |
|
1133
|
|
|
*/ |
|
1134
|
|
|
public function removeGroup(Group $group) |
|
1135
|
|
|
{ |
|
1136
|
|
|
if ($this->getGroups()->contains($group)) { |
|
1137
|
|
|
$this->getGroups()->removeElement($group); |
|
1138
|
|
|
} |
|
1139
|
|
|
|
|
1140
|
|
|
return $this; |
|
1141
|
|
|
} |
|
1142
|
|
|
|
|
1143
|
|
|
/** |
|
1144
|
|
|
* {@inheritdoc} |
|
1145
|
|
|
*/ |
|
1146
|
|
|
public function getRoles() |
|
1147
|
|
|
{ |
|
1148
|
|
|
$roles = parent::getRoles(); |
|
1149
|
|
|
|
|
1150
|
|
|
/** @var Group $group */ |
|
1151
|
|
|
foreach ($this->getGroups() as $group) { |
|
1152
|
|
|
$roles = array_merge($roles, $group->getRoles()->toArray()); |
|
1153
|
|
|
} |
|
1154
|
|
|
|
|
1155
|
|
|
return array_unique($roles); |
|
1156
|
|
|
} |
|
1157
|
|
|
|
|
1158
|
|
|
/** |
|
1159
|
|
|
* @param OrganizationInterface $organization |
|
1160
|
|
|
* |
|
1161
|
|
|
* @return $this |
|
1162
|
|
|
*/ |
|
1163
|
|
|
public function setCurrentOrganization(OrganizationInterface $organization) |
|
1164
|
|
|
{ |
|
1165
|
|
|
$this->currentOrganization = $organization; |
|
1166
|
|
|
|
|
1167
|
|
|
return $this; |
|
1168
|
|
|
} |
|
1169
|
|
|
|
|
1170
|
|
|
/** |
|
1171
|
|
|
* @return OrganizationInterface |
|
1172
|
|
|
*/ |
|
1173
|
|
|
public function getCurrentOrganization() |
|
1174
|
|
|
{ |
|
1175
|
|
|
return $this->currentOrganization; |
|
1176
|
|
|
} |
|
1177
|
|
|
|
|
1178
|
|
|
/** |
|
1179
|
|
|
* Get user full name |
|
1180
|
|
|
* |
|
1181
|
|
|
* @return string |
|
1182
|
|
|
*/ |
|
1183
|
|
|
public function getFullName() |
|
1184
|
|
|
{ |
|
1185
|
|
|
return sprintf('%s %s', $this->getFirstName(), $this->getLastName()); |
|
1186
|
|
|
} |
|
1187
|
|
|
} |
|
1188
|
|
|
|