1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LPTracker\models; |
4
|
|
|
|
5
|
|
|
use LPTracker\exceptions\LPTrackerSDKException; |
6
|
|
|
|
7
|
|
|
class ContactDetail extends Model |
8
|
|
|
{ |
9
|
|
|
const TYPE_PHONE = 'phone'; |
10
|
|
|
const TYPE_EMAIL = 'email'; |
11
|
|
|
const TYPE_SKYPE = 'skype'; |
12
|
|
|
const TYPE_ICQ = 'icq'; |
13
|
|
|
const TYPE_FACEBOOK = 'facebook'; |
14
|
|
|
const TYPE_VK = 'vk'; |
15
|
|
|
const TYPE_TELEGRAM = 'telegram'; |
16
|
|
|
const TYPE_VIBER = 'viber'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var integer |
20
|
|
|
*/ |
21
|
|
|
protected $id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var integer |
25
|
|
|
*/ |
26
|
|
|
protected $contactId; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $type; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $data; |
37
|
|
|
|
38
|
|
|
public function __construct(array $detailData = []) |
39
|
|
|
{ |
40
|
|
|
if (isset($detailData['id'])) { |
41
|
|
|
$this->id = $detailData['id']; |
42
|
|
|
} |
43
|
|
|
if (isset($detailData['contact_id'])) { |
44
|
|
|
$this->contactId = $detailData['contact_id']; |
45
|
|
|
} |
46
|
|
|
if (isset($detailData['type'])) { |
47
|
|
|
$this->type = $detailData['type']; |
48
|
|
|
} |
49
|
|
|
if (isset($detailData['data'])) { |
50
|
|
|
$this->data = $detailData['data']; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public static function getAllTypes() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
self::TYPE_PHONE, |
61
|
|
|
self::TYPE_EMAIL, |
62
|
|
|
self::TYPE_SKYPE, |
63
|
|
|
self::TYPE_ICQ, |
64
|
|
|
self::TYPE_FACEBOOK, |
65
|
|
|
self::TYPE_VK, |
66
|
|
|
self::TYPE_TELEGRAM, |
67
|
|
|
self::TYPE_VIBER, |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return bool |
73
|
|
|
* @throws LPTrackerSDKException |
74
|
|
|
*/ |
75
|
|
|
public function validate() |
76
|
|
|
{ |
77
|
|
|
if (empty($this->type)) { |
78
|
|
|
throw new LPTrackerSDKException('Detail type can not be null: ' . $this->__toString()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (!in_array($this->type, self::getAllTypes(), true)) { |
82
|
|
|
throw new LPTrackerSDKException('Detail type not in (' . implode(',', self::getAllTypes()) . '): ' . $this->__toString()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (empty($this->data)) { |
86
|
|
|
throw new LPTrackerSDKException('Detail data can not be null: ' . $this->__toString()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function toArray() |
96
|
|
|
{ |
97
|
|
|
$result = [ |
98
|
|
|
'type' => $this->type, |
99
|
|
|
'data' => $this->data, |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
if (!empty($this->id)) { |
103
|
|
|
$result['id'] = $this->getId(); |
104
|
|
|
} |
105
|
|
|
return $result; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return int |
110
|
|
|
*/ |
111
|
|
|
public function getId() |
112
|
|
|
{ |
113
|
|
|
return $this->id; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
|
|
public function getContactId() |
120
|
|
|
{ |
121
|
|
|
return $this->contactId; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getType() |
128
|
|
|
{ |
129
|
|
|
return $this->type; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $type |
134
|
|
|
* @return $this |
135
|
|
|
*/ |
136
|
|
|
public function setType($type) |
137
|
|
|
{ |
138
|
|
|
$this->type = $type; |
139
|
|
|
|
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getData() |
147
|
|
|
{ |
148
|
|
|
return $this->data; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string $data |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
|
public function setData($data) |
156
|
|
|
{ |
157
|
|
|
$this->data = $data; |
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|