Listing, updating, deleting and inserting Lookup Table services

It’s been a week of early mornings and late nights for me, yet I thrived and overcame. Onto the tutorial…

Many times churches desire a way to administratively collect and manage an attendee’s or member’s passions, spiritual gifting, and abilities.

Fortunately, CCB provides Lookup Table services for each of the aforementioned services.

Each service is has the capability to update, list, delete and insert by simply appending _update, _list, _delete and _insert respectively.

Today’s tutorial is about learning how to use Lookup Table Services, specifically how to list abilities.

Although not focusing on updating, deleting, and inserting, you can likely use the same code with some minor alterations.

There’s not much difference when updating, deleting and inserting than listing.

Setup variables and file inclusions

Just as with previous tutorials, include the config.php and the necessary comments.

Next, set the apiService variable equal to ability_list.

<?PHP

// contains resusable globals and functions
include("includes/config.php");

$apiService = 'ability_list'; // CCB api service

?>

Making CCB API call to retrieve data

The next variable to set and define is the urlData, which is going to bind the srv label to the apiService variable as a filtered array.

To make the CCB API call using ccbDetails function, set the rss variable equal the ccbDetails fucntion, and pass ‘get’ as the first argument and urlData as the second argument.

<?PHP

$urlData = array_filter( array(
	'srv' => "$apiService"
	) );

$rss = ccbDetails('get',$urlData); // transform to XML

?>

Parsing XML and displaying response

To parse the XML response from the CCB API call, begin by setting the node variable. Set it equal to the rss variable pointed to the PHP built-in XPATH query function, using the following expression: //items/item.

Next, set an empty response_object, and you’re ready to iterate the nodes variable using a foreach statement (see below).

<?PHP

$nodes = $rss->xpath('//items/item');  // xpath for items->item

$response_object = '';

?>

Within the foreach statement, set another response_object variable and concatenate the response data containing the ability name and id using the .= operator.

The last thing to do is now echo the response_object variable.

<?PHP

foreach ($nodes as $node)
{
    $response_object .= $node->name.' (ID: '.$node->id.')'."<br/>";  // now print the item name and it (See CCB API documentation for more $apiService fields)
}

echo $response_object;

?>

Time to test away…

Your code should look like the code below.

<?PHP

// contains resusable globals and functions
include("includes/config.php");

$apiService = 'ability_list'; // CCB api service

$urlData = array_filter( array(
	'srv' => "$apiService"
	) );

$rss = ccbDetails('get',$urlData); // transform to XML

$nodes = $rss->xpath('//items/item');  // xpath for items->item

$response_object = '';

foreach ($nodes as $node)
{
    $response_object .= $node->name.' (ID: '.$node->id.')'."<br/>";  // now print the item name and it (See CCB API documentation for more $apiService fields)
}

echo $response_object;

?>

It’s time to compile the code, save it a php file, and open the file in a web browser.

screen-shot-2016-10-29-at-2-50-07-pm

Again, this tutorial uses the _list option, having _update, _delete and _insert easily swapped.

Remember, there is an expansive list of additional Lookup Table Services.

We’ll look further into identifying and updating passions, gifting, and abilities for an individual’s CCB profile in the coming weeks.

See you around.

Related Posts

Subscribe and receive the following...

  • Inside CCB tips and tricks
  • Instant CCB tutorial alerts and updates
  • CCB How To's, Videos, Webinars and more...