Completed
Push — master ( 7564b6...a34f18 )
by Julito
23:49 queued 09:48
created

User   F

Complexity

Total Complexity 141

Size/Duplication

Total Lines 1894
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 291
c 3
b 0
f 0
dl 0
loc 1894
rs 2
wmc 141

126 Methods

Rating   Name   Duplication   Size   Complexity  
A setExpiresAt() 0 5 1
A getCredentialsExpireAt() 0 3 1
A getExpiresAt() 0 3 1
A getUsername() 0 3 1
A setHrDeptId() 0 5 1
A isCredentialsNonExpired() 0 11 1
A setEmail() 0 5 1
A setExpirationDate() 0 5 1
A setOpenid() 0 5 1
A setTeach() 0 5 1
A setProductions() 0 5 1
A getTeach() 0 3 1
A isEqualTo() 0 15 4
A setCreatorId() 0 5 1
A setUserId() 0 4 2
A setSessionAsGeneralCoach() 0 5 1
A getAddress() 0 3 1
A setId() 0 3 1
A getAuthSource() 0 3 1
A getSessionAsGeneralCoach() 0 3 1
A getMemberSince() 0 3 1
A getFullname() 0 3 1
A isAccountNonExpired() 0 11 1
A getProductions() 0 3 1
A getSlug() 0 3 1
A getActive() 0 3 1
A setCredentialsExpired() 0 5 1
A setAddress() 0 5 1
A setDropBoxSentFiles() 0 3 1
A setCourses() 0 3 1
A getPhone() 0 3 1
A setCurrentUrl() 0 12 3
A getExpirationDate() 0 3 1
A setDropBoxReceivedFiles() 0 3 1
A getHrDeptId() 0 3 1
A setSalt() 0 5 1
A getStatus() 0 3 1
A getUserId() 0 3 1
A setTheme() 0 5 1
A getCourseGroupsAsTutorFromCourse() 0 8 1
A postPersist() 0 4 1
A loadValidatorMetadata() 0 2 1
A getCompleteNameWithClasses() 0 12 3
A setRoles() 0 9 2
A getDiplomas() 0 3 1
A getOpenid() 0 3 1
A getPassword() 0 3 1
A getCourseGroupsAsMember() 0 3 1
A getIdentifier() 0 3 1
A setCurriculumItems() 0 5 1
A isEnabled() 0 3 1
A setLocked() 0 5 1
A getResourceNode() 0 3 1
A setOpenarea() 0 5 1
A setResourceNode() 0 5 1
A getClasses() 0 3 1
A isActive() 0 3 1
A isProfileCompleted() 0 3 1
A __construct() 0 28 1
A setClasses() 0 5 1
A getAchievedSkills() 0 3 1
A getConfirmationToken() 0 3 1
A getResourceNodes() 0 3 1
A setCredentialsExpireAt() 0 5 1
A getRoles() 0 12 2
A getLps() 0 2 1
A getLocked() 0 3 1
A getReceivedMessages() 0 3 1
A setAuthSource() 0 5 1
A getId() 0 3 1
A getCompetences() 0 3 1
A getSalt() 0 3 1
A __toString() 0 3 1
A isAccountNonLocked() 0 3 1
A getOpenarea() 0 3 1
A setCompetences() 0 5 1
A isOnline() 0 3 1
A setSessionCourseSubscriptions() 0 5 1
A getCreatorId() 0 3 1
A getDropBoxReceivedFiles() 0 3 1
A getCourseGroupsAsTutor() 0 3 1
A setGroups() 0 7 2
A setConfirmationToken() 0 5 1
A setOfficialCode() 0 5 1
A getCourses() 0 3 1
A setStatus() 0 5 1
A getSessionCourseSubscriptions() 0 3 1
A setPhone() 0 5 1
A setPortal() 0 3 1
A getCourseGroupsAsMemberFromCourse() 0 8 1
A setCommentedUserSkills() 0 5 1
A getLanguage() 0 3 1
A setLastLogin() 0 5 1
A getExpired() 0 3 1
A setPortals() 0 3 1
A getRegistrationDate() 0 3 1
A setRegistrationDate() 0 5 1
A getCredentialsExpired() 0 3 1
A setLastname() 0 5 1
A getCommentedUserSkills() 0 3 1
A hasSkill() 0 10 3
A getCurrentUrl() 0 3 1
A setProfileCompleted() 0 5 1
A setEnabled() 0 5 1
A getPictureLegacy() 0 9 2
A setFirstname() 0 5 1
A getTheme() 0 3 1
A getPortals() 0 3 1
A getSentMessages() 0 3 1
A getEmail() 0 3 1
A getIsActive() 0 3 1
A getUnreadReceivedMessages() 0 16 2
A setExpired() 0 5 1
A getLastLogin() 0 3 1
A setActive() 0 5 1
A getDropBoxSentFiles() 0 3 1
A getPasswordRequestedAt() 0 3 1
A setPassword() 0 5 1
A setDiplomas() 0 5 1
A getCurriculumItems() 0 3 1
A getOfficialCode() 0 3 1
A setLanguage() 0 5 1
A setSlug() 0 3 1
A setAchievedSkills() 0 5 1
A getPasswordConstraints() 0 21 1
A setResourceNodes() 0 5 1

How to fix   Complexity   

Complex Class

Complex classes like User often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use User, and based on these observations, apply Extract Interface, too.

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\UserBundle\Entity;
5
6
use Chamilo\CoreBundle\Entity\AccessUrl;
7
use Chamilo\CoreBundle\Entity\AccessUrlRelUser;
8
use Chamilo\CoreBundle\Entity\Course;
9
use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
10
use Chamilo\CoreBundle\Entity\Skill;
11
use Chamilo\CoreBundle\Entity\UsergroupRelUser;
12
use Chamilo\ThemeBundle\Model\UserInterface as ThemeUser;
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Doctrine\Common\Collections\Criteria;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Mapping as ORM;
18
use Sonata\UserBundle\Entity\BaseUser;
19
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
20
use Symfony\Component\Security\Core\User\EquatableInterface;
21
use Symfony\Component\Security\Core\User\UserInterface;
22
use Symfony\Component\Validator\Constraints as Assert;
23
use Symfony\Component\Validator\Mapping\ClassMetadata;
24
25
/**
26
 * @ORM\HasLifecycleCallbacks
27
 * @ORM\Table(
28
 *  name="user",
29
 *  indexes={
30
 *      @ORM\Index(name="idx_user_uid", columns={"user_id"}),
31
 *      @ORM\Index(name="status", columns={"status"})
32
 *  }
33
 * )
34
 * @UniqueEntity("username")
35
 *
36
 * @ORM\Entity()
37
 *
38
 * @ORM\AttributeOverrides({
39
 *     @ORM\AttributeOverride(name="username",
40
 *         column=@ORM\Column(
41
 *             name="username",
42
 *             type="string",
43
 *             length=100,
44
 *             unique=true
45
 *         )
46
 *     ),
47
 *      @ORM\AttributeOverride(name="email",
48
 *         column=@ORM\Column(
49
 *             name="email",
50
 *             type="string",
51
 *             length=100,
52
 *             unique=false
53
 *         )
54
 *     ),
55
 *     @ORM\AttributeOverride(name="emailCanonical",
56
 *         column=@ORM\Column(
57
 *             name="email_canonical",
58
 *             type="string",
59
 *             length=100,
60
 *             unique=false
61
 *         )
62
 *     ),
63
 *     @ORM\AttributeOverride(name="usernameCanonical",
64
 *         column=@ORM\Column(
65
 *             name="username_canonical",
66
 *             type="string",
67
 *             length=180,
68
 *             unique=false
69
 *         )
70
 *     )
71
 * })
72
 */
73
class User extends BaseUser implements ThemeUser, EquatableInterface //implements ParticipantInterface, ThemeUser
74
{
75
    public const COURSE_MANAGER = 1;
76
    public const TEACHER = 1;
77
    public const SESSION_ADMIN = 3;
78
    public const DRH = 4;
79
    public const STUDENT = 5;
80
    public const ANONYMOUS = 6;
81
82
    /**
83
     * @var int
84
     *
85
     * @ORM\Column(name="id", type="integer")
86
     * @ORM\Id
87
     * @ORM\GeneratedValue(strategy="AUTO")
88
     */
89
    protected $id;
90
91
    /**
92
     * @var int
93
     *
94
     * @ORM\Column(name="user_id", type="integer", nullable=true)
95
     */
96
    protected $userId;
97
98
    /**
99
     * @var string
100
     *
101
     * @ORM\Column(name="username", type="string", length=100, nullable=false, unique=true)
102
     */
103
    //protected $username;
104
105
    /**
106
     * @var string
107
     *
108
     * @ORM\Column(name="username_canonical", type="string", length=100, nullable=false)
109
     */
110
    //protected $usernameCanonical;
111
112
    /**
113
     * @var string
114
     * @ORM\Column(name="email_canonical", type="string", length=100, nullable=false, unique=false)
115
     */
116
    //protected $emailCanonical;
117
118
    /**
119
     * @var string
120
     *
121
     * @ORM\Column(name="email", type="string", length=100, nullable=false, unique=false)
122
     */
123
    //protected $email;
124
125
    /**
126
     * @var bool
127
     *
128
     * @ORM\Column(name="locked", type="boolean")
129
     */
130
    protected $locked;
131
132
    /**
133
     * @var bool
134
     *
135
     * @ORM\Column(name="enabled", type="boolean")
136
     */
137
    //protected $enabled;
138
139
    /**
140
     * @var bool
141
     *
142
     * @ORM\Column(name="expired", type="boolean")
143
     */
144
    protected $expired;
145
146
    /**
147
     * @var bool
148
     *
149
     * @ORM\Column(name="credentials_expired", type="boolean")
150
     */
151
    protected $credentialsExpired;
152
153
    /**
154
     * @var \DateTime
155
     *
156
     * @ORM\Column(name="credentials_expire_at", type="datetime", nullable=true, unique=false)
157
     */
158
    protected $credentialsExpireAt;
159
160
    /**
161
     * @var \DateTime
162
     *
163
     * @ORM\Column(name="expires_at", type="datetime", nullable=true, unique=false)
164
     */
165
    protected $expiresAt;
166
167
    /**
168
     * @var string
169
     *
170
     * @ORM\Column(name="phone", type="string", length=30, nullable=true, unique=false)
171
     */
172
    //protected $phone;
173
174
    /**
175
     * @var string
176
     *
177
     * @ORM\Column(name="address", type="string", length=250, nullable=true, unique=false)
178
     */
179
    protected $address;
180
181
    /**
182
     * @var AccessUrl
183
     */
184
    protected $currentUrl;
185
186
    /**
187
     * @ORM\Column(type="string", length=255)
188
     */
189
    //protected $salt;
190
191
    /**
192
     * @var \DateTime
193
     *
194
     * @ORM\Column(name="last_login", type="datetime", nullable=true, unique=false)
195
     */
196
    //protected $lastLogin;
197
198
    /**
199
     * Random string sent to the user email address in order to verify it.
200
     *
201
     * @var string
202
     * @ORM\Column(name="confirmation_token", type="string", length=255, nullable=true)
203
     */
204
    //protected $confirmationToken;
205
206
    /**
207
     * @var \DateTime
208
     *
209
     * @ORM\Column(name="password_requested_at", type="datetime", nullable=true, unique=false)
210
     */
211
    //protected $passwordRequestedAt;
212
213
    /**
214
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true)
215
     */
216
    protected $courses;
217
218
    /**
219
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="user")
220
     */
221
    //protected $items;
222
223
    /**
224
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\UsergroupRelUser", mappedBy="user")
225
     */
226
    protected $classes;
227
228
    /**
229
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxPost", mappedBy="user").
230
     */
231
    protected $dropBoxReceivedFiles;
232
233
    /**
234
     * ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CDropboxFile", mappedBy="userSent").
235
     */
236
    protected $dropBoxSentFiles;
237
238
    /**
239
     * @ORM\Column(type="array")
240
     */
241
    //protected $roles;
242
243
    /**
244
     * @var bool
245
     *
246
     * @ORM\Column(name="profile_completed", type="boolean", nullable=true)
247
     */
248
    protected $profileCompleted;
249
250
    /**
251
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\JuryMembers", mappedBy="user")
252
     */
253
    //protected $jurySubscriptions;
254
255
    /**
256
     * @ORM\ManyToMany(targetEntity="Chamilo\UserBundle\Entity\Group", inversedBy="users")
257
     * @ORM\JoinTable(
258
     *      name="fos_user_user_group",
259
     *      joinColumns={
260
     *          @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade")
261
     *      },
262
     *      inverseJoinColumns={
263
     *          @ORM\JoinColumn(name="group_id", referencedColumnName="id")
264
     *      }
265
     * )
266
     */
267
    protected $groups;
268
269
    /**
270
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CurriculumItemRelUser", mappedBy="user").
271
     */
272
    protected $curriculumItems;
273
274
    /**
275
     * @ORM\OneToMany(
276
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelUser",
277
     *     mappedBy="user",
278
     *     cascade={"persist", "remove"},
279
     *     orphanRemoval=true
280
     * )
281
     */
282
    protected $portals;
283
284
    /**
285
     * @var ArrayCollection
286
     *
287
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Session", mappedBy="generalCoach")
288
     */
289
    protected $sessionAsGeneralCoach;
290
291
    /**
292
     * @ORM\OneToOne(
293
     *     targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", cascade={"remove"}, orphanRemoval=true
294
     * )
295
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="CASCADE")
296
     */
297
    public $resourceNode;
298
299
    /**
300
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceNode", mappedBy="creator")
301
     */
302
    protected $resourceNodes;
303
304
    /**
305
     * @ORM\OneToMany(
306
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelCourseRelUser",
307
     *     mappedBy="user",
308
     *     cascade={"persist"},
309
     *     orphanRemoval=true
310
     * )
311
     */
312
    protected $sessionCourseSubscriptions;
313
314
    /**
315
     * @ORM\OneToMany(
316
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser",
317
     *     mappedBy="user",
318
     *     cascade={"persist", "remove"},
319
     *     orphanRemoval=true
320
     * )
321
     */
322
    protected $achievedSkills;
323
324
    /**
325
     * @ORM\OneToMany(
326
     *     targetEntity="Chamilo\CoreBundle\Entity\SkillRelUserComment",
327
     *     mappedBy="feedbackGiver",
328
     *     cascade={"persist", "remove"},
329
     *     orphanRemoval=true
330
     * )
331
     */
332
    protected $commentedUserSkills;
333
334
    /**
335
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="user")
336
     */
337
    protected $gradeBookCategories;
338
339
    /**
340
     * @ORM\OneToMany(
341
     *     targetEntity="Chamilo\CoreBundle\Entity\SessionRelUser",
342
     *     mappedBy="user",
343
     *     cascade={"persist", "remove"},
344
     *     orphanRemoval=true
345
     * )
346
     */
347
    protected $sessions;
348
349
    /**
350
     * @var Collection
351
     *
352
     * @ORM\OneToMany(
353
     *     targetEntity="Chamilo\CourseBundle\Entity\CGroupRelUser",
354
     *     mappedBy="user",
355
     *     cascade={"persist", "remove"},
356
     *     orphanRemoval=true
357
     * )
358
     */
359
    protected $courseGroupsAsMember;
360
361
    /**
362
     * @var Collection
363
     *
364
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupRelTutor", mappedBy="user", orphanRemoval=true)
365
     */
366
    protected $courseGroupsAsTutor;
367
368
    /**
369
     * @var string
370
     *
371
     * @ORM\Column(name="auth_source", type="string", length=50, nullable=true, unique=false)
372
     */
373
    protected $authSource;
374
375
    /**
376
     * @var int
377
     *
378
     * @ORM\Column(name="status", type="integer", nullable=false)
379
     */
380
    protected $status;
381
382
    /**
383
     * @var string
384
     *
385
     * @ORM\Column(name="official_code", type="string", length=40, nullable=true, unique=false)
386
     */
387
    protected $officialCode;
388
389
    /**
390
     * @var string
391
     *
392
     * @ORM\Column(name="picture_uri", type="string", length=250, nullable=true, unique=false)
393
     */
394
    protected $pictureUri;
395
396
    /**
397
     * @var int
398
     *
399
     * @ORM\Column(name="creator_id", type="integer", nullable=true, unique=false)
400
     */
401
    protected $creatorId;
402
403
    /**
404
     * @var string
405
     *
406
     * @ORM\Column(name="competences", type="text", nullable=true, unique=false)
407
     */
408
    protected $competences;
409
410
    /**
411
     * @var string
412
     *
413
     * @ORM\Column(name="diplomas", type="text", nullable=true, unique=false)
414
     */
415
    protected $diplomas;
416
417
    /**
418
     * @var string
419
     *
420
     * @ORM\Column(name="openarea", type="text", nullable=true, unique=false)
421
     */
422
    protected $openarea;
423
424
    /**
425
     * @var string
426
     *
427
     * @ORM\Column(name="teach", type="text", nullable=true, unique=false)
428
     */
429
    protected $teach;
430
431
    /**
432
     * @var string
433
     *
434
     * @ORM\Column(name="productions", type="string", length=250, nullable=true, unique=false)
435
     */
436
    protected $productions;
437
438
    /**
439
     * @var string
440
     *
441
     * @ORM\Column(name="language", type="string", length=40, nullable=true, unique=false)
442
     */
443
    protected $language;
444
445
    /**
446
     * @var \DateTime
447
     *
448
     * @ORM\Column(name="registration_date", type="datetime", nullable=false, unique=false)
449
     */
450
    protected $registrationDate;
451
452
    /**
453
     * @var \DateTime
454
     *
455
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
456
     */
457
    protected $expirationDate;
458
459
    /**
460
     * @var bool
461
     *
462
     * @ORM\Column(name="active", type="boolean", nullable=false, unique=false)
463
     */
464
    protected $active;
465
466
    /**
467
     * @var string
468
     *
469
     * @ORM\Column(name="openid", type="string", length=255, nullable=true, unique=false)
470
     */
471
    protected $openid;
472
473
    /**
474
     * @var string
475
     *
476
     * @ORM\Column(name="theme", type="string", length=255, nullable=true, unique=false)
477
     */
478
    protected $theme;
479
480
    /**
481
     * @var int
482
     *
483
     * @ORM\Column(name="hr_dept_id", type="smallint", nullable=true, unique=false)
484
     */
485
    protected $hrDeptId;
486
487
    /**
488
     * @var ArrayCollection
489
     *
490
     * @ORM\OneToMany(
491
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
492
     *     mappedBy="userSender",
493
     *     cascade={"persist", "remove"},
494
     *     orphanRemoval=true
495
     * )
496
     */
497
    protected $sentMessages;
498
499
    /**
500
     * @var ArrayCollection
501
     *
502
     * @ORM\OneToMany(
503
     *     targetEntity="Chamilo\CoreBundle\Entity\Message",
504
     *     mappedBy="userReceiver",
505
     *     cascade={"persist", "remove"},
506
     *     orphanRemoval=true
507
     * )
508
     */
509
    protected $receivedMessages;
510
511
    /**
512
     * Constructor.
513
     */
514
    public function __construct()
515
    {
516
        parent::__construct();
517
        $this->status = self::STUDENT;
518
        $this->salt = sha1(uniqid(null, true));
0 ignored issues
show
Bug Best Practice introduced by
The property salt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
519
        $this->active = true;
520
        $this->registrationDate = new \DateTime();
521
        $this->authSource = 'platform';
522
        $this->courses = new ArrayCollection();
523
        //$this->items = new ArrayCollection();
524
        $this->classes = new ArrayCollection();
525
        $this->curriculumItems = new ArrayCollection();
526
        $this->portals = new ArrayCollection();
527
        $this->dropBoxSentFiles = new ArrayCollection();
528
        $this->dropBoxReceivedFiles = new ArrayCollection();
529
        //$this->extraFields = new ArrayCollection();
530
        //$this->userId = 0;
531
        //$this->createdAt = new \DateTime();
532
        //$this->updatedAt = new \DateTime();
533
534
        $this->enabled = false;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
535
        $this->locked = false;
536
        $this->expired = false;
537
        $this->roles = [];
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
538
        $this->credentialsExpired = false;
539
540
        $this->courseGroupsAsMember = new ArrayCollection();
541
        $this->courseGroupsAsTutor = new ArrayCollection();
542
    }
543
544
    /**
545
     * @return string
546
     */
547
    public function __toString()
548
    {
549
        return $this->username;
550
    }
551
552
    /**
553
     * @return $this
554
     */
555
    public function setResourceNode(ResourceNode $resourceNode): self
556
    {
557
        $this->resourceNode = $resourceNode;
558
559
        return $this;
560
    }
561
562
    public function getResourceNode(): ResourceNode
563
    {
564
        return $this->resourceNode;
565
    }
566
567
    /**
568
     * @return mixed
569
     */
570
    public function getResourceNodes()
571
    {
572
        return $this->resourceNodes;
573
    }
574
575
    /**
576
     * @param mixed $resourceNodes
577
     *
578
     * @return User
579
     */
580
    public function setResourceNodes($resourceNodes)
581
    {
582
        $this->resourceNodes = $resourceNodes;
583
584
        return $this;
585
    }
586
587
    /**
588
     * Updates the id with the user_id.
589
     *
590
     * @ORM\PostPersist()
591
     */
592
    public function postPersist(LifecycleEventArgs $args)
593
    {
594
        $user = $args->getEntity();
595
        $this->setUserId($user->getId());
596
    }
597
598
    /**
599
     * @param int $userId
600
     */
601
    public function setId($userId)
602
    {
603
        $this->id = $userId;
604
    }
605
606
    /**
607
     * @param int $userId
608
     */
609
    public function setUserId($userId)
610
    {
611
        if (!empty($userId)) {
612
            $this->userId = $userId;
613
        }
614
    }
615
616
    /**
617
     * @return int
618
     */
619
    public function getId()
620
    {
621
        return $this->id;
622
    }
623
624
    /**
625
     * @return ArrayCollection
626
     */
627
    public function getDropBoxSentFiles()
628
    {
629
        return $this->dropBoxSentFiles;
630
    }
631
632
    /**
633
     * @return ArrayCollection
634
     */
635
    public function getDropBoxReceivedFiles()
636
    {
637
        return $this->dropBoxReceivedFiles;
638
    }
639
640
    /**
641
     * @param ArrayCollection $value
642
     */
643
    public function setDropBoxSentFiles($value)
644
    {
645
        $this->dropBoxSentFiles = $value;
646
    }
647
648
    /**
649
     * @param ArrayCollection $value
650
     */
651
    public function setDropBoxReceivedFiles($value)
652
    {
653
        $this->dropBoxReceivedFiles = $value;
654
    }
655
656
    /**
657
     * @param ArrayCollection $courses
658
     */
659
    public function setCourses($courses)
660
    {
661
        $this->courses = $courses;
662
    }
663
664
    /**
665
     * @return ArrayCollection
666
     */
667
    public function getCourses()
668
    {
669
        return $this->courses;
670
    }
671
672
    /**
673
     * @return array
674
     */
675
    public static function getPasswordConstraints()
676
    {
677
        return
678
            [
679
                new Assert\Length(['min' => 5]),
680
                // Alpha numeric + "_" or "-"
681
                new Assert\Regex(
682
                    [
683
                        'pattern' => '/^[a-z\-_0-9]+$/i',
684
                        'htmlPattern' => '/^[a-z\-_0-9]+$/i', ]
685
                ),
686
                // Min 3 letters - not needed
687
                /*new Assert\Regex(array(
688
                    'pattern' => '/[a-z]{3}/i',
689
                    'htmlPattern' => '/[a-z]{3}/i')
690
                ),*/
691
                // Min 2 numbers
692
                new Assert\Regex(
693
                    [
694
                        'pattern' => '/[0-9]{2}/',
695
                        'htmlPattern' => '/[0-9]{2}/', ]
696
                ),
697
            ]
698
            ;
699
    }
700
701
    public static function loadValidatorMetadata(ClassMetadata $metadata)
702
    {
703
        //$metadata->addPropertyConstraint('firstname', new Assert\NotBlank());
704
        //$metadata->addPropertyConstraint('lastname', new Assert\NotBlank());
705
        //$metadata->addPropertyConstraint('email', new Assert\Email());
706
        /*
707
        $metadata->addPropertyConstraint('password',
708
            new Assert\Collection(self::getPasswordConstraints())
709
        );*/
710
711
        /*$metadata->addConstraint(new UniqueEntity(array(
712
            'fields'  => 'username',
713
            'message' => 'This value is already used.',
714
        )));*/
715
716
        /*$metadata->addPropertyConstraint(
717
            'username',
718
            new Assert\Length(array(
719
                'min'        => 2,
720
                'max'        => 50,
721
                'minMessage' => 'This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.',
722
                'maxMessage' => 'This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.',
723
            ))
724
        );*/
725
    }
726
727
    /**
728
     * @return ArrayCollection
729
     */
730
    public function getPortals()
731
    {
732
        return $this->portals;
733
    }
734
735
    /**
736
     * @param $portal
737
     */
738
    public function setPortal($portal)
739
    {
740
        $this->portals->add($portal);
741
    }
742
743
    /**
744
     * @param $value
745
     */
746
    public function setPortals($value)
747
    {
748
        $this->portals = $value;
749
    }
750
751
    /**
752
     * @return ArrayCollection
753
     */
754
    public function getCurriculumItems()
755
    {
756
        return $this->curriculumItems;
757
    }
758
759
    /**
760
     * @param $items
761
     *
762
     * @return $this
763
     */
764
    public function setCurriculumItems($items)
765
    {
766
        $this->curriculumItems = $items;
767
768
        return $this;
769
    }
770
771
    /**
772
     * @return bool
773
     */
774
    public function getIsActive()
775
    {
776
        return $this->active == 1;
777
    }
778
779
    /**
780
     * @return bool
781
     */
782
    public function isActive()
783
    {
784
        return $this->getIsActive();
785
    }
786
787
    /**
788
     * {@inheritdoc}
789
     */
790
    public function isEnabled()
791
    {
792
        return $this->getActive() == 1;
793
    }
794
795
    /**
796
     * @return ArrayCollection
797
     */
798
    /*public function getRolesObj()
799
    {
800
        return $this->roles;
801
    }*/
802
803
    /**
804
     * Set salt.
805
     *
806
     * @param string $salt
807
     *
808
     * @return User
809
     */
810
    public function setSalt($salt)
811
    {
812
        $this->salt = $salt;
0 ignored issues
show
Bug Best Practice introduced by
The property salt does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
813
814
        return $this;
815
    }
816
817
    /**
818
     * Get salt.
819
     *
820
     * @return string
821
     */
822
    public function getSalt()
823
    {
824
        return $this->salt;
825
    }
826
827
    /**
828
     * @param ArrayCollection $classes
829
     *
830
     * @return $this
831
     */
832
    public function setClasses($classes)
833
    {
834
        $this->classes = $classes;
835
836
        return $this;
837
    }
838
839
    /**
840
     * @return ArrayCollection
841
     */
842
    public function getClasses()
843
    {
844
        return $this->classes;
845
    }
846
847
    public function getLps()
848
    {
849
        //return $this->lps;
850
        /*$criteria = Criteria::create()
851
            ->where(Criteria::expr()->eq("id", "666"))
852
            //->orderBy(array("username" => "ASC"))
853
            //->setFirstResult(0)
854
            //->setMaxResults(20)
855
        ;
856
        $lps = $this->lps->matching($criteria);*/
857
        /*return $this->lps->filter(
858
            function($entry) use ($idsToFilter) {
859
                return $entry->getId() == 1;
860
        });*/
861
    }
862
863
    /**
864
     * Returns the list of classes for the user.
865
     *
866
     * @return string
867
     */
868
    public function getCompleteNameWithClasses()
869
    {
870
        $classSubscription = $this->getClasses();
871
        $classList = [];
872
        /** @var UsergroupRelUser $subscription */
873
        foreach ($classSubscription as $subscription) {
874
            $class = $subscription->getUsergroup();
875
            $classList[] = $class->getName();
876
        }
877
        $classString = !empty($classList) ? ' ['.implode(', ', $classList).']' : null;
878
879
        return \UserManager::formatUserFullName($this).$classString;
880
    }
881
882
    /**
883
     * Get userId.
884
     *
885
     * @return int
886
     */
887
    public function getUserId()
888
    {
889
        return $this->userId;
890
    }
891
892
    /**
893
     * Set lastname.
894
     *
895
     * @param string $lastname
896
     *
897
     * @return User
898
     */
899
    public function setLastname($lastname)
900
    {
901
        $this->lastname = $lastname;
0 ignored issues
show
Bug Best Practice introduced by
The property lastname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
902
903
        return $this;
904
    }
905
906
    /**
907
     * Set firstname.
908
     *
909
     * @param string $firstname
910
     *
911
     * @return User
912
     */
913
    public function setFirstname($firstname)
914
    {
915
        $this->firstname = $firstname;
0 ignored issues
show
Bug Best Practice introduced by
The property firstname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
916
917
        return $this;
918
    }
919
920
    /**
921
     * Set password.
922
     *
923
     * @param string $password
924
     *
925
     * @return User
926
     */
927
    public function setPassword($password)
928
    {
929
        $this->password = $password;
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
930
931
        return $this;
932
    }
933
934
    /**
935
     * Get password.
936
     *
937
     * @return string
938
     */
939
    public function getPassword()
940
    {
941
        return $this->password;
942
    }
943
944
    /**
945
     * Set authSource.
946
     *
947
     * @param string $authSource
948
     *
949
     * @return User
950
     */
951
    public function setAuthSource($authSource)
952
    {
953
        $this->authSource = $authSource;
954
955
        return $this;
956
    }
957
958
    /**
959
     * Get authSource.
960
     *
961
     * @return string
962
     */
963
    public function getAuthSource()
964
    {
965
        return $this->authSource;
966
    }
967
968
    /**
969
     * Set email.
970
     *
971
     * @param string $email
972
     *
973
     * @return User
974
     */
975
    public function setEmail($email)
976
    {
977
        $this->email = $email;
0 ignored issues
show
Bug Best Practice introduced by
The property email does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
978
979
        return $this;
980
    }
981
982
    /**
983
     * Get email.
984
     *
985
     * @return string
986
     */
987
    public function getEmail()
988
    {
989
        return $this->email;
990
    }
991
992
    /**
993
     * Set status.
994
     *
995
     * @param int $status
996
     *
997
     * @return User
998
     */
999
    public function setStatus($status)
1000
    {
1001
        $this->status = $status;
1002
1003
        return $this;
1004
    }
1005
1006
    /**
1007
     * Get status.
1008
     *
1009
     * @return int
1010
     */
1011
    public function getStatus()
1012
    {
1013
        return $this->status;
1014
    }
1015
1016
    /**
1017
     * Set officialCode.
1018
     *
1019
     * @param string $officialCode
1020
     *
1021
     * @return User
1022
     */
1023
    public function setOfficialCode($officialCode)
1024
    {
1025
        $this->officialCode = $officialCode;
1026
1027
        return $this;
1028
    }
1029
1030
    /**
1031
     * Get officialCode.
1032
     *
1033
     * @return string
1034
     */
1035
    public function getOfficialCode()
1036
    {
1037
        return $this->officialCode;
1038
    }
1039
1040
    /**
1041
     * Set phone.
1042
     *
1043
     * @param string $phone
1044
     *
1045
     * @return User
1046
     */
1047
    public function setPhone($phone)
1048
    {
1049
        $this->phone = $phone;
0 ignored issues
show
Bug Best Practice introduced by
The property phone does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1050
1051
        return $this;
1052
    }
1053
1054
    /**
1055
     * Get phone.
1056
     *
1057
     * @return string
1058
     */
1059
    public function getPhone()
1060
    {
1061
        return $this->phone;
1062
    }
1063
1064
    /**
1065
     * Set address.
1066
     *
1067
     * @param string $address
1068
     *
1069
     * @return User
1070
     */
1071
    public function setAddress($address)
1072
    {
1073
        $this->address = $address;
1074
1075
        return $this;
1076
    }
1077
1078
    /**
1079
     * Get address.
1080
     *
1081
     * @return string
1082
     */
1083
    public function getAddress()
1084
    {
1085
        return $this->address;
1086
    }
1087
1088
    /**
1089
     * Set creatorId.
1090
     *
1091
     * @param int $creatorId
1092
     *
1093
     * @return User
1094
     */
1095
    public function setCreatorId($creatorId)
1096
    {
1097
        $this->creatorId = $creatorId;
1098
1099
        return $this;
1100
    }
1101
1102
    /**
1103
     * Get creatorId.
1104
     *
1105
     * @return int
1106
     */
1107
    public function getCreatorId()
1108
    {
1109
        return $this->creatorId;
1110
    }
1111
1112
    /**
1113
     * Set competences.
1114
     *
1115
     * @param string $competences
1116
     *
1117
     * @return User
1118
     */
1119
    public function setCompetences($competences)
1120
    {
1121
        $this->competences = $competences;
1122
1123
        return $this;
1124
    }
1125
1126
    /**
1127
     * Get competences.
1128
     *
1129
     * @return string
1130
     */
1131
    public function getCompetences()
1132
    {
1133
        return $this->competences;
1134
    }
1135
1136
    /**
1137
     * Set diplomas.
1138
     *
1139
     * @param string $diplomas
1140
     *
1141
     * @return User
1142
     */
1143
    public function setDiplomas($diplomas)
1144
    {
1145
        $this->diplomas = $diplomas;
1146
1147
        return $this;
1148
    }
1149
1150
    /**
1151
     * Get diplomas.
1152
     *
1153
     * @return string
1154
     */
1155
    public function getDiplomas()
1156
    {
1157
        return $this->diplomas;
1158
    }
1159
1160
    /**
1161
     * Set openarea.
1162
     *
1163
     * @param string $openarea
1164
     *
1165
     * @return User
1166
     */
1167
    public function setOpenarea($openarea)
1168
    {
1169
        $this->openarea = $openarea;
1170
1171
        return $this;
1172
    }
1173
1174
    /**
1175
     * Get openarea.
1176
     *
1177
     * @return string
1178
     */
1179
    public function getOpenarea()
1180
    {
1181
        return $this->openarea;
1182
    }
1183
1184
    /**
1185
     * Set teach.
1186
     *
1187
     * @param string $teach
1188
     *
1189
     * @return User
1190
     */
1191
    public function setTeach($teach)
1192
    {
1193
        $this->teach = $teach;
1194
1195
        return $this;
1196
    }
1197
1198
    /**
1199
     * Get teach.
1200
     *
1201
     * @return string
1202
     */
1203
    public function getTeach()
1204
    {
1205
        return $this->teach;
1206
    }
1207
1208
    /**
1209
     * Set productions.
1210
     *
1211
     * @param string $productions
1212
     *
1213
     * @return User
1214
     */
1215
    public function setProductions($productions)
1216
    {
1217
        $this->productions = $productions;
1218
1219
        return $this;
1220
    }
1221
1222
    /**
1223
     * Get productions.
1224
     *
1225
     * @return string
1226
     */
1227
    public function getProductions()
1228
    {
1229
        return $this->productions;
1230
    }
1231
1232
    /**
1233
     * Set language.
1234
     *
1235
     * @param string $language
1236
     *
1237
     * @return User
1238
     */
1239
    public function setLanguage($language)
1240
    {
1241
        $this->language = $language;
1242
1243
        return $this;
1244
    }
1245
1246
    /**
1247
     * Get language.
1248
     *
1249
     * @return string
1250
     */
1251
    public function getLanguage()
1252
    {
1253
        return $this->language;
1254
    }
1255
1256
    /**
1257
     * Set registrationDate.
1258
     *
1259
     * @param \DateTime $registrationDate
1260
     *
1261
     * @return User
1262
     */
1263
    public function setRegistrationDate($registrationDate)
1264
    {
1265
        $this->registrationDate = $registrationDate;
1266
1267
        return $this;
1268
    }
1269
1270
    /**
1271
     * Get registrationDate.
1272
     *
1273
     * @return \DateTime
1274
     */
1275
    public function getRegistrationDate()
1276
    {
1277
        return $this->registrationDate;
1278
    }
1279
1280
    /**
1281
     * Set expirationDate.
1282
     *
1283
     * @param \DateTime $expirationDate
1284
     *
1285
     * @return User
1286
     */
1287
    public function setExpirationDate($expirationDate)
1288
    {
1289
        $this->expirationDate = $expirationDate;
1290
1291
        return $this;
1292
    }
1293
1294
    /**
1295
     * Get expirationDate.
1296
     *
1297
     * @return \DateTime
1298
     */
1299
    public function getExpirationDate()
1300
    {
1301
        return $this->expirationDate;
1302
    }
1303
1304
    /**
1305
     * Set active.
1306
     *
1307
     * @param bool $active
1308
     *
1309
     * @return User
1310
     */
1311
    public function setActive($active)
1312
    {
1313
        $this->active = $active;
1314
1315
        return $this;
1316
    }
1317
1318
    /**
1319
     * Get active.
1320
     *
1321
     * @return bool
1322
     */
1323
    public function getActive()
1324
    {
1325
        return $this->active;
1326
    }
1327
1328
    /**
1329
     * Set openid.
1330
     *
1331
     * @param string $openid
1332
     *
1333
     * @return User
1334
     */
1335
    public function setOpenid($openid)
1336
    {
1337
        $this->openid = $openid;
1338
1339
        return $this;
1340
    }
1341
1342
    /**
1343
     * Get openid.
1344
     *
1345
     * @return string
1346
     */
1347
    public function getOpenid()
1348
    {
1349
        return $this->openid;
1350
    }
1351
1352
    /**
1353
     * Set theme.
1354
     *
1355
     * @param string $theme
1356
     *
1357
     * @return User
1358
     */
1359
    public function setTheme($theme)
1360
    {
1361
        $this->theme = $theme;
1362
1363
        return $this;
1364
    }
1365
1366
    /**
1367
     * Get theme.
1368
     *
1369
     * @return string
1370
     */
1371
    public function getTheme()
1372
    {
1373
        return $this->theme;
1374
    }
1375
1376
    /**
1377
     * Set hrDeptId.
1378
     *
1379
     * @param int $hrDeptId
1380
     *
1381
     * @return User
1382
     */
1383
    public function setHrDeptId($hrDeptId)
1384
    {
1385
        $this->hrDeptId = $hrDeptId;
1386
1387
        return $this;
1388
    }
1389
1390
    /**
1391
     * Get hrDeptId.
1392
     *
1393
     * @return int
1394
     */
1395
    public function getHrDeptId()
1396
    {
1397
        return $this->hrDeptId;
1398
    }
1399
1400
    /**
1401
     * @return \DateTime
1402
     */
1403
    public function getMemberSince()
1404
    {
1405
        return $this->registrationDate;
1406
    }
1407
1408
    /**
1409
     * @return bool
1410
     */
1411
    public function isOnline()
1412
    {
1413
        return false;
1414
    }
1415
1416
    /**
1417
     * @return int
1418
     */
1419
    public function getIdentifier()
1420
    {
1421
        return $this->getId();
1422
    }
1423
1424
    /**
1425
     * @return string
1426
     */
1427
    public function getSlug()
1428
    {
1429
        return $this->getUsername();
1430
    }
1431
1432
    /**
1433
     * @param $slug
1434
     *
1435
     * @return User
1436
     */
1437
    public function setSlug($slug)
1438
    {
1439
        return $this->setUsername($slug);
1440
    }
1441
1442
    /**
1443
     * Set lastLogin.
1444
     *
1445
     * @param \DateTime $lastLogin
1446
     *
1447
     * @return User
1448
     */
1449
    public function setLastLogin(\DateTime $lastLogin = null)
1450
    {
1451
        $this->lastLogin = $lastLogin;
0 ignored issues
show
Bug Best Practice introduced by
The property lastLogin does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1452
1453
        return $this;
1454
    }
1455
1456
    /**
1457
     * Get lastLogin.
1458
     *
1459
     * @return \DateTime
1460
     */
1461
    public function getLastLogin()
1462
    {
1463
        return $this->lastLogin;
1464
    }
1465
1466
    /**
1467
     * Get sessionCourseSubscription.
1468
     *
1469
     * @return ArrayCollection
1470
     */
1471
    public function getSessionCourseSubscriptions()
1472
    {
1473
        return $this->sessionCourseSubscriptions;
1474
    }
1475
1476
    /**
1477
     * @param $value
1478
     *
1479
     * @return $this
1480
     */
1481
    public function setSessionCourseSubscriptions($value)
1482
    {
1483
        $this->sessionCourseSubscriptions = $value;
1484
1485
        return $this;
1486
    }
1487
1488
    /**
1489
     * @return string
1490
     */
1491
    public function getConfirmationToken()
1492
    {
1493
        return $this->confirmationToken;
1494
    }
1495
1496
    /**
1497
     * @param string $confirmationToken
1498
     *
1499
     * @return User
1500
     */
1501
    public function setConfirmationToken($confirmationToken)
1502
    {
1503
        $this->confirmationToken = $confirmationToken;
0 ignored issues
show
Bug Best Practice introduced by
The property confirmationToken does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1504
1505
        return $this;
1506
    }
1507
1508
    /**
1509
     * @return \DateTime
1510
     */
1511
    public function getPasswordRequestedAt()
1512
    {
1513
        return $this->passwordRequestedAt;
1514
    }
1515
1516
    /**
1517
     * @param int $ttl
1518
     *
1519
     * @return bool
1520
     */
1521
    /*public function isPasswordRequestNonExpired($ttl)
1522
    {
1523
        return $this->getPasswordRequestedAt() instanceof \DateTime &&
1524
            $this->getPasswordRequestedAt()->getTimestamp() + $ttl > time();
1525
    }*/
1526
1527
    public function getUsername(): string
1528
    {
1529
        return (string) $this->username;
1530
    }
1531
1532
    /**
1533
     * Returns the expiration date.
1534
     *
1535
     * @return \DateTime|null
1536
     */
1537
    public function getExpiresAt()
1538
    {
1539
        return $this->expiresAt;
1540
    }
1541
1542
    /**
1543
     * Returns the credentials expiration date.
1544
     *
1545
     * @return \DateTime
1546
     */
1547
    public function getCredentialsExpireAt()
1548
    {
1549
        return $this->credentialsExpireAt;
1550
    }
1551
1552
    /**
1553
     * Sets the credentials expiration date.
1554
     *
1555
     * @return User
1556
     */
1557
    public function setCredentialsExpireAt(\DateTime $date = null)
1558
    {
1559
        $this->credentialsExpireAt = $date;
1560
1561
        return $this;
1562
    }
1563
1564
    /**
1565
     * Sets the user groups.
1566
     *
1567
     * @param array $groups
1568
     *
1569
     * @return User
1570
     */
1571
    public function setGroups($groups)
1572
    {
1573
        foreach ($groups as $group) {
1574
            $this->addGroup($group);
1575
        }
1576
1577
        return $this;
1578
    }
1579
1580
    /**
1581
     * @return string
1582
     */
1583
    public function getFullname()
1584
    {
1585
        return sprintf('%s %s', $this->getFirstname(), $this->getLastname());
1586
    }
1587
1588
    /**
1589
     * Returns the user roles.
1590
     *
1591
     * @return array The roles
1592
     */
1593
    public function getRoles()
1594
    {
1595
        $roles = $this->roles;
1596
1597
        foreach ($this->getGroups() as $group) {
1598
            $roles = array_merge($roles, $group->getRoles());
1599
        }
1600
1601
        // we need to make sure to have at least one role
1602
        $roles[] = static::ROLE_DEFAULT;
1603
1604
        return array_unique($roles);
1605
    }
1606
1607
    public function isAccountNonExpired()
1608
    {
1609
        /*if (true === $this->expired) {
1610
            return false;
1611
        }
1612
1613
        if (null !== $this->expiresAt && $this->expiresAt->getTimestamp() < time()) {
1614
            return false;
1615
        }*/
1616
1617
        return true;
1618
    }
1619
1620
    public function isAccountNonLocked()
1621
    {
1622
        return true;
1623
        //return !$this->locked;
1624
    }
1625
1626
    public function isCredentialsNonExpired()
1627
    {
1628
        /*if (true === $this->credentialsExpired) {
1629
            return false;
1630
        }
1631
1632
        if (null !== $this->credentialsExpireAt && $this->credentialsExpireAt->getTimestamp() < time()) {
1633
            return false;
1634
        }*/
1635
1636
        return true;
1637
    }
1638
1639
    /**
1640
     * @return bool
1641
     */
1642
    public function getCredentialsExpired()
1643
    {
1644
        return $this->credentialsExpired;
1645
    }
1646
1647
    /**
1648
     * @param bool $boolean
1649
     *
1650
     * @return User
1651
     */
1652
    public function setCredentialsExpired($boolean)
1653
    {
1654
        $this->credentialsExpired = $boolean;
1655
1656
        return $this;
1657
    }
1658
1659
    /**
1660
     * @param $boolean
1661
     *
1662
     * @return $this|BaseUser
1663
     */
1664
    public function setEnabled($boolean)
1665
    {
1666
        $this->enabled = (bool) $boolean;
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1667
1668
        return $this;
1669
    }
1670
1671
    /**
1672
     * @return bool
1673
     */
1674
    public function getExpired()
1675
    {
1676
        return $this->expired;
1677
    }
1678
1679
    /**
1680
     * Sets this user to expired.
1681
     *
1682
     * @param bool $boolean
1683
     *
1684
     * @return User
1685
     */
1686
    public function setExpired($boolean)
1687
    {
1688
        $this->expired = (bool) $boolean;
1689
1690
        return $this;
1691
    }
1692
1693
    /**
1694
     * @return User
1695
     */
1696
    public function setExpiresAt(\DateTime $date)
1697
    {
1698
        $this->expiresAt = $date;
1699
1700
        return $this;
1701
    }
1702
1703
    public function getLocked(): bool
1704
    {
1705
        return $this->locked;
1706
    }
1707
1708
    /**
1709
     * @param $boolean
1710
     *
1711
     * @return $this
1712
     */
1713
    public function setLocked($boolean)
1714
    {
1715
        $this->locked = $boolean;
1716
1717
        return $this;
1718
    }
1719
1720
    /**
1721
     * @return $this
1722
     */
1723
    public function setRoles(array $roles)
1724
    {
1725
        $this->roles = [];
0 ignored issues
show
Bug Best Practice introduced by
The property roles does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
1726
1727
        foreach ($roles as $role) {
1728
            $this->addRole($role);
1729
        }
1730
1731
        return $this;
1732
    }
1733
1734
    /**
1735
     * Get achievedSkills.
1736
     *
1737
     * @return ArrayCollection
1738
     */
1739
    public function getAchievedSkills()
1740
    {
1741
        return $this->achievedSkills;
1742
    }
1743
1744
    /**
1745
     * @param $value
1746
     *
1747
     * @return $this
1748
     */
1749
    public function setAchievedSkills($value)
1750
    {
1751
        $this->achievedSkills = $value;
1752
1753
        return $this;
1754
    }
1755
1756
    /**
1757
     * Check if the user has the skill.
1758
     *
1759
     * @param Skill $skill The skill
1760
     *
1761
     * @return bool
1762
     */
1763
    public function hasSkill(Skill $skill)
1764
    {
1765
        $achievedSkills = $this->getAchievedSkills();
1766
1767
        foreach ($achievedSkills as $userSkill) {
1768
            if ($userSkill->getSkill()->getId() !== $skill->getId()) {
1769
                continue;
1770
            }
1771
1772
            return true;
1773
        }
1774
    }
1775
1776
    /**
1777
     * @return bool
1778
     */
1779
    public function isProfileCompleted()
1780
    {
1781
        return $this->profileCompleted;
1782
    }
1783
1784
    /**
1785
     * @param mixed $profileCompleted
1786
     *
1787
     * @return User
1788
     */
1789
    public function setProfileCompleted($profileCompleted)
1790
    {
1791
        $this->profileCompleted = $profileCompleted;
1792
1793
        return $this;
1794
    }
1795
1796
    /**
1797
     * Sets the AccessUrl for the current user in memory.
1798
     *
1799
     * @return $this
1800
     */
1801
    public function setCurrentUrl(AccessUrl $url)
1802
    {
1803
        $urlList = $this->getPortals();
1804
        /** @var AccessUrlRelUser $item */
1805
        foreach ($urlList as $item) {
1806
            if ($item->getUrl()->getId() === $url->getId()) {
1807
                $this->currentUrl = $url;
1808
                break;
1809
            }
1810
        }
1811
1812
        return $this;
1813
    }
1814
1815
    /**
1816
     * @return AccessUrl
1817
     */
1818
    public function getCurrentUrl()
1819
    {
1820
        return $this->currentUrl;
1821
    }
1822
1823
    /**
1824
     * Get sessionAsGeneralCoach.
1825
     *
1826
     * @return ArrayCollection
1827
     */
1828
    public function getSessionAsGeneralCoach()
1829
    {
1830
        return $this->sessionAsGeneralCoach;
1831
    }
1832
1833
    /**
1834
     * Get sessionAsGeneralCoach.
1835
     *
1836
     * @param ArrayCollection $value
1837
     *
1838
     * @return $this
1839
     */
1840
    public function setSessionAsGeneralCoach($value)
1841
    {
1842
        $this->sessionAsGeneralCoach = $value;
1843
1844
        return $this;
1845
    }
1846
1847
    /**
1848
     * @return mixed
1849
     */
1850
    public function getCommentedUserSkills()
1851
    {
1852
        return $this->commentedUserSkills;
1853
    }
1854
1855
    /**
1856
     * @param mixed $commentedUserSkills
1857
     *
1858
     * @return User
1859
     */
1860
    public function setCommentedUserSkills($commentedUserSkills)
1861
    {
1862
        $this->commentedUserSkills = $commentedUserSkills;
1863
1864
        return $this;
1865
    }
1866
1867
    /**
1868
     * @return bool
1869
     */
1870
    public function isEqualTo(UserInterface $user)
1871
    {
1872
        if ($this->password !== $user->getPassword()) {
1873
            return false;
1874
        }
1875
1876
        if ($this->salt !== $user->getSalt()) {
1877
            return false;
1878
        }
1879
1880
        if ($this->username !== $user->getUsername()) {
1881
            return false;
1882
        }
1883
1884
        return true;
1885
    }
1886
1887
    public function getPictureLegacy(): string
1888
    {
1889
        $id = $this->id;
1890
        $uri = $this->getPictureUri();
1891
        if ($uri) {
1892
            return 'users/'.substr((string) $id, 0, 1).'/'.$id.'/'.'small_'.$uri;
1893
        }
1894
1895
        return '';
1896
    }
1897
1898
    /**
1899
     * Get sentMessages.
1900
     *
1901
     * @return ArrayCollection
1902
     */
1903
    public function getSentMessages()
1904
    {
1905
        return $this->sentMessages;
1906
    }
1907
1908
    /**
1909
     * Get receivedMessages.
1910
     *
1911
     * @return ArrayCollection
1912
     */
1913
    public function getReceivedMessages()
1914
    {
1915
        return $this->receivedMessages;
1916
    }
1917
1918
    /**
1919
     * @param int $lastId Optional. The ID of the last received message
1920
     */
1921
    public function getUnreadReceivedMessages($lastId = 0): ArrayCollection
1922
    {
1923
        $criteria = Criteria::create();
1924
        $criteria->where(
1925
            Criteria::expr()->eq('msgStatus', MESSAGE_STATUS_UNREAD)
1926
        );
1927
1928
        if ($lastId > 0) {
1929
            $criteria->andWhere(
1930
                Criteria::expr()->gt('id', (int) $lastId)
1931
            );
1932
        }
1933
1934
        $criteria->orderBy(['sendDate' => Criteria::DESC]);
1935
1936
        return $this->receivedMessages->matching($criteria);
1937
    }
1938
1939
    public function getCourseGroupsAsMember(): Collection
1940
    {
1941
        return $this->courseGroupsAsMember;
1942
    }
1943
1944
    public function getCourseGroupsAsTutor(): Collection
1945
    {
1946
        return $this->courseGroupsAsTutor;
1947
    }
1948
1949
    public function getCourseGroupsAsMemberFromCourse(Course $course): ArrayCollection
1950
    {
1951
        $criteria = Criteria::create();
1952
        $criteria->where(
1953
            Criteria::expr()->eq('cId', $course)
1954
        );
1955
1956
        return $this->courseGroupsAsMember->matching($criteria);
1957
    }
1958
1959
    public function getCourseGroupsAsTutorFromCourse(Course $course): ArrayCollection
1960
    {
1961
        $criteria = Criteria::create();
1962
        $criteria->where(
1963
            Criteria::expr()->eq('cId', $course->getId())
1964
        );
1965
1966
        return $this->courseGroupsAsTutor->matching($criteria);
1967
    }
1968
}
1969