Today I’m back with yet another tutorial using Church Community Builder’s Public Web API Tool.
This week’s tutorial will focus on how to retrieve position list and a list of position holders for the respective position list.
Our church doesn’t use position lists (yet!) as of today only because majority of our volunteer management is handled and managed well within Planning Center Online.
Nevertheless, today’s tutorial share’s the necessary code needed to use the position_list API service to retrieve and display position lists and a list of position holders for the respective position list.
If you need technical assistance understanding the code below, then might I suggest reading previous tutorials, especially the primer tutorial, or visit the Getting Started Toolbox.
Let’s get started with today’s tutorial!
<?PHP // contains resusable globals and functions include("includes/config.php"); $apiService = 'position_list'; // CCB api service $urlData = array_filter( array( 'srv' => "$apiService" ) ); $rss = ccbDetails('get',$urlData); // transform to XML $nodes = $rss->xpath('//positions/position'); // xpath for custom_fields/custom_field $response_object = '<h1>Position List</h1>'; foreach ($nodes as $node) { // now print the position name and description // (See CCB API documentation for more $apiService fields) $response_object .= '<h2>'.$node->name.'</h2>'; if($node->description) $response_object .= '<p>'.$node->description.'</p>'; // now check and validate position holders existence, and // print the position holder name, status, and status date // (See CCB API documentation for more $apiService fields) $itemdata = $node->position_holders->position_holder; if($itemdata){ $response_object .= '<ul>'; foreach($itemdata as $idata){ $response_object .= '<li><b>'.$idata->name.'</b> ('.$idata->status.', '.$idata->status_date.')</li>'; } $response_object .= '</ul>'; } } echo $response_object; ?>
The code above should give great insight in regards to positions that exist in your CCB account and persons filling such positions, producing the following data hierarchy when viewed and executed via a web browser (example data used):
Process List
Event Coordinator
This is an event coordinator role description
- Jane Doe (Fills Currently, 2015-12-30 10:34:00)
- Julie Doe (Fills Currently, 2015-12-20 09:34:00)
- John Doe (Fills Currently, 2015-12-19 11:34:00)
Crew Leader
This is a crew leader role description
- Jack Doe (Fills Currently, 2015-12-20 09:44:00)
- Jessica Doe (Fills Currently, 2015-12-23 07:14:00)
- James Doe (Fills Currently, 2015-12-27 12:54:00)
To learn more about the position_list API service, please refer to CCB API Documentation.
Well, that’s it for today’s tutorial. I know most of the tutorials have been simple in nature over the past few months as we close out an expansive list of CCB API services.
Hang in there as we close out the list though. Soon and very soon, we’ll focus on how to use services in conjunction to begin to build simple applications with functionality not built or found within CCB.
Thanks and see you back here next week. That’s all for now!