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