1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use JMS\Serializer\Tests\Fixtures\Order; |
8
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
9
|
|
|
use JMS\Serializer\Annotation\ExclusionPolicy; |
10
|
|
|
use JMS\Serializer\Annotation\Expose; |
11
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
12
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\CustomerRepository") |
16
|
|
|
* @UniqueEntity("facebookId") |
17
|
|
|
* @ExclusionPolicy("all") |
18
|
|
|
*/ |
19
|
|
|
class Customer implements UserInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
* |
24
|
|
|
* @ORM\Column(name="id", type="integer") |
25
|
|
|
* @ORM\Id |
26
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
27
|
|
|
*/ |
28
|
|
|
protected $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* |
33
|
|
|
* @ORM\Column(name="first_name", type="string", length=100, nullable=true) |
34
|
|
|
* @Assert\Regex(pattern="/\d/", match=false) |
35
|
|
|
* @Assert\Type("string") |
36
|
|
|
* @Assert\Length(min=2, max=100) |
37
|
|
|
* @Assert\NotBlank( |
38
|
|
|
* message="not.blank" |
39
|
|
|
* ) |
40
|
|
|
* @Expose |
41
|
|
|
*/ |
42
|
|
|
protected $firstName; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(name="last_name", type="string", length=100, nullable=true) |
48
|
|
|
* @Assert\Regex(pattern="/\d/", match=false) |
49
|
|
|
* @Assert\Type("string") |
50
|
|
|
* @Assert\Length(min=2, max=100) |
51
|
|
|
* @Assert\NotBlank( |
52
|
|
|
* message="not.blank" |
53
|
|
|
* ) |
54
|
|
|
* @Expose |
55
|
|
|
*/ |
56
|
|
|
protected $lastName; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var string |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(name="email", type="string", length=100, nullable=true) |
62
|
|
|
* @Assert\Email() |
63
|
|
|
* @Assert\Type("string") |
64
|
|
|
* @Assert\Length(max=100) |
65
|
|
|
* @Assert\NotBlank( |
66
|
|
|
* message="not.blank" |
67
|
|
|
* ) |
68
|
|
|
* @Expose |
69
|
|
|
*/ |
70
|
|
|
protected $email; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string |
74
|
|
|
* |
75
|
|
|
* @ORM\Column(name="username", type="string", length=100) |
76
|
|
|
* @Assert\Type("string") |
77
|
|
|
* @Assert\Length(max=100) |
78
|
|
|
*/ |
79
|
|
|
protected $username; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var string |
83
|
|
|
* |
84
|
|
|
* @ORM\Column(name="api_key", type="string", length=255, nullable=true) |
85
|
|
|
* @Assert\Type("string") |
86
|
|
|
* @Assert\Length(max=255) |
87
|
|
|
*/ |
88
|
|
|
private $apiKey; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var string |
92
|
|
|
* |
93
|
|
|
* @ORM\Column(name="facebook_id", type="string", length=255, nullable=true, unique=true) |
94
|
|
|
* @Assert\Type("string") |
95
|
|
|
* @Assert\Length(max=255) |
96
|
|
|
*/ |
97
|
|
|
private $facebookId; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var ArrayCollection|Order[] |
101
|
|
|
* |
102
|
|
|
* @ORM\OneToMany( |
103
|
|
|
* targetEntity="AppBundle\Entity\CustomerOrder", |
104
|
|
|
* mappedBy="customer", |
105
|
|
|
* cascade={"persist", "remove"}, |
106
|
|
|
* orphanRemoval=true |
107
|
|
|
* ) |
108
|
|
|
*/ |
109
|
|
|
private $orders; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get id. |
113
|
|
|
* |
114
|
|
|
* @return int |
115
|
|
|
*/ |
116
|
|
|
public function getId() |
117
|
|
|
{ |
118
|
|
|
return $this->id; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set apiKey. |
123
|
|
|
* |
124
|
|
|
* @param string $apiKey |
125
|
|
|
* |
126
|
|
|
* @return Customer |
127
|
|
|
*/ |
128
|
|
|
public function setApiKey($apiKey) |
129
|
|
|
{ |
130
|
|
|
$this->apiKey = $apiKey; |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get apiKey. |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getApiKey() |
141
|
|
|
{ |
142
|
|
|
return $this->apiKey; |
143
|
|
|
} |
144
|
|
|
/** |
145
|
|
|
* Constructor. |
146
|
|
|
*/ |
147
|
|
|
public function __construct() |
148
|
|
|
{ |
149
|
|
|
$this->orders = new ArrayCollection(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function __toString() |
153
|
|
|
{ |
154
|
|
|
return $this->getFirstName().' '.$this->getLastName(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Add order. |
159
|
|
|
* |
160
|
|
|
* @param CustomerOrder $order |
161
|
|
|
* |
162
|
|
|
* @return Customer |
163
|
|
|
*/ |
164
|
|
|
public function addOrder(CustomerOrder $order) |
165
|
|
|
{ |
166
|
|
|
$this->orders[] = $order; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Remove order. |
173
|
|
|
* |
174
|
|
|
* @param CustomerOrder $order |
175
|
|
|
*/ |
176
|
|
|
public function removeOrder(CustomerOrder $order) |
177
|
|
|
{ |
178
|
|
|
$this->orders->removeElement($order); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get orders. |
183
|
|
|
* |
184
|
|
|
* @return \Doctrine\Common\Collections\Collection |
185
|
|
|
*/ |
186
|
|
|
public function getOrders() |
187
|
|
|
{ |
188
|
|
|
return $this->orders; |
189
|
|
|
} |
190
|
|
|
/** |
191
|
|
|
* {@inheritdoc} |
192
|
|
|
*/ |
193
|
|
|
public function getRoles() |
194
|
|
|
{ |
195
|
|
|
return array('ROLE_API'); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* {@inheritdoc} |
200
|
|
|
*/ |
201
|
|
|
public function getPassword() |
202
|
|
|
{ |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* {@inheritdoc} |
207
|
|
|
*/ |
208
|
|
|
public function getSalt() |
209
|
|
|
{ |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* {@inheritdoc} |
214
|
|
|
*/ |
215
|
|
|
public function eraseCredentials() |
216
|
|
|
{ |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Set facebookId. |
221
|
|
|
* |
222
|
|
|
* @param string $facebookId |
223
|
|
|
* |
224
|
|
|
* @return Customer |
225
|
|
|
*/ |
226
|
|
|
public function setFacebookId($facebookId) |
227
|
|
|
{ |
228
|
|
|
$this->facebookId = $facebookId; |
229
|
|
|
|
230
|
|
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get facebookId. |
235
|
|
|
* |
236
|
|
|
* @return string |
237
|
|
|
*/ |
238
|
|
|
public function getFacebookId() |
239
|
|
|
{ |
240
|
|
|
return $this->facebookId; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Set username. |
245
|
|
|
* |
246
|
|
|
* @param string $username |
247
|
|
|
* |
248
|
|
|
* @return Customer |
249
|
|
|
*/ |
250
|
|
|
public function setUsername($username) |
251
|
|
|
{ |
252
|
|
|
$this->username = $username; |
253
|
|
|
|
254
|
|
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Get username. |
259
|
|
|
* |
260
|
|
|
* @return string |
261
|
|
|
*/ |
262
|
|
|
public function getUsername() |
263
|
|
|
{ |
264
|
|
|
return $this->username; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Set firstName. |
269
|
|
|
* |
270
|
|
|
* @param string $firstName |
271
|
|
|
* |
272
|
|
|
* @return Customer |
273
|
|
|
*/ |
274
|
|
|
public function setFirstName($firstName) |
275
|
|
|
{ |
276
|
|
|
$this->firstName = $firstName; |
277
|
|
|
|
278
|
|
|
return $this; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Get firstName. |
283
|
|
|
* |
284
|
|
|
* @return string |
285
|
|
|
*/ |
286
|
|
|
public function getFirstName() |
287
|
|
|
{ |
288
|
|
|
return $this->firstName; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Set lastName. |
293
|
|
|
* |
294
|
|
|
* @param string $lastName |
295
|
|
|
* |
296
|
|
|
* @return Customer |
297
|
|
|
*/ |
298
|
|
|
public function setLastName($lastName) |
299
|
|
|
{ |
300
|
|
|
$this->lastName = $lastName; |
301
|
|
|
|
302
|
|
|
return $this; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Get lastName. |
307
|
|
|
* |
308
|
|
|
* @return string |
309
|
|
|
*/ |
310
|
|
|
public function getLastName() |
311
|
|
|
{ |
312
|
|
|
return $this->lastName; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Set email. |
317
|
|
|
* |
318
|
|
|
* @param string $email |
319
|
|
|
* |
320
|
|
|
* @return Customer |
321
|
|
|
*/ |
322
|
|
|
public function setEmail($email) |
323
|
|
|
{ |
324
|
|
|
$this->email = $email; |
325
|
|
|
|
326
|
|
|
return $this; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Get email. |
331
|
|
|
* |
332
|
|
|
* @return string |
333
|
|
|
*/ |
334
|
|
|
public function getEmail() |
335
|
|
|
{ |
336
|
|
|
return $this->email; |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|