1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zephia\PilotApiClient\Model; |
4
|
|
|
|
5
|
|
|
use Zephia\PilotApiClient\Exception\InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
class LeadData |
8
|
|
|
{ |
9
|
|
|
private $firstname; |
10
|
|
|
private $lastname; |
11
|
|
|
private $phone; |
12
|
|
|
private $cellphone; |
13
|
|
|
private $email; |
14
|
|
|
private $contact_type_id; |
15
|
|
|
private $business_type_id; |
16
|
|
|
private $notes; |
17
|
|
|
private $origin_id; |
18
|
|
|
private $suborigin_id; |
19
|
|
|
private $assigned_user; |
20
|
|
|
private $car_brand; |
21
|
|
|
private $car_modelo; |
22
|
|
|
private $city; |
23
|
|
|
private $province; |
24
|
|
|
private $country; |
25
|
|
|
private $vendor_name; |
26
|
|
|
private $vendor_email; |
27
|
|
|
private $vendor_phone; |
28
|
|
|
private $provider_service; |
29
|
|
|
private $provider_url; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* LeadData constructor. |
33
|
|
|
* |
34
|
|
|
* @param array $data |
35
|
|
|
*/ |
36
|
27 |
|
public function __construct($data = []) |
37
|
|
|
{ |
38
|
27 |
|
if (count($data) > 0) { |
39
|
26 |
|
foreach ($data as $key => $value) { |
40
|
26 |
|
$this->set($key, $value); |
41
|
26 |
|
} |
42
|
26 |
|
$this->validate(); |
43
|
4 |
|
} |
44
|
5 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Object to array |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
25 |
|
public function toArray() |
52
|
|
|
{ |
53
|
25 |
|
$this->validate(); |
54
|
|
|
return [ |
55
|
4 |
|
'pilot_firstname' => $this->getFirstname(), |
56
|
4 |
|
'pilot_lastname' => $this->getLastname(), |
57
|
4 |
|
'pilot_phone' => $this->getPhone(), |
58
|
4 |
|
'pilot_cellphone' => $this->getCellphone(), |
59
|
4 |
|
'pilot_email' => $this->getEmail(), |
60
|
4 |
|
'pilot_contact_type_id' => $this->getContactTypeId(), |
61
|
4 |
|
'pilot_business_type_id' => $this->getBusinessTypeId(), |
62
|
4 |
|
'pilot_notes' => $this->getNotes(), |
63
|
4 |
|
'pilot_origin_id' => $this->getOriginId(), |
64
|
4 |
|
'pilot_suborigin_id' => $this->getSuboriginId(), |
65
|
4 |
|
'pilot_assigned_user' => $this->getAssignedUser(), |
66
|
4 |
|
'pilot_car_brand' => $this->getCarBrand(), |
67
|
4 |
|
'pilot_car_modelo' => $this->getCarModelo(), |
68
|
4 |
|
'pilot_city' => $this->getCity(), |
69
|
4 |
|
'pilot_province' => $this->getProvince(), |
70
|
4 |
|
'pilot_country' => $this->getCountry(), |
71
|
4 |
|
'pilot_vendor_name' => $this->getVendorName(), |
72
|
4 |
|
'pilot_vendor_email' => $this->getVendorEmail(), |
73
|
4 |
|
'pilot_vendor_phone' => $this->getVendorPhone(), |
74
|
4 |
|
'pilot_provider_service' => $this->getProviderService(), |
75
|
4 |
|
'pilot_provider_url' => $this->getProviderUrl() |
76
|
4 |
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Validate |
81
|
|
|
* |
82
|
|
|
* @throws InvalidArgumentException |
83
|
|
|
*/ |
84
|
47 |
|
private function validate() |
85
|
|
|
{ |
86
|
47 |
|
$required = ''; |
87
|
|
|
|
88
|
|
|
$validations = [ |
89
|
47 |
|
'firstname|lastname', |
90
|
47 |
|
'phone|cellphone|email', |
91
|
47 |
|
'contact_type_id', |
92
|
47 |
|
'business_type_id', |
93
|
47 |
|
'suborigin_id', |
94
|
47 |
|
]; |
95
|
|
|
|
96
|
47 |
|
for ($i = 0; $i < count($validations) && empty($required); $i ++) { |
97
|
47 |
|
switch ($validations[$i]) { |
98
|
47 |
|
case "firstname|lastname": |
99
|
47 |
|
$required = $this->validateFirstnameOrLastname(); |
100
|
47 |
|
break; |
101
|
46 |
|
case "phone|cellphone|email": |
102
|
46 |
|
$required = $this->validatePhoneCellphoneOrEmail(); |
103
|
46 |
|
break; |
104
|
40 |
|
case "contact_type_id": |
105
|
40 |
|
$required = $this->validateContactTypeId(); |
106
|
40 |
|
break; |
107
|
28 |
|
case "business_type_id": |
108
|
28 |
|
$required = $this->validateBusinessTypeId(); |
109
|
28 |
|
break; |
110
|
16 |
|
case "suborigin_id": |
111
|
16 |
|
$required = $this->validateSuboriginId(); |
112
|
16 |
|
break; |
113
|
47 |
|
} |
114
|
47 |
|
} |
115
|
|
|
|
116
|
47 |
|
if (!empty($required)) { |
117
|
43 |
|
throw new InvalidArgumentException( |
118
|
43 |
|
sprintf('Missing required value: %s.', $required) |
119
|
43 |
|
); |
120
|
|
|
} |
121
|
4 |
|
} |
122
|
|
|
|
123
|
|
|
// Validations |
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
47 |
|
public function validateFirstnameOrLastname() |
128
|
|
|
{ |
129
|
47 |
|
if (empty($this->getFirstname()) && empty($this->getLastname())) { |
130
|
1 |
|
return "firstname or lastname"; |
131
|
|
|
} |
132
|
46 |
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
46 |
|
public function validatePhoneCellphoneOrEmail() |
138
|
|
|
{ |
139
|
46 |
|
if (empty($this->getPhone()) |
140
|
46 |
|
&& empty($this->getCellphone()) |
141
|
46 |
|
&& empty($this->getEmail())) { |
142
|
6 |
|
return "phone, cellphone or email"; |
143
|
|
|
} |
144
|
40 |
|
} |
145
|
|
|
|
146
|
40 |
|
public function validateContactTypeId() |
147
|
|
|
{ |
148
|
40 |
|
if (empty($this->getContactTypeId())) { |
149
|
12 |
|
return "contact_type_id"; |
150
|
|
|
} |
151
|
28 |
|
} |
152
|
|
|
|
153
|
28 |
|
public function validateBusinessTypeId() |
154
|
|
|
{ |
155
|
28 |
|
if (empty($this->getBusinessTypeId())) { |
156
|
12 |
|
return "business_type_id"; |
157
|
|
|
} |
158
|
16 |
|
} |
159
|
|
|
|
160
|
16 |
|
public function validateSuboriginId() |
161
|
|
|
{ |
162
|
16 |
|
if (empty($this->getSuboriginId())) { |
163
|
12 |
|
return "suborigin_id"; |
164
|
|
|
} |
165
|
4 |
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Set |
169
|
|
|
* |
170
|
|
|
* @param $key |
171
|
|
|
* @param string $value |
172
|
|
|
*/ |
173
|
26 |
|
private function set($key, $value = "") |
174
|
|
|
{ |
175
|
26 |
|
if (property_exists($this, $key)) { |
176
|
26 |
|
$key = implode('', array_map('ucfirst', explode('_', $key))); |
177
|
26 |
|
$this->{'set' . $key}($value); |
178
|
26 |
|
} |
179
|
26 |
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return mixed |
183
|
|
|
*/ |
184
|
48 |
|
public function getFirstname() |
185
|
|
|
{ |
186
|
48 |
|
return $this->firstname; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param $firstname |
191
|
|
|
* |
192
|
|
|
* @return $this |
193
|
|
|
*/ |
194
|
17 |
|
public function setFirstname($firstname) |
195
|
|
|
{ |
196
|
17 |
|
$this->firstname = $firstname; |
197
|
17 |
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return mixed |
202
|
|
|
*/ |
203
|
26 |
|
public function getLastname() |
204
|
|
|
{ |
205
|
26 |
|
return $this->lastname; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param $lastname |
210
|
|
|
* |
211
|
|
|
* @return $this |
212
|
|
|
*/ |
213
|
13 |
|
public function setLastname($lastname) |
214
|
|
|
{ |
215
|
13 |
|
$this->lastname = $lastname; |
216
|
13 |
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return mixed |
221
|
|
|
*/ |
222
|
47 |
|
public function getPhone() |
223
|
|
|
{ |
224
|
47 |
|
return $this->phone; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param $phone |
229
|
|
|
* |
230
|
|
|
* @return $this |
231
|
|
|
*/ |
232
|
11 |
|
public function setPhone($phone) |
233
|
|
|
{ |
234
|
11 |
|
$this->phone = $phone; |
235
|
11 |
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @return mixed |
240
|
|
|
*/ |
241
|
35 |
|
public function getCellphone() |
242
|
|
|
{ |
243
|
35 |
|
return $this->cellphone; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param $cellphone |
248
|
|
|
* |
249
|
|
|
* @return $this |
250
|
|
|
*/ |
251
|
7 |
|
public function setCellphone($cellphone) |
252
|
|
|
{ |
253
|
7 |
|
$this->cellphone = $cellphone; |
254
|
7 |
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @return mixed |
259
|
|
|
*/ |
260
|
23 |
|
public function getEmail() |
261
|
|
|
{ |
262
|
23 |
|
return $this->email; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @param $email |
267
|
|
|
* |
268
|
|
|
* @return $this |
269
|
|
|
*/ |
270
|
7 |
|
public function setEmail($email) |
271
|
|
|
{ |
272
|
7 |
|
$this->email = $email; |
273
|
7 |
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return mixed |
278
|
|
|
*/ |
279
|
41 |
|
public function getContactTypeId() |
280
|
|
|
{ |
281
|
41 |
|
return $this->contact_type_id; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param $contact_type_id |
286
|
|
|
* |
287
|
|
|
* @return $this |
288
|
|
|
*/ |
289
|
19 |
|
public function setContactTypeId($contact_type_id) |
290
|
|
|
{ |
291
|
19 |
|
$this->contact_type_id = $contact_type_id; |
292
|
19 |
|
return $this; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @return mixed |
297
|
|
|
*/ |
298
|
29 |
|
public function getBusinessTypeId() |
299
|
|
|
{ |
300
|
29 |
|
return $this->business_type_id; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @param $business_type_id |
305
|
|
|
* |
306
|
|
|
* @return $this |
307
|
|
|
*/ |
308
|
13 |
|
public function setBusinessTypeId($business_type_id) |
309
|
|
|
{ |
310
|
13 |
|
$this->business_type_id = $business_type_id; |
311
|
13 |
|
return $this; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @return mixed |
316
|
|
|
*/ |
317
|
5 |
|
public function getNotes() |
318
|
|
|
{ |
319
|
5 |
|
return $this->notes; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @param $notes |
324
|
|
|
* |
325
|
|
|
* @return $this |
326
|
|
|
*/ |
327
|
1 |
|
public function setNotes($notes) |
328
|
|
|
{ |
329
|
1 |
|
$this->notes = $notes; |
330
|
1 |
|
return $this; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @return mixed |
335
|
|
|
*/ |
336
|
5 |
|
public function getOriginId() |
337
|
|
|
{ |
338
|
5 |
|
return $this->origin_id; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @param $origin_id |
343
|
|
|
* |
344
|
|
|
* @return $this |
345
|
|
|
*/ |
346
|
1 |
|
public function setOriginId($origin_id) |
347
|
|
|
{ |
348
|
1 |
|
$this->origin_id = $origin_id; |
349
|
1 |
|
return $this; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @return mixed |
354
|
|
|
*/ |
355
|
17 |
|
public function getSuboriginId() |
356
|
|
|
{ |
357
|
17 |
|
return $this->suborigin_id; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @param $suborigin_id |
362
|
|
|
* |
363
|
|
|
* @return $this |
364
|
|
|
*/ |
365
|
7 |
|
public function setSuboriginId($suborigin_id) |
366
|
|
|
{ |
367
|
7 |
|
$this->suborigin_id = $suborigin_id; |
368
|
7 |
|
return $this; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @return mixed |
373
|
|
|
*/ |
374
|
5 |
|
public function getAssignedUser() |
375
|
|
|
{ |
376
|
5 |
|
return $this->assigned_user; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* @param $assigned_user |
381
|
|
|
* |
382
|
|
|
* @return $this |
383
|
|
|
*/ |
384
|
1 |
|
public function setAssignedUser($assigned_user) |
385
|
|
|
{ |
386
|
1 |
|
$this->assigned_user = $assigned_user; |
387
|
1 |
|
return $this; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @return mixed |
392
|
|
|
*/ |
393
|
5 |
|
public function getCarBrand() |
394
|
|
|
{ |
395
|
5 |
|
return $this->car_brand; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @param $car_brand |
400
|
|
|
* |
401
|
|
|
* @return $this |
402
|
|
|
*/ |
403
|
1 |
|
public function setCarBrand($car_brand) |
404
|
|
|
{ |
405
|
1 |
|
$this->car_brand = $car_brand; |
406
|
1 |
|
return $this; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @return mixed |
411
|
|
|
*/ |
412
|
5 |
|
public function getCarModelo() |
413
|
|
|
{ |
414
|
5 |
|
return $this->car_modelo; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* @param $car_modelo |
419
|
|
|
* |
420
|
|
|
* @return $this |
421
|
|
|
*/ |
422
|
1 |
|
public function setCarModelo($car_modelo) |
423
|
|
|
{ |
424
|
1 |
|
$this->car_modelo = $car_modelo; |
425
|
1 |
|
return $this; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* @return mixed |
430
|
|
|
*/ |
431
|
5 |
|
public function getCity() |
432
|
|
|
{ |
433
|
5 |
|
return $this->city; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* @param $city |
438
|
|
|
* |
439
|
|
|
* @return $this |
440
|
|
|
*/ |
441
|
1 |
|
public function setCity($city) |
442
|
|
|
{ |
443
|
1 |
|
$this->city = $city; |
444
|
1 |
|
return $this; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* @return mixed |
449
|
|
|
*/ |
450
|
5 |
|
public function getProvince() |
451
|
|
|
{ |
452
|
5 |
|
return $this->province; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* @param $province |
457
|
|
|
* |
458
|
|
|
* @return $this |
459
|
|
|
*/ |
460
|
1 |
|
public function setProvince($province) |
461
|
|
|
{ |
462
|
1 |
|
$this->province = $province; |
463
|
1 |
|
return $this; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @return mixed |
468
|
|
|
*/ |
469
|
5 |
|
public function getCountry() |
470
|
|
|
{ |
471
|
5 |
|
return $this->country; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* @param $country |
476
|
|
|
* |
477
|
|
|
* @return $this |
478
|
|
|
*/ |
479
|
1 |
|
public function setCountry($country) |
480
|
|
|
{ |
481
|
1 |
|
$this->country = $country; |
482
|
1 |
|
return $this; |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* @return mixed |
487
|
|
|
*/ |
488
|
5 |
|
public function getVendorName() |
489
|
|
|
{ |
490
|
5 |
|
return $this->vendor_name; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* @param $vendor_name |
495
|
|
|
* |
496
|
|
|
* @return $this |
497
|
|
|
*/ |
498
|
1 |
|
public function setVendorName($vendor_name) |
499
|
|
|
{ |
500
|
1 |
|
$this->vendor_name = $vendor_name; |
501
|
1 |
|
return $this; |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* @return mixed |
506
|
|
|
*/ |
507
|
5 |
|
public function getVendorEmail() |
508
|
|
|
{ |
509
|
5 |
|
return $this->vendor_email; |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* @param $vendor_email |
514
|
|
|
* |
515
|
|
|
* @return $this |
516
|
|
|
*/ |
517
|
1 |
|
public function setVendorEmail($vendor_email) |
518
|
|
|
{ |
519
|
1 |
|
$this->vendor_email = $vendor_email; |
520
|
1 |
|
return $this; |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* @return mixed |
525
|
|
|
*/ |
526
|
5 |
|
public function getVendorPhone() |
527
|
|
|
{ |
528
|
5 |
|
return $this->vendor_phone; |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* @param $vendor_phone |
533
|
|
|
* |
534
|
|
|
* @return $this |
535
|
|
|
*/ |
536
|
1 |
|
public function setVendorPhone($vendor_phone) |
537
|
|
|
{ |
538
|
1 |
|
$this->vendor_phone = $vendor_phone; |
539
|
1 |
|
return $this; |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* @return mixed |
544
|
|
|
*/ |
545
|
5 |
|
public function getProviderService() |
546
|
|
|
{ |
547
|
5 |
|
return $this->provider_service; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* @param $provider_service |
552
|
|
|
* |
553
|
|
|
* @return $this |
554
|
|
|
*/ |
555
|
1 |
|
public function setProviderService($provider_service) |
556
|
|
|
{ |
557
|
1 |
|
$this->provider_service = $provider_service; |
558
|
1 |
|
return $this; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* @return mixed |
563
|
|
|
*/ |
564
|
5 |
|
public function getProviderUrl() |
565
|
|
|
{ |
566
|
5 |
|
return $this->provider_url; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* @param $provider_url |
571
|
|
|
* |
572
|
|
|
* @return $this |
573
|
|
|
*/ |
574
|
1 |
|
public function setProviderUrl($provider_url) |
575
|
|
|
{ |
576
|
1 |
|
$this->provider_url = $provider_url; |
577
|
1 |
|
return $this; |
578
|
|
|
} |
579
|
|
|
} |
580
|
|
|
|