Welcome. Have you ever wondered or been asked exactly how many families are in CCB?
Today’s tutorial is quite simple. This tutorial will help you identify or snapshot the exact number of families in your CCB environment.
I know you’re questioning and thinking, “why would anyone want to know the number of families in CCB?” Although not a mission-critical metric, knowing how many families within CCB could help identify a increase or decrease (oh no, never!) within your overall church attendance and engagement.
Add a little automation elbow grease to the tutorial we’ll soon cover, and you’ll be able to track track the number of families over time.
We won’t cover the automation piece today. However, feel free to review the following tutorials to get familiar with how to automate and track data using a MySQL database:
Who knows, you may be able to cobble together an automated CCB weekly report to track the total number of families in CCB.
Well, we don’t have a minute to waste. Let’s get started!
Open your text editor of choice, and create and save a file named total-number-ccb-families.php. Be sure to add the header comment, including the page name, and then include the config.php file found in your includes directory.
You are now ready to set the apiService variable, making it equal to the API service family_search.
Although we won’t use any of the additional parameters for the family_search API service in this tutorial, the following optional parameters are available:
Read and learn more about family_search additional parameters by reading the CCB API Documentation.
Of course, once you define the service name and optional parameter variables with their respective values, now you are ready to bing and prep the URL data for a CCB API request.
Like previous tutorials, create a urlData variable and assign it an array of binded service API labels and variables. Be sure to encapsulate the array with the array_filter function.
Now, create a rss variable and assign it the ccbDetails function. Pass get as the first argument and the urlData as the second argument.
The ccbDetails function will return a XML response. Parse this XML response using a XPATH query. For this tutorial, use the XPATH query expression //items.
Create a nodes variable and assign it the rss variable that is referencing the XPATH query.
Now, create a foreach statement to iterate through each nodes variable array response. Then, set the response_object equal to the node[‘count’] data, which will contain the total number of families in CCB.
Finally, echo the response_object variable to the web browser.
Open the file and you should see the total number of families in CCB echoed to the web browser display.
// contains resusable globals and functions
$apiService = 'family_search'; // CCB api service
$urlData = array_filter( array(
'srv' => "$apiService"
$rss = ccbDetails('get',$urlData); // transform to XML
$nodes = $rss->xpath('//items'); // xpath for individuals->individual
$response_object = '';
foreach ($nodes as $node)
$response_object = $node['count']; // now print the total number of families in CCB (See CCB API documentation for more $apiService fields)