Welcome back to this week’s tutorial.
Of course, it’s spring (no matter how short lived) here in Texas with summer to fast arrive.
Like most when spring arrives, we do a bit of spring cleaning around the house, ridding ourselves of things that once were the apple of our eye, yet we longer use.
In fact, we have a rule in our house that if we’ve not used it in 9 months, then it must go!
And as spring cleaning goes in our personal lives, we must also take a moment to do a bit of church digital cleaning to ensure that our church’s data remains updated and in tip-top shape.
Today’s tutorial focuses on helping you and your church quickly mark abandoned profiles/accounts, attendees, and members as inactive using the CCB API.
Word of caution before beginning
This is a critical tutorial that must be handled with care. If and when used improperly could result in CCB profiles no longer being accessed via the API and Church Community Builder system in its entirety.
Think of this tutorial very much a logical delete for the individual specified. That said, be CAUTIOUS and CAREFUL to ensure you have the correct perfect that needs to be set to inactivate.
Let’s get started.
Setup variables and includes
Start by opening a text editor of your choice, naming and saving the following php file: person-inactivate.php.
As usual, include the config.php file, and then define the following variables with their respective value:
- apiService variable set equal to individual_inactivate API service
- personID variable set to person’s CCB profile id
<?PHP /** * Individual Inactivate */ // contains resusable globals and functions include("includes/config.php"); $apiService = 'individual_inactivate'; // CCB api service $personID = '6168'; // Person's ID ?>
Of course, this tutorial only shows you how to inactivate one person, but could easily become a dynamic parse a CSV/Excel file for person ids to inactivate with a bit of elbow grease.
It’s fairly easy to do, and I think you can figure this out! If fact, I know you can!
Prepare API call and parse its response
All of the variables are set, right?
Next, it’s time to create a urlData array variable that binds both the API service and id labels to the apiService and personID variables.
Now prepare to make the API call using the ccbDetails function, passing it get as the first argument and urlData variable as the second.
Once the call has been made, then it’s time to define a nodes variable and set it to parse the rss variable’s XML response for data using PHP’s built-in XPATH method and the following expression: //individuals/individual.
<? $urlData = array_filter( array( 'srv' => "$apiService", 'id' => "$personID" ) ); $rss = ccbDetails('get',$urlData); // transform to XML $nodes = $rss->xpath('//individuals/individual'); // xpath for individual ?>
Time to capture and display results
To capture and display the results of the CCB API call to inactivate an individual, define an empty response_object variable.
Next, create a foreach statement the iterates the nodes variable response data. Within the foreach statement, re-define the response_object variable to use the .= operator to concatenate data.
Finally, close the foreach statement and echo the response_object variable.
<?PHP $response_object = ''; foreach ($nodes as $node) { $response_object .= $node->success.': '.$node->name.' has an inactive status of '.$node->inactive.'<br/>'; } echo $response_object; ?>
Time to test your code
Okay, it’s that time already. It’s time to test your code.
PLEASE BE SURE THAT YOU HAVE THE RIGHT PERSON’S ID OR GROUP OF INDIVIDUAL IDS.
You don’t want to incorrectly inactivate the wrong person trying to accomplish a good thing in church digital cleaning.
SO, PLEASE DOUBLE, TRIPLE and QUADRUPLE check your list of individuals before executing code.
Better yet, test with only 1 ID first before attempting a bulk inactivate.
If ready, then your code should look like the following code below. Go ahead and fire up your web browser, and test away when ready.
Hopefully all is well with your test, and you now have updated and clean CCB system data. Remember to do digital clean annually or bi-annually.
I wish you the best, and I look forward to seeing you back here next week for another CCB API tutorial.
<?PHP /** * Individual Inactivate */ // contains resusable globals and functions include("includes/config.php"); $apiService = 'individual_inactivate'; // CCB api service $personID = '6168'; // Person's ID $urlData = array_filter( array( 'srv' => "$apiService", 'id' => "$personID" ) ); $rss = ccbDetails('get',$urlData); // transform to XML $nodes = $rss->xpath('//individuals/individual'); // xpath for individual $response_object = ''; foreach ($nodes as $node) { $response_object .= $node->success.': '.$node->name.' has an inactive status of '.$node->inactive.'<br/>'; } echo $response_object; ?>