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 to add a Location * * @return int location id of created location */ function locationAdd($contactID) { $params = array('contact_id' => $contactID, 'location_type' => 'New Location Type', 'is_primary' => 1, 'name' => 'Saint Helier St', 'county' => 'Marin', 'country' => 'United States', 'state_province' => 'Michigan', 'supplemental_address_1' => 'Hallmark Ct', 'supplemental_address_2' => 'Jersey Village'); require_once 'api/v2/Location.php'; $result = civicrm_location_add($params); if (civicrm_error($result)) { throw new Exception('Could not create location', $result); } return $result; }
function testAddWithAddressEmail() { $workPhone = array('phone' => '91-20-276048', 'phone_type_id' => 1, 'is_primary' => 1); $workFax = array('phone' => '91-20-234-657686', 'phone_type_id' => 3); $phone = array($workPhone, $workFax); $workIMFirst = array('name' => 'Hi', 'provider_id' => '1', 'is_primary' => 0); $workIMSecond = array('name' => 'Hola', 'provider_id' => '3', 'is_primary' => 0); $workIMThird = array('name' => 'Welcome', 'provider_id' => '5', 'is_primary' => 1); $im = array($workIMFirst, $workIMSecond, $workIMThird); $workEmailFirst = array('email' => '*****@*****.**', 'on_hold' => 1); $workEmailSecond = array('email' => '*****@*****.**', 'is_bulkmail' => 1); $workEmailThird = array('email' => '*****@*****.**'); $email = array($workEmailFirst, $workEmailSecond, $workEmailThird); $params = array('contact_id' => $this->_contactID, 'location_type' => 'New Location Type', 'phone' => $phone, 'city' => 'San Francisco', 'state_province' => 'California', 'country_id' => 1228, 'street_address' => '123, FC Road', 'supplemental_address_1' => 'Near Wenna Lake', 'is_primary' => 1, 'im' => $im, 'email' => $email); $location =& civicrm_location_add($params); $match = array(); $match['address'][0] = array('contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, 'city' => 'San Francisco', 'state_province_id' => 1004, 'country_id' => 1228, 'street_address' => '123, FC Road', 'supplemental_address_1' => 'Near Wenna Lake', 'is_primary' => 1); $match['email'][0] = array('is_primary' => 1, 'email' => '*****@*****.**', 'on_hold' => 1); $match['email'][1] = array('is_primary' => 0, 'email' => '*****@*****.**', 'is_primary' => 0); $match['email'][2] = array('contact_id' => $this->_contactID, 'is_primary' => 0, 'email' => '*****@*****.**'); $match['phone'][0] = array('is_primary' => 1, 'phone' => '91-20-276048', 'phone_type_id' => 1, 'location_type_id' => $this->_locationType->id, 'contact_id' => $this->_contactID); $match['phone'][1] = array('is_primary' => 0, 'phone_type_id' => 3, 'phone' => '91-20-234-657686'); $match['im'][0] = array('name' => 'Hi', 'is_primary' => 0, 'provider_id' => 1, 'location_type_id' => $this->_locationType->id); $match['im'][1] = array('name' => 'Hola', 'is_primary' => 0, 'provider_id' => 3); $match['im'][2] = array('name' => 'Welcome', 'is_primary' => 1, 'provider_id' => 5, 'contact_id' => $this->_contactID); $this->_checkResult($location['result'], $match); }
function civicrm_location_create($params) { $result = civicrm_location_add($params); return $result; }