1: <?php
2: namespace Ctct\Components\Contacts;
3:
4: use Ctct\Components\Component;
5: use Ctct\Util\Config;
6:
7: 8: 9: 10: 11: 12: 13:
14: class Contact extends Component
15: {
16:
17: 18: 19: 20:
21: public $id;
22:
23: 24: 25: 26:
27: public $status;
28:
29: 30: 31: 32:
33: public $first_name;
34:
35: 36: 37: 38:
39: public $middle_name;
40:
41: 42: 43: 44:
45: public $last_name;
46:
47: 48: 49: 50:
51: public $confirmed;
52:
53: 54: 55: 56:
57: public $source;
58:
59: 60: 61: 62:
63: public $email_addresses = array();
64:
65: 66: 67: 68:
69: public $prefix_name;
70:
71: 72: 73: 74:
75: public $job_title;
76:
77: 78: 79: 80:
81: public $addresses = array();
82:
83: 84: 85: 86:
87: public $notes = array();
88:
89: 90: 91: 92:
93: public $company_name;
94:
95: 96: 97: 98:
99: public $home_phone;
100:
101: 102: 103: 104:
105: public $work_phone;
106:
107: 108: 109: 110:
111: public $cell_phone;
112:
113: 114: 115: 116:
117: public $fax;
118:
119: 120: 121: 122:
123: public $custom_fields = array();
124:
125: 126: 127: 128:
129: public $lists = array();
130:
131: 132: 133: 134:
135: public $source_details;
136:
137: 138: 139: 140: 141:
142: public static function create(array $props)
143: {
144: $contact = new Contact();
145: $contact->id = parent::getValue($props, "id");
146: $contact->status = parent::getValue($props, "status");
147: $contact->first_name = parent::getValue($props, "first_name");
148: $contact->middle_name = parent::getValue($props, "middle_name");
149: $contact->last_name = parent::getValue($props, "last_name");
150: $contact->confirmed = parent::getValue($props, "confirmed");
151: $contact->source = parent::getValue($props, "source");
152:
153: foreach ($props['email_addresses'] as $email_address) {
154: $contact->email_addresses[] = EmailAddress::create($email_address);
155: }
156:
157: $contact->prefix_name = parent::getValue($props, "prefix_name");
158: $contact->job_title = parent::getValue($props, "job_title");
159:
160: foreach ($props['addresses'] as $address) {
161: $contact->addresses[] = Address::create($address);
162: }
163:
164: foreach ($props['notes'] as $note) {
165: $contact->notes[] = Note::create($note);
166: }
167:
168: $contact->company_name = parent::getValue($props, "company_name");
169: $contact->home_phone = parent::getValue($props, "home_phone");
170: $contact->work_phone = parent::getValue($props, "work_phone");
171: $contact->cell_phone = parent::getValue($props, "cell_phone");
172: $contact->fax = parent::getValue($props, "fax");
173:
174: foreach ($props['custom_fields'] as $custom_field) {
175: $contact->custom_fields[] = CustomField::create($custom_field);
176: }
177:
178: foreach ($props['lists'] as $contact_list) {
179: $contact->lists[] = ContactList::create($contact_list);
180: }
181:
182: $contact->source_details = parent::getValue($props, "source_details");
183:
184: return $contact;
185: }
186:
187: 188: 189: 190:
191: public function addList($contactList)
192: {
193: if (!$contactList instanceof ContactList) {
194: $contactList = new ContactList($contactList);
195: }
196:
197: $this->lists[] = $contactList;
198: }
199:
200: 201: 202: 203:
204: public function addEmail($emailAddress)
205: {
206: if (! $emailAddress instanceof EmailAddress) {
207: $emailAddress = new EmailAddress($emailAddress);
208: }
209:
210: $this->email_addresses[] = $emailAddress;
211: }
212:
213: 214: 215: 216:
217: public function addCustomField(CustomField $customField)
218: {
219: $this->custom_fields[] = $customField;
220: }
221:
222: 223: 224: 225:
226: public function addAddress(Address $address)
227: {
228: $this->addresses[] = $address;
229: }
230:
231: public function toJson()
232: {
233: unset($this->last_update_date);
234: return json_encode($this);
235: }
236: }
237: