1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Component\Customer\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Michał Marcinkowski <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Customer implements CustomerInterface, GroupableInterface |
22
|
|
|
{ |
23
|
|
|
use TimestampableTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var mixed |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $email; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $emailCanonical; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $firstName; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
protected $lastName; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var \DateTime |
52
|
|
|
*/ |
53
|
|
|
protected $birthday; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
protected $gender = CustomerInterface::UNKNOWN_GENDER; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var Collection|GroupInterface[] |
62
|
|
|
*/ |
63
|
|
|
protected $groups; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
protected $phoneNumber; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
protected $subscribedToNewsletter = false; |
74
|
|
|
|
75
|
|
|
public function __construct() |
76
|
|
|
{ |
77
|
|
|
$this->groups = new ArrayCollection(); |
78
|
|
|
$this->createdAt = new \DateTime(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function getId() |
85
|
|
|
{ |
86
|
|
|
return $this->id; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function getEmail() |
93
|
|
|
{ |
94
|
|
|
return $this->email; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function setEmail($email) |
101
|
|
|
{ |
102
|
|
|
$this->email = $email; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function getEmailCanonical() |
109
|
|
|
{ |
110
|
|
|
return $this->emailCanonical; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function setEmailCanonical($emailCanonical) |
117
|
|
|
{ |
118
|
|
|
$this->emailCanonical = $emailCanonical; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function getFullName() |
125
|
|
|
{ |
126
|
|
|
return trim(sprintf('%s %s', $this->firstName, $this->lastName)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* {@inheritdoc} |
131
|
|
|
*/ |
132
|
|
|
public function getFirstName() |
133
|
|
|
{ |
134
|
|
|
return $this->firstName; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
public function setFirstName($firstName) |
141
|
|
|
{ |
142
|
|
|
$this->firstName = $firstName; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function getLastName() |
149
|
|
|
{ |
150
|
|
|
return $this->lastName; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* {@inheritdoc} |
155
|
|
|
*/ |
156
|
|
|
public function setLastName($lastName) |
157
|
|
|
{ |
158
|
|
|
$this->lastName = $lastName; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* {@inheritdoc} |
163
|
|
|
*/ |
164
|
|
|
public function getBirthday() |
165
|
|
|
{ |
166
|
|
|
return $this->birthday; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* {@inheritdoc} |
171
|
|
|
*/ |
172
|
|
|
public function setBirthday(\DateTime $birthday = null) |
173
|
|
|
{ |
174
|
|
|
$this->birthday = $birthday; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* {@inheritdoc} |
179
|
|
|
*/ |
180
|
|
|
public function getGender() |
181
|
|
|
{ |
182
|
|
|
return $this->gender; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* {@inheritdoc} |
187
|
|
|
*/ |
188
|
|
|
public function setGender($gender) |
189
|
|
|
{ |
190
|
|
|
$this->gender = $gender; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* {@inheritdoc} |
195
|
|
|
*/ |
196
|
|
|
public function isMale() |
197
|
|
|
{ |
198
|
|
|
return CustomerInterface::MALE_GENDER === $this->gender; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* {@inheritdoc} |
203
|
|
|
*/ |
204
|
|
|
public function isFemale() |
205
|
|
|
{ |
206
|
|
|
return CustomerInterface::FEMALE_GENDER === $this->gender; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* {@inheritdoc} |
211
|
|
|
*/ |
212
|
|
|
public function getGroups() |
213
|
|
|
{ |
214
|
|
|
return $this->groups; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* {@inheritdoc} |
219
|
|
|
*/ |
220
|
|
|
public function hasGroup($name) |
221
|
|
|
{ |
222
|
|
|
return in_array($name, $this->getGroupNames(), true); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* {@inheritdoc} |
227
|
|
|
*/ |
228
|
|
|
public function getGroupNames() |
229
|
|
|
{ |
230
|
|
|
$names = []; |
231
|
|
|
foreach ($this->groups as $group) { |
232
|
|
|
$names[] = $group->getName(); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
return $names; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* {@inheritdoc} |
240
|
|
|
*/ |
241
|
|
|
public function addGroup(GroupInterface $group) |
242
|
|
|
{ |
243
|
|
|
if (!$this->groups->contains($group)) { |
244
|
|
|
$this->groups->add($group); |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* {@inheritdoc} |
250
|
|
|
*/ |
251
|
|
|
public function removeGroup(GroupInterface $group) |
252
|
|
|
{ |
253
|
|
|
if ($this->groups->contains($group)) { |
254
|
|
|
$this->groups->removeElement($group); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* {@inheritdoc} |
260
|
|
|
*/ |
261
|
|
|
public function getPhoneNumber() |
262
|
|
|
{ |
263
|
|
|
return $this->phoneNumber; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* {@inheritdoc} |
268
|
|
|
*/ |
269
|
|
|
public function setPhoneNumber($phoneNumber) |
270
|
|
|
{ |
271
|
|
|
$this->phoneNumber = $phoneNumber; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* {@inheritdoc} |
276
|
|
|
*/ |
277
|
|
|
public function isSubscribedToNewsletter() |
278
|
|
|
{ |
279
|
|
|
return $this->subscribedToNewsletter; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* {@inheritdoc} |
284
|
|
|
*/ |
285
|
|
|
public function setSubscribedToNewsletter($subscribedToNewsletter) |
286
|
|
|
{ |
287
|
|
|
$this->subscribedToNewsletter = $subscribedToNewsletter; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
public function __toString() |
291
|
|
|
{ |
292
|
|
|
return $this->getEmail(); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
|