Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$participants = civicrm_api3('Participant', 'get', array(
'sequential' => 1,
'status_id' => "Registered",
'event_id' => array(
'IN' => $event_ids
),
// Get price set info if available in line below
'api.LineItem.get' => array('entity_table' => "civicrm_participant", 'entity_id' => "\$value.participant_id")
)) ['values'];
/*
Events can use price sets to allow for 1 reg to have mult attendees.
To account for this, we can check if a multi-registrant price set is being
used, and if so we use that number for overall attendee count instead
of just counting the number of registrations
Example when price set not used:
participant["api.LineItem.get"] = {
"is_error": 0,
"version": 3,
"count": 0,
"values": []
}
Example when price set is used:
participant["api.LineItem.get"] = {
"is_error": 0,
"version": 3,
"count": 1,
"id": 325,
"values": [
{
"id": "325",
"entity_table": "civicrm_participant",
"entity_id": "30",
"contribution_id": "324",
"price_field_id": "9",
"label": "2",
"qty": "1.00",
"unit_price": "0.00",
"line_total": "0.00",
"participant_count": "2",
"price_field_value_id": "18",
"financial_type_id": "4",
"deductible_amount": "0.00"
}
]
}
*/
foreach ($participants as $key=>$p) {
if ($p["api.LineItem.get"]["count"]) {
$participants[$key]['participant_count']=$p["api.LineItem.get"]["values"][0]["participant_count"];
} else {
$participants[$key]['participant_count']=1;
}
}
foreach($participants as $participant) {
$total_count+=$participant['participant_count'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.