Last Families Modified Report and Dashboard

Welcome back to this week’s tutorial where we’ll cover the last families modified report.

If you’re a growing church with a large number of families joining the fold, then this is likely the tutorial you’ll want to implement.

Today’s tutorial will allow you to create a ongoing report that tracks families modified over the last 7 days.

This is a great internal report to help gauge and understand CCB usage at the family level.

This tutorial is not detailed, nor do we cover ALL there is you could do with this point.

I simply want to intro you to a few CCB API services built around gathering family detail.

You’ll likely be able to make the connection with all the many ways to use both services to enhance operations and processes using CCB.

Let’s get started!

Setup Variables and Includes

Open a text editor of your choice, naming and saving the following PHP file: family-list.php.

Be sure to include the appropriate comments and include files as shown below.

Next, define apiService and modDate variables as shown below:

  • apiService variable value is family_list
  • modDate variable value is date(‘Y-m-d’, strtotime(‘-7 days’));

The apiService variable value should be set to the CCB API service family_list. The modDate variable is used to return family results that have modified since a specified date.

As you can see below, we’ve not hardcoded a value for the modDate variable, but we’ve chosen to use two built-in PHP methods: date and strtotime.

Not hard coding the dates will allow for this page to be dynamically display the last seven (7) days from the current date when the report is executed.

As a stretch goal, you could create a drop down where a user specifies dates or selects a pre-populated date selection (i.e., last 7 days, last 14 days, last 30 days, etc.). This drop could then set the modDate variable to the selected value as chosen by the user via the drop down menu/select.

Nevertheless, read up on the family_list and its respective parameters via the CCB Public Web API documentation.

Prepping and Making API Call, and Prepping Response Data

Now that the input variables are defined, it’s time to prepare to make the CCB API call.

But before we can make the call, the variables in the last section must be binded to their respective CCB API label or parameter.

Create a urlData variable so that we can define its value as a binded labels and variables. This binding is a key-value pair array encapsulated using PHP’s built-in array_filter method, using the following:

  • srv label binds to apiService variable
  • modified_since label binds to modDate variable

Now that the urlData has been successfully defined, it’s time to define the rss variable and it’s value to make the CCB API call.

Set the rss variable equal to the ccbDetails function, passing it get as the first argument and the urlData variable as the second argument.

If you’re not familiar with the ccbDetails function, then feel free to read and review the heavy lifting magic this function provides here.

Parsing and display the family_list data

Up to this point, we’ve successfully made the CCB API call to retrieve results for family_list API service. Now, it’s time to parse the data response.

To parse the response, we’ll use a PHP built-in XPATH query method and the following response: //families/family.

You’ll have to refer to CCB’s Public Web API documentation for specific schema information.

Next, lets prepare a concatenating response_object variable for when we view the report via a web browser.

Create an empty response_object variable and then using the “.=” operator to provide concatenation, create the following lines:

We simply gave the report a title, displayed date from 7 days ago, and the total number of families by using PHP’s built-in sizeof method to tally the nodes variable.

Speaking of nodes variable, it’s time to parse each node or family that was returned in the result.

For reporting sake, I’ve opted to return a box for each family, displaying family last name and email for now.

You can choose to show more such as totaling the number of individuals in a family. However, for the sake of time and this tutorial, I only wanted to show family name and email.

Create a foreach statement so that we can iterate through each family collected and return to the nodes variable.

Within the foreach statement, we’re going to introduce another CCB API service via the getFamilyDetail functions: family_detail.

Because family_list doesn’t return specific enough detail (i.e., email, picture, etc.), we must use family_detail to gain access to such data.

Create a data_object variable and set it equal to the getFamilyDetail function, passing $node[‘id’] as the one and only argument.

In short, we’re passing the ccbDetails function the unique family id and returning specific family attributes via an array.

Below the data_object variable, create a few concatenated response_object variables that encapsulate the data_object variable array values for name and email.

Close the foreach statement and echo the response_object variable. That’s it for this for this tutorial. Easy huh?

Time to save, open and test in a web browser

Following this tutorial section by section and step by step, you should have code in your family-list.php that resembles the following:

Save the code and open the file in a web browser, and it should look like the following:

This tutorial barely scratches the surface on all that you can display via the web browser. Let you imagination run wild with all the options of where you can take this tutorial.

Personally, I envision a dashboard to be used in our church to help staff and deacons get accustomed on a weekly basis to the new families joining our congregation, seeing we can get families to upload a picture.

I’ll leave you be and let you have it, extending this tutorial. See you back here next week. Have a blessed week.

getFamilyDetail Function

This function returns specific details about a given family using the family_detail CCB API service. I’ve commented out a quite a few fields below within the function to show what type of information can be returned.

Please comment if this tutorial has helped you.