Overview

Namespaces

  • Ctct
    • Auth
    • Components
      • Account
      • Activities
      • Contacts
      • EmailMarketing
      • Tracking
    • Exceptions
    • Services
  • PHP

Classes

  • Address
  • Contact
  • ContactList
  • CustomField
  • EmailAddress
  • Note
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: namespace Ctct\Components\Contacts;
  3:  
  4: use Ctct\Components\Component;
  5: use Ctct\Util\Config;
  6: 
  7: /**
  8:  * Represents a single Contact in Constant Contact
  9:  *
 10:  * @package     Components
 11:  * @subpackage     Contacts
 12:  * @author         Constant Contact
 13:  */
 14: class Contact extends Component
 15: {
 16: 
 17:     /**
 18:      * Unique identifier for the contact
 19:      * @var string
 20:      */
 21:     public $id;
 22: 
 23:     /**
 24:      * Status of the contact, must be one of "ACTIVE", "UNCONFIRMED", "OPTOUT", "REMOVED", "NON_SUBSCRIBER", "VISITOR"
 25:      * @var string
 26:      */
 27:     public $status;
 28: 
 29:     /**
 30:      * First name of the contact
 31:      * @var string
 32:      */
 33:     public $first_name;
 34: 
 35:     /**
 36:      * Middle name of the contact
 37:      * @var string
 38:      */
 39:     public $middle_name;
 40: 
 41:     /**
 42:      * Last name of the contact
 43:      * @var string
 44:      */
 45:     public $last_name;
 46: 
 47:     /**
 48:      * Whether or not the contact is confirmed
 49:      * @var boolean
 50:      */
 51:     public $confirmed;
 52: 
 53:     /**
 54:      * Contact source information
 55:      * @var string
 56:      */
 57:     public $source;
 58: 
 59:     /**
 60:      * Array of email addresses associated with this contact
 61:      * @var array
 62:      */
 63:     public $email_addresses = array();
 64: 
 65:     /**
 66:      * The prefix name of the contact
 67:      * @var string
 68:      */
 69:     public $prefix_name;
 70: 
 71:     /**
 72:      * The job title of the contact
 73:      * @var string
 74:      */
 75:     public $job_title;
 76: 
 77:     /**
 78:      * Array of addresses associated with this contact
 79:      * @var array
 80:      */
 81:     public $addresses = array();
 82: 
 83:     /**
 84:      * Array of notes associated with this contact
 85:      * @var array
 86:      */
 87:     public $notes = array();
 88: 
 89:     /**
 90:      * Company name this contact works for
 91:      * @var string
 92:      */
 93:     public $company_name;
 94: 
 95:     /**
 96:      * Contact's home phone number
 97:      * @var string
 98:      */
 99:     public $home_phone;
100: 
101:     /**
102:      * Contact's work phone number
103:      * @var string
104:      */
105:     public $work_phone;
106: 
107:     /**
108:      * Contact's cell phone number
109:      * @var string
110:      */
111:     public $cell_phone;
112: 
113:     /**
114:      * Contact's fax number
115:      * @var string
116:      */
117:     public $fax;
118: 
119:     /**
120:      * Array of custom fields associated with this contact
121:      * @var array
122:      */
123:     public $custom_fields = array();
124: 
125:     /**
126:      * Array of contact lists this contact belongs to
127:      * @var array
128:      */
129:     public $lists = array();
130: 
131:     /**
132:      * Contact source details
133:      * @var string
134:      */
135:     public $source_details;
136: 
137:     /**
138:      * Factory method to create a Contact object from an array
139:      * @param array $props - Associative array of initial properties to set
140:      * @return Contact
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:      * Add a ContactList
189:      * @param mixed $contactList - ContactList object or contact list id
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:      * Add an EmailAddress
202:      * @param mixed $emailAddress - EmailAddress object or email address
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:      * Add a custom field to the contact object
215:      * @param CustomField $customField - custom field to add to the contact
216:      */
217:     public function addCustomField(CustomField $customField)
218:     {
219:         $this->custom_fields[] = $customField;
220:     }
221:     
222:     /**
223:      * Add an address
224:      * @param Address $address - Address to add
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: 
Appconnect PHP SDK API documentation generated by ApiGen 2.8.0