You are here

function _civicrm_entity_price_set_field_get_participant_count_for_event in CiviCRM Entity 7.2

Function to query number of participants for an event, with optional contact_id

Parameters

$event_id:

int $contact_id:

Return value

int

3 calls to _civicrm_entity_price_set_field_get_participant_count_for_event()
civicrm_entity_price_set_field_display_form_event in modules/civicrm_entity_price_set_field/includes/civicrm_entity_price_set_field.event_registration.inc
Form callback for event registration form
civicrm_entity_price_set_field_display_form_event_submit in modules/civicrm_entity_price_set_field/includes/civicrm_entity_price_set_field.event_registration.inc
Submit handler for event registration form 'Register' button
_civicrm_entity_price_set_field_setup_event_registration_form_fapi in modules/civicrm_entity_price_set_field/includes/civicrm_entity_price_set_field.event_registration.inc
Helper function to setup event registration form FAPI

File

modules/civicrm_entity_price_set_field/includes/civicrm_entity_price_set_field.event_registration.inc, line 1147
CiviCRM Entity Price Set Field, Form display formatter, event registration

Code

function _civicrm_entity_price_set_field_get_participant_count_for_event($event_id, $contact_id = 0) {
  if (!empty($event_id) && is_numeric($event_id)) {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'civicrm_participant')
      ->propertyCondition('event_id', $event_id);
    if (!empty($contact_id) && is_numeric($contact_id)) {
      $query
        ->propertyCondition('contact_id', $contact_id);
    }
    $results = $query
      ->execute();
    if (!empty($results['civicrm_participant'])) {
      return count($results['civicrm_participant']);
    }
  }
  return 0;
}