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