1
|
|
|
<?php |
2
|
|
|
// src/AppBundle/Entity/User.php |
3
|
|
|
|
4
|
|
|
namespace AppBundle\Entity; |
5
|
|
|
|
6
|
|
|
use FOS\UserBundle\Model\User as BaseUser; |
7
|
|
|
use Doctrine\ORM\Mapping as ORM; |
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
9
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Entity |
13
|
|
|
* @ORM\Table(name="fos_user") |
14
|
|
|
* @UniqueEntity(fields="usernameCanonical", errorPath="username", message="fos_user.username.already_used", groups={"Default", "Registration", "Profile"}) |
15
|
|
|
* @UniqueEntity(fields="emailCanonical", errorPath="email", message="fos_user.email.already_used", groups={"Default", "Registration", "Profile"}) |
16
|
|
|
*/ |
17
|
|
|
class User extends BaseUser { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @ORM\Id |
21
|
|
|
* @ORM\Column(type="integer") |
22
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
23
|
|
|
*/ |
24
|
|
|
protected $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Group", inversedBy="users") |
28
|
|
|
* @ORM\JoinTable(name="fos_user_user_group", |
29
|
|
|
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, |
30
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} |
31
|
|
|
* ) |
32
|
|
|
*/ |
33
|
|
|
protected $groups; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\Column(type="integer", length=6, options={"default":0}) |
37
|
|
|
*/ |
38
|
|
|
protected $loginCount = 0; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \DateTime |
42
|
|
|
* |
43
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
44
|
|
|
*/ |
45
|
|
|
protected $firstLogin; |
46
|
|
|
|
47
|
|
|
public function __construct() { |
48
|
|
|
parent::__construct(); |
49
|
|
|
$this->groups = new ArrayCollection(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set loginCount |
54
|
|
|
* |
55
|
|
|
* @param integer $loginCount |
56
|
|
|
* |
57
|
|
|
* @return User |
58
|
|
|
*/ |
59
|
|
|
public function setLoginCount($loginCount) { |
60
|
|
|
$this->loginCount = $loginCount; |
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get loginCount |
66
|
|
|
* |
67
|
|
|
* @return integer |
68
|
|
|
*/ |
69
|
|
|
public function getLoginCount() { |
70
|
|
|
return $this->loginCount; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set firstLogin |
75
|
|
|
* |
76
|
|
|
* @param \DateTime $firstLogin |
77
|
|
|
* |
78
|
|
|
* @return User |
79
|
|
|
*/ |
80
|
|
|
public function setFirstLogin($firstLogin) { |
81
|
|
|
$this->firstLogin = $firstLogin; |
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get firstLogin |
87
|
|
|
* |
88
|
|
|
* @return \DateTime |
89
|
|
|
*/ |
90
|
|
|
public function getFirstLogin() { |
91
|
|
|
return $this->firstLogin; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function getEnabled() { |
|
|
|
|
95
|
|
|
return $this->enabled; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
function getLocked() { |
|
|
|
|
99
|
|
|
return $this->locked; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
function getExpired() { |
|
|
|
|
103
|
|
|
return $this->expired; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
function getExpiresAt() { |
|
|
|
|
107
|
|
|
return $this->expiresAt; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
function getCredentialsExpired() { |
|
|
|
|
111
|
|
|
return $this->credentialsExpired; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function getCredentialsExpireAt() { |
|
|
|
|
115
|
|
|
return $this->credentialsExpireAt; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
function setSalt($salt) { |
|
|
|
|
119
|
|
|
$this->salt = $salt; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function setPassword($password) { |
123
|
|
|
if ($password !== null) { |
124
|
|
|
$this->password = $password; |
125
|
|
|
} |
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function setGroups(Collection $groups = null) { |
|
|
|
|
130
|
|
|
if ($groups !== null) { |
131
|
|
|
$this->groups = $groups; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function setRoles(array $roles = array()) { |
136
|
|
|
$this->roles = array(); |
137
|
|
|
foreach ($roles as $role) { |
138
|
|
|
$this->addRole($role); |
139
|
|
|
} |
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function hasGroup($name = '') { |
144
|
|
|
return in_array($name, $this->getGroupNames()); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.