You are here

function _civicrm_entity_contact_assign_rel_contact_field_remove_contact_relationship in CiviCRM Entity 7.2

Helper function, set a relationship to inactive and set end date to "now"

Parameters

$contact_a_id:

$contact_b_id:

$relationship_type_id:

1 call to _civicrm_entity_contact_assign_rel_contact_field_remove_contact_relationship()
_civicrm_entity_contact_assign_rel_contact_field_process_field_items in modules/civicrm_entity_contact_assign_rel_contact_field/civicrm_entity_contact_assign_rel_contact_field.module
Helper function to process field items on entity insert or update

File

modules/civicrm_entity_contact_assign_rel_contact_field/civicrm_entity_contact_assign_rel_contact_field.module, line 685
Provide CiviCRM Entity Contact Assign Relationship Contacts List Field Type. Provides a widget for adding/removing a contacts relationships to a list of contacts.

Code

function _civicrm_entity_contact_assign_rel_contact_field_remove_contact_relationship($contact_a_id, $contact_b_id, $relationship_type_id) {
  civicrm_initialize();
  try {
    $end_date = date('Y-m-d');
    $relationship_result = civicrm_api3('Relationship', 'get', array(
      'relationship_type_id' => $relationship_type_id,
      'contact_id_a' => $contact_a_id,
      'contact_id_b' => $contact_b_id,
    ));
    if ($relationship_result['count']) {
      $params = array(
        'id' => $relationship_result['id'],
        'contact_id_a' => $contact_a_id,
        'contact_id_b' => $contact_b_id,
        'relationship_type_id' => $relationship_type_id,
        'is_active' => 0,
        'end_date' => $end_date,
      );
    }
    $result = civicrm_api3('Relationship', 'create', $params);
  } catch (CiviCRM_API3_Exception $e) {
  }
}