private function location_create($mode = 'import') { $this->import_status_update('location'); $x = 0; foreach ($this->contacts as $contact_id => $column_field_array) { $location_param = array('version' => '3.0', 'contact_id' => $contact_id); if (isset($this->location_data['phone_home'])) { foreach ($this->location_data['phone_home'] as $column_matched => $field) { $this->phone_create($field, $contact_id, 'Home', 1); } } if (isset($this->location_data['phone_work'])) { foreach ($this->location_data['phone_work'] as $column_matched => $field) { $this->phone_create($field, $contact_id, 'Work'); } } if (isset($this->location_data['phone_other'])) { foreach ($this->location_data['phone_other'] as $column_matched => $field) { $this->phone_create($field, $contact_id, 'Other'); } } if (isset($this->location_data['address_home'])) { $address_home['location_type'] = 'Home'; foreach ($this->location_data['address_home'] as $column_matched => $field) { $address_home[$field] = $column_field_array[$column_matched]; } $address_home['version'] = '3'; $address_home['location_type_id'] = 1; $address_home['contact_id'] = $contact_id; $address_home['is_primary'] = 1; } if (isset($this->location_data['address_billing'])) { $address_billing['location_type'] = 'Billing'; foreach ($this->location_data['address_billing'] as $column_matched => $field) { $address_billing[$field] = $column_field_array[$column_matched]; } } // Location API requires 1 to 1 address calls so we have to determine if // The import has a Home or Billing address or both and generate either // one of 2 Location API calls. $home_address_only = isset($this->location_data['address_home']) && !isset($this->location_data['address_billing']) ? TRUE : FALSE; $billing_address_only = isset($this->location_data['address_billing']) && !isset($this->location_data['address_home']) ? TRUE : FALSE; $both_address = isset($this->location_data['address_home']) && isset($this->location_data['address_billing']) ? TRUE : FALSE; if ($home_address_only) { $address_billing['location_type_id'] = 1; $address_billing['is_primary'] = 1; $location_param['address'] = array(1 => $address_home); } if ($billing_address_only) { $address_billing['location_type_id'] = 5; $address_billing['is_primary'] = 1; $location_param['address'] = array(1 => $address_billing); } if ($both_address) { $location_param1 = array('version' => '3.0', 'contact_id' => $contact_id, 'address' => array(1 => $address_home)); // set address of the outside call to the billing address $location_param['address'] = array(1 => $address_billing); if ($mode == 'import') { $location_result1 = civicrm_location_add($location_param1); } else { $location_result1 = civicrm_location_update($location_param1); } if ($location_result1['is_error'] == 1) { $this->log->_log('Error (Location API Call) on ContactID: ' . $contact_id . ': ' . $location_result1['error_message'], 'error'); } else { $x++; } } $location_param['phone'] = $phone_param; // unset the params so they don't get built up as we go through the array unset($phone_param, $address_home, $address_billing); if ($mode == 'import') { $location_result2 = civicrm_location_add($location_param); } else { $location_result2 = civicrm_location_update($location_param); } if ($location_result2['is_error'] == 1) { $this->log->_log('Error (Location API Call) on ContactID: ' . $contact_id . ': ' . $location_result2['error_message'], 'error'); } else { $this->location_imported++; // record the number of location data imported if ($this->location_imported % 100 == 0) { $this->update_count('location'); } } } $this->update_count('location'); $this->log->_log($x . ' number of location data (A) imported.'); // from ' . count($this->contacts) . ' number of created contacts'); $this->log->_log($this->location_imported . ' number of location data (B) imported.'); // from ' . count($this->contacts) . ' number of created contacts'); }
function testLocationUpdate() { $location = $this->locationAdd($this->_contactID); $workPhone = array('phone' => '02327276048', 'phone_type' => 'Phone'); $phones = array($workPhone); $workEmailFirst = array('email' => '*****@*****.**'); $workEmailSecond = array('email' => '*****@*****.**'); $emails = array($workEmailFirst, $workEmailSecond); $params = array('phone' => $phones, 'city' => 'Mumbai', 'email' => $emails, 'contact_id' => $this->_contactID, 'location_type_id' => $location['result']['location_type_id']); $locationUpdate =& civicrm_location_update($params); $this->assertEquals($locationUpdate['is_error'], 0); }