Retrieving individual activity attendance report

Okay, today’s tutorial will be a one off that builds upon last week’s tutorial of retrieving a list of group participants.

We won’t integrate today’s tutorial with last weeks tutorial, but hang in there. Next week is coming and so is integration.

For now, we’ll focus on creating an activity attendance report for one individual and will contain ALL events attended and checked into by that person.

What type of events are we referencing in this attendance report? Specifically, we’re focusing on whether or not a person attended a community group. Let’s get started.

Go ahead and crack open the text editor of your choice. If you have no clue as to what I’m talking about, then visit Getting Started to catch up with the times.

Defining the Variables

With the text editor open, create and save a file named individual-attendance.php. As with previous tutorials, be sure to add the appropriate header comments and include config files.

We’re ready to define the variables for the CCB API service and the person’s id we’re going to retrieve an activity attendance report for.

Define the apiService variable, setting the value of the variable to individual_attendance.

Next, it’s time to define the personID variable. To do this, you’ll need to login to your church’s CCB account and search for a person to retrieve their individual_id.

Login to your CCB account, and select People from the left hand menu as shown below.


CCB People Search


In this example, I’ll search for my own individual profile and you can search for yours or another person’s profile. Now that the individual profile has been searched and found, review the url address in the web browser’s address bar (see image below).


CCB Person Search


Find and identify the number that follows individual_id and there should be a number. In our example, the individual’s id that follows individual_id is equal to 44. Next, create a personID variable and define the value equal to the respective individual’s id.

Binding Labels and Data to Make API Call

This next step is imperative to successfully make a CCB API call to retrieve an individual’s activity attendance report.

For the apiService and personID variables previously created, we’ll now create an array of binded service API labels and variables that’ll be passed as an argument to the ccbDetails function to retrieve an individual’s activity attendance report.

Create the urlData variable and assign it the appropriate service labels binded to their respective apiService and personID variable.

Next, create the rss variable, assigning it the ccbDetails function with get as the first argument and urlData as the second argument. ccbDetails function returns a XML response that you’ll use XPATH query to parse.

As for the XPATH query expression to parse the XML response, we’ll use the following: //attendances/attendance.

Now create a nodes variable and assign it the rss variable that references the XPATH query.

To ensure we have no other data assigned and that we start from a clear variable, define the response_object variable as shown in the code below just before the foreach statement.

Looping or Iterating Through Attendance Activity Data

Now we’re ready to create the foreach statement to iterate through each nodes variable array response, which contains list participants with their respective data.

Within the foreach statement, we’ll define a pageString variable and assign it the attendance event. The attendance event name will be searched and return only the events where the phrases ‘Group’, ‘Gathering’, and ‘Community’ are included.

For this functionality, we’ll use a PHP if statement in conjunction with PHP strpos methods. In short, the logic reads if the event name includes ‘Group’ or ‘Gathering’ AND not ‘IF’ or ‘Community’, then we list the activity attendance for individual.

I only included “not ‘IF'” due to the fact that our church had a group named IF:Gathering that was not a Community Group.  Nevertheless, the phrases could be used for groups, events or any type of check in activities.

As shown and defined with the response_object variable, this activity attendance lists the event name, event group and date or occurrence of event concatenated as a string. Oh and don’t forget to use the .= operator to concatenate each attendance data when defining the response_object variable.

Finally, once all nodes have been traversed, then we echo the response_object variable to the web browser for display.


Time to Test Activity Attendance Report

You know the drill. It’s time to save the individual-attendance.php file and open it using your web browser. And there you have it. You should now be able to view an activity attendance report for a single individual.

Next up, we’ll show you how to combine this week’s tutorial with the one from last so you can create an automated activity attendance report for groups. That’s it for now. See you here next week, same bat time and channel.

Please comment if this tutorial has helped you.