You are here

function civicrm_entity_contact_is_in_group in CiviCRM Entity 7.2

Condition Contact is in Group

File

./civicrm_entity.module, line 2890

Code

function civicrm_entity_contact_is_in_group($contact, $group_id) {
  if (!civicrm_initialize()) {
    return;
  }
  try {
    $contact_id = $contact->id;
    $params = array(
      'sequential' => 1,
      'contact_id' => $contact_id,
      'group_id' => $group_id,
    );
    $get_result = civicrm_api3('GroupContact', 'Get', $params);
    if (!empty($get_result['count'])) {
      $group = entity_load_single('civicrm_group', $group_id);
      return $group;
    }
  } catch (CiviCRM_API3_Exception $e) {
    drupal_set_message($e
      ->getMessage());
  }
  return FALSE;
}