Retrieving the total attendance for multiple events using CCB’s API.

Today, I’m back with a simple tutorial that expounds upon on a previous tutorial: Retrieving the total attendance for a specific event using CCB’s API.

We’ve successfully mastered retrieving total attendance for a specific event, but what if I have more than one event?

Of course, the straightforward answer would be to repeat the same call until you’ve retrieved all events.

And although it is one way of answering the question, it’s quite expensive to make so many calls.

If you’re a church with a hand full or not many events, then it may make sense to perform such these calls.

However, if you’re a church with more than 10 events, then today’s tutorial will show you how to get all events and their respective total attendance.

I won’t go into the nitty-gritty details of the inner works. Feel free to read the previous tutorial.

Minor changes made to this tutorial is the use of the following:

  • Use of attendance_profiles instead of attendance_profile
  • Required start and end dates when making CCB API call
  • Use of //events/event as the XPATH query expression

Again, it would be quite expensive to execute this script without the dates. That stated, be mindful not to execute this script with start dates dating back to the first event ever entered into CCB.

In most cases, I would imagine that you’re likely going to use this script to report weekly, monthly and quarterly total attendance for each event occurrence.

With a bit of elbow grease, one could modify this script to use dropdowns displaying a list of events and another displaying date range. And don’t forget to add in some filters or auto complete search for events.

You achieve the aforementioned ideas and you’ll be well on your way to a reporting engine, and answering the questions of how many attendees an event had registered or how many spaces remain available for an event.

That’s it for today’s tutorial. Drop me a comment or question below should you have any ideas or encounter any challenges.

<?PHP

// contains resusable globals and functions
include("includes/config.php");

$apiService = 'attendance_profiles'; // CCB api service

// set the dates using the following format: YYYY-MM-DD (2017-01-27)
$eventStartDate = '2017-01-15';
$eventEndDate = '2017-01-31';

$urlData = array_filter( array(
	'srv' => "$apiService",
	'start_date' => "$eventStartDate",
	'end_date' => "$eventEndDate"
	) );

$rss = ccbDetails('get',$urlData); // transform to XML

$nodes = $rss->xpath('//events/event');  // xpath for events->event

$response_object = '';

foreach ($nodes as $node)
{
	$response_object .= $node->name.' ('.$node->occurrence.'): '.sizeof($node->attendees->attendee).'<br>';
}

echo $response_object;

?>

 

Related Posts

Subscribe and receive the following...

  • Inside CCB tips and tricks
  • Instant CCB tutorial alerts and updates
  • CCB How To's, Videos, Webinars and more...