This repository was archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathContact.php
More file actions
executable file
·257 lines (215 loc) · 6.3 KB
/
Contact.php
File metadata and controls
executable file
·257 lines (215 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
namespace Ctct\Components\Contacts;
use Ctct\Components\Component;
/**
* Represents a single Contact in Constant Contact
*
* @package Components
* @subpackage Contacts
* @author Constant Contact
*/
class Contact extends Component {
/**
* Unique identifier for the contact
* @var string
*/
public $id;
/**
* Status of the contact, must be one of "ACTIVE", "UNCONFIRMED", "OPTOUT", "REMOVED", "NON_SUBSCRIBER", "VISITOR"
* @var string
*/
public $status;
/**
* First name of the contact
* @var string
*/
public $first_name;
/**
* Last name of the contact
* @var string
*/
public $last_name;
/**
* Whether or not the contact is confirmed
* @var boolean
*/
public $confirmed;
/**
* Contact source information
* @var string
*/
public $source;
/**
* Contact source information
* @var string
*/
public $create_source;
/**
* Email address associated with this contact
* @var EmailAddress
*/
public $email_address;
/**
* The prefix name of the contact
* @var string
*/
public $prefix_name;
/**
* The job title of the contact
* @var string
*/
public $job_title;
/**
* Array of addresses associated with this contact
* @var Address[]
*/
public $addresses = array();
/**
* Array of notes associated with this contact
* @var Note[]
*/
public $notes = array();
/**
* Company name this contact works for
* @var string
*/
public $company_name;
/**
* Contact's home phone number
* @var string
*/
public $home_phone;
/**
* Contact's work phone number
* @var string
*/
public $work_phone;
/**
* Contact's cell phone number
* @var string
*/
public $cell_phone;
/**
* Contact's fax number
* @var string
*/
public $fax;
/**
* Array of custom fields associated with this contact
* @var CustomField[]
*/
public $custom_fields = array();
/**
* Array of contact lists this contact belongs to
* @var ContactList[]
*/
public $lists = array();
/**
* Array of contact lists IDs this contact belongs to
* @var []
*/
public $list_memberships = array();
/**
* Date the contact was created
* @var string
*/
public $created_date;
/**
* Date the contact was last modified
* @var string
*/
public $modified_date;
/**
* Contact source details
* @var string
*/
public $source_details;
/**
* Factory method to create a Contact object from an array
* @param array $props - Associative array of initial properties to set
* @return Contact
*/
public static function create(array $props) {
$contact = new Contact();
$contact->id = parent::getValue($props, "id");
$contact->status = parent::getValue($props, "status");
$contact->first_name = parent::getValue($props, "first_name");
$contact->last_name = parent::getValue($props, "last_name");
$contact->confirmed = parent::getValue($props, "confirmed");
$contact->source = parent::getValue($props, "source");
$contact->create_source = parent::getValue($props, "create_source");
$contact->list_memberships = parent::getValue($props, "list_memberships");
if (isset($props['email_address'])) {
$contact->email_address = EmailAddress::create(parent::getValue($props, "email_address"));
}
$contact->prefix_name = parent::getValue($props, "prefix_name");
$contact->job_title = parent::getValue($props, "job_title");
if (isset($props['addresses'])) {
foreach ($props['addresses'] as $address) {
$contact->addresses[] = Address::create($address);
}
}
if (isset($props['notes'])) {
foreach ($props['notes'] as $note) {
$contact->notes[] = Note::create($note);
}
}
$contact->company_name = parent::getValue($props, "company_name");
$contact->home_phone = parent::getValue($props, "home_phone");
$contact->work_phone = parent::getValue($props, "work_phone");
$contact->cell_phone = parent::getValue($props, "cell_phone");
$contact->fax = parent::getValue($props, "fax");
if (isset($props['custom_fields'])) {
foreach ($props['custom_fields'] as $custom_field) {
$contact->custom_fields[] = CustomField::create($custom_field);
}
}
if (isset($props['lists'])) {
foreach ($props['lists'] as $contact_list) {
$contact->lists[] = ContactList::create($contact_list);
}
}
$contact->created_date = parent::getValue($props, "created_date");
$contact->modified_date = parent::getValue($props, "modified_date");
$contact->source_details = parent::getValue($props, "source_details");
return $contact;
}
/**
* Add a ContactList
* @param mixed $contactList - ContactList object or contact list id
*/
public function addList($contactList) {
if (!$contactList instanceof ContactList) {
$contactList = new ContactList($contactList);
}
$this->lists[] = $contactList;
}
/**
* Add an EmailAddress
* @param mixed $emailAddress - EmailAddress object or email address
*/
public function addEmail($emailAddress) {
if (!$emailAddress instanceof EmailAddress) {
$emailAddress = new EmailAddress($emailAddress);
}
$this->email_addresses[] = $emailAddress;
}
/**
* Add a custom field to the contact object
* @param CustomField $customField - custom field to add to the contact
*/
public function addCustomField(CustomField $customField) {
$this->custom_fields[] = $customField;
}
/**
* Add an address
* @param Address $address - Address to add
*/
public function addAddress(Address $address) {
$this->addresses[] = $address;
}
public function toJson() {
unset($this->last_update_date);
return json_encode($this);
}
}