Esempio n. 1
0
 /**
  * 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->middle_name = parent::getValue($props, "middle_name");
     $contact->last_name = parent::getValue($props, "last_name");
     $contact->confirmed = parent::getValue($props, "confirmed");
     $contact->source = parent::getValue($props, "source");
     if (isset($props['email_addresses'])) {
         foreach ($props['email_addresses'] as $email_address) {
             $contact->email_addresses[] = EmailAddress::create($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;
 }
 function set($key, $value)
 {
     if (!$this->is_editable(strtolower($key), false)) {
         return false;
     }
     switch (strtolower($key)) {
         case 'email_addresses':
             $this->email_addresses[0]->email_address = $value;
             break;
         case 'notes':
             // Ctct got rid of notes for now.
             if (isset($this->notes[0]) && is_object($this->notes[0])) {
                 $this->notes[0]->note = $value;
             } else {
                 $this->addNote($value);
             }
             break;
         case preg_match('/^personal_/ism', $key) ? true : false:
             $key = strtolower(str_ireplace('personal_', '', $key));
             $this->addresses[0]->{$key} = $value;
             break;
         case preg_match('/^business_/ism', $key) ? true : false:
             $key = strtolower(str_ireplace('business_', '', $key));
             $this->addresses[1]->{$key} = $value;
             break;
         case preg_match('/^customfield([0-9]+)/ism', $key, $matches) ? true : false:
             // First, check whether it already exists.
             foreach ((array) $this->custom_fields as $customfield) {
                 if (strtolower($customfield->name) === strtolower($key)) {
                     $customfield->value = $value;
                     return true;
                 }
             }
             $this->custom_fields = (array) $this->custom_fields;
             // Otherwise, create it.
             $this->custom_fields[] = CustomField::create(array('name' => 'CustomField' . $matches[1], 'value' => $value));
             break;
         default:
             $this->{$key} = $value;
             break;
     }
     return true;
 }