1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use FOS\UserBundle\Model\GroupInterface; |
8
|
|
|
use FOS\UserBundle\Model\User as AbstractUser; |
9
|
|
|
use Kunstmaan\AdminBundle\Validator\Constraints\PasswordRestrictions; |
10
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
11
|
|
|
use Symfony\Component\Validator\Constraints\Email; |
12
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
13
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata; |
14
|
|
|
|
15
|
|
|
abstract class BaseUser extends AbstractUser |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @ORM\Id |
19
|
|
|
* @ORM\Column(type="integer") |
20
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
21
|
|
|
*/ |
22
|
|
|
protected $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The doctrine metadata is set dynamically in Kunstmaan\AdminBundle\EventListener\MappingListener |
26
|
|
|
*/ |
27
|
|
|
protected $groups; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @ORM\Column(type="string", name="admin_locale", length=5, nullable=true) |
31
|
|
|
*/ |
32
|
|
|
protected $adminLocale; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @ORM\Column(type="boolean", name="password_changed", nullable=true) |
36
|
|
|
*/ |
37
|
|
|
protected $passwordChanged; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @ORM\Column(name="google_id", type="string", length=255, nullable=true) |
41
|
|
|
*/ |
42
|
|
|
protected $googleId; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \DateTimeImmutable|null |
46
|
|
|
* @ORM\Column(name="created_at", type="datetime_immutable", nullable=true) |
47
|
|
|
*/ |
48
|
|
|
protected $createdAt; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string|null |
52
|
|
|
* @ORM\Column(name="created_by", type="string", nullable=true) |
53
|
|
|
*/ |
54
|
|
|
protected $createdBy; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Construct a new user |
58
|
|
|
*/ |
59
|
35 |
|
public function __construct() |
60
|
|
|
{ |
61
|
35 |
|
parent::__construct(); |
62
|
35 |
|
$this->groups = new ArrayCollection(); |
63
|
35 |
|
$this->createdAt = new \DateTimeImmutable(); |
64
|
35 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get id |
68
|
|
|
* |
69
|
|
|
* @return int |
70
|
|
|
*/ |
71
|
3 |
|
public function getId() |
72
|
|
|
{ |
73
|
3 |
|
return $this->id; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Set id |
78
|
|
|
* |
79
|
|
|
* @param int $id |
80
|
|
|
* |
81
|
|
|
* @return BaseUser |
82
|
|
|
*/ |
83
|
8 |
|
public function setId($id) |
84
|
|
|
{ |
85
|
8 |
|
$this->id = $id; |
86
|
|
|
|
87
|
8 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Gets the groupIds for the user. |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
1 |
|
public function getGroupIds() |
96
|
|
|
{ |
97
|
1 |
|
$groups = $this->groups; |
98
|
|
|
|
99
|
1 |
|
$groupIds = array(); |
100
|
1 |
|
if (\count($groups) > 0) { |
101
|
|
|
/* @var $group GroupInterface */ |
102
|
1 |
|
foreach ($groups as $group) { |
103
|
1 |
|
$groupIds[] = $group->getId(); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
return $groupIds; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Gets the groups the user belongs to. |
112
|
|
|
* |
113
|
|
|
* @return ArrayCollection |
114
|
|
|
*/ |
115
|
6 |
|
public function getGroups() |
116
|
|
|
{ |
117
|
6 |
|
return $this->groups; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get adminLocale |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
1 |
|
public function getAdminLocale() |
126
|
|
|
{ |
127
|
1 |
|
return $this->adminLocale; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set adminLocale |
132
|
|
|
* |
133
|
|
|
* @param string $adminLocale |
134
|
|
|
* |
135
|
|
|
* @return BaseUser |
136
|
|
|
*/ |
137
|
2 |
|
public function setAdminLocale($adminLocale) |
138
|
|
|
{ |
139
|
2 |
|
$this->adminLocale = $adminLocale; |
140
|
|
|
|
141
|
2 |
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* is passwordChanged |
146
|
|
|
* |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
1 |
|
public function isPasswordChanged() |
150
|
|
|
{ |
151
|
1 |
|
return $this->passwordChanged; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Set passwordChanged |
156
|
|
|
* |
157
|
|
|
* @param bool $passwordChanged |
158
|
|
|
* |
159
|
|
|
* @return User |
160
|
|
|
*/ |
161
|
2 |
|
public function setPasswordChanged($passwordChanged) |
162
|
|
|
{ |
163
|
2 |
|
$this->passwordChanged = $passwordChanged; |
164
|
|
|
|
165
|
2 |
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return mixed |
170
|
|
|
*/ |
171
|
1 |
|
public function getGoogleId() |
172
|
|
|
{ |
173
|
1 |
|
return $this->googleId; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param mixed $googleId |
178
|
|
|
*/ |
179
|
3 |
|
public function setGoogleId($googleId) |
180
|
|
|
{ |
181
|
3 |
|
$this->googleId = $googleId; |
182
|
3 |
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param ClassMetadata $metadata |
186
|
|
|
*/ |
187
|
1 |
|
public static function loadValidatorMetadata(ClassMetadata $metadata) |
188
|
|
|
{ |
189
|
1 |
|
$metadata->addPropertyConstraint('username', new NotBlank()); |
190
|
1 |
|
$metadata->addPropertyConstraints( |
191
|
1 |
|
'plainPassword', |
192
|
|
|
array( |
193
|
1 |
|
new NotBlank(array('groups' => array('Registration'))), |
194
|
1 |
|
new PasswordRestrictions(array('groups' => array('Registration', 'Default'))), |
195
|
|
|
) |
196
|
|
|
); |
197
|
1 |
|
$metadata->addPropertyConstraint('email', new NotBlank()); |
198
|
1 |
|
$metadata->addPropertyConstraint('email', new Email()); |
199
|
1 |
|
$metadata->addConstraint(new UniqueEntity(array( |
200
|
1 |
|
'fields' => 'username', |
201
|
|
|
'message' => 'errors.user.loginexists', |
202
|
|
|
))); |
203
|
1 |
|
$metadata->addConstraint(new UniqueEntity(array( |
204
|
1 |
|
'fields' => 'email', |
205
|
|
|
'message' => 'errors.user.emailexists', |
206
|
|
|
))); |
207
|
1 |
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Return class name of form type used to add & edit users |
211
|
|
|
* |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
abstract public function getFormTypeClass(); |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* {@inheritdoc} |
218
|
|
|
*/ |
219
|
1 |
|
public function isAccountNonLocked() |
220
|
|
|
{ |
221
|
1 |
|
return $this->isEnabled(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function getCreatedAt(): ?\DateTimeImmutable |
225
|
|
|
{ |
226
|
|
|
return $this->createdAt; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function getCreatedBy(): ?string |
230
|
|
|
{ |
231
|
|
|
return $this->createdBy; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function setCreatedBy(string $createdBy): void |
235
|
|
|
{ |
236
|
|
|
$this->createdBy = $createdBy; |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|