Fitting into ministry with CCB’s gifting, abilities, passions, and personality styles

I’m back this week with a follow up tutorial to last week’s tutorial about using CCB’s Lookup Table Services.

As one’s church grows, so does the needs of the church.

From staff to attendees and members, it can be a challenge to make sense of everyone’s gifting, abilities, passions and personality styles.

Today’s tutorial focuses on how to use the CCB API to retrieve and view an individual’s My Fit selections for the following sections: Ability, Gifting, Passions and Personality Styles.

Let’s get started.

Setup variables and include files

First things first, open your text editor of choice and start with necessary comments and files.

Next, as with previous tutorials, set the apiService variable, making it individual_fit.

After apiService variable has been setup, then define and set the personID to the individual id of choice.

For the sake of simplifying this tutorial, I’m not using the CCB API to retrieve the individual ids, but don’t let it stop you.

<?PHP

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

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

$personID = 3224;

?>

Making the CCB API call for Individual Fit

It’s time to bind variables and prepare API call.

To bind variables, create a urlData variable equal to an array with srv as key and apiService variable as the value.

Next, define a rss variable and set it equal to the ccbDetails function, passing get as the first argument and the urlData as the second argument.

<?PHP

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

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

?>

Time to parse the XML response

Define a nodes variable and set it equal to the rss variable pointed to the XPATH query, using the following expression: //individuals/individual.

Next, set an empty response_object variable and then prepare a foreach statement, passing to it the nodes variable.

<?PHP

$nodes = $rss->xpath('//individuals/individual');  // xpath for individuals->individual

$response_object = '';

foreach ($nodes as $node)
{

}

?>

Parsing each individual’s fit data

Because the individual_fit service returns data for ALL users, I’m using an if statement to ensure the individual’s id is equal to the personID.

You don’t have to use the if statement logic if you’re wanting to iterate through each person.

Nevertheless, once inside the if statement, it’s time to validate the person has abilities, passions, gifting, and personality styles to be viewed using the following variables:

  • Set abilitiesData equal to $node->abilities->ability;
  • Set passionsData equal to $node->passions->passion;
  • Set spritiualGiftingData equal to $node->spiritual_gifts->spiritual_gift;
  • Set personalityStyleData equal to $node->personality_style->personality_style;

Next, it’s time to set and define the following variables to empty:

  • abilitiesArr
  • passionsArr
  • spiritualGiftingArr
  • personalityStyleArr

Before we’re ready to return whether or not an individual has fit data, we’ll set up if statements for the following variables:

  • abilitiesData
  • passionsData
  • spiritualGiftingData
  • personalityStyleData

After each aforementioned if statement, set each of the following variables equal to and concatenated using the .= operator to their respective if statement:

  • Set abilitiesArr equal to the prepareFitOutput function, passing Abilities as the first argument and abilitiesData variable as the second.
  • Set passionsArr equal to the prepareFitOutput function, passing Passions as the first argument and passionData variable as the second.
  • Set spiritualGiftingArr equal to the prepareFitOutput function, passing Spiritual Gifting as the first argument and spiritualGiftingData variable as the second.
  • Set personalityStyleArr equal to the prepareFitOutput function, passing Personality Style as the first argument and personalityStyleData variable as the second.

Next, define a response_object variable and set it equal, using the .= operator, to the concatenated list of the following variables:

  • abilitiesArr
  • passionsArr
  • spiritualGiftingArr
  • personalityStyleArr

Finally close both if and foreach statements, and then echo the response_object variable.

<?PHP

foreach ($nodes as $node)
{

	if($node['id'] == $personID){

		$abilitiesData = $node->abilities->ability;
		$passionsData = $node->passions->passion;
		$spiritualGiftingData = $node->spiritual_gifts->spiritual_gift;
		$personalityStyleData = $node->personality_style->personality_style;

		$abilitiesArr = $passionsArr = $spiritualGiftingArr = $personalityStyleArr = '';

		if($abilitiesData)
			$abilitiesArr .= prepareFitOutput('Abilities',$abilitiesData);

		if($passionsData)
			$passionsArr .= prepareFitOutput('Passions',$passionsData);

		if($spiritualGiftingData)
			$spiritualGiftingArr .= prepareFitOutput('Spiritual Gifting',$spiritualGiftingData);

		if($personalityStyleData)
			$personalityStyleArr .= prepareFitOutput('Personality Style',$personalityStyleData);

    	$response_object .= $abilitiesArr.$passionsArr.$spiritualGiftingArr.$personalityStyleArr;  // now print the item name and it (See CCB API documentation for more $apiService fields)

	}
}

echo $response_object;

?>

It’s time to test your technical prowess

Here’s what your code should look like. Before I forget… I’ve included the prepareFitOutput function in the file, but you should include the function in the general.php file.

<?PHP

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

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

$personID = 3224;

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

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

$nodes = $rss->xpath('//individuals/individual');  // xpath for individuals->individual

$response_object = '';

foreach ($nodes as $node)
{

	if($node['id'] == $personID){

		$abilitiesData = $node->abilities->ability;
		$passionsData = $node->passions->passion;
		$spiritualGiftingData = $node->spiritual_gifts->spiritual_gift;
		$personalityStyleData = $node->personality_style->personality_style;

		$abilitiesArr = $passionsArr = $spiritualGiftingArr = $personalityStyleArr = '';

		if($abilitiesData)
			$abilitiesArr .= prepareFitOutput('Abilities',$abilitiesData);

		if($passionsData)
			$passionsArr .= prepareFitOutput('Passions',$passionsData);

		if($spiritualGiftingData)
			$spiritualGiftingArr .= prepareFitOutput('Spiritual Gifting',$spiritualGiftingData);

		if($personalityStyleData)
			$personalityStyleArr .= prepareFitOutput('Personality Style',$personalityStyleData);

    	$response_object .= $abilitiesArr.$passionsArr.$spiritualGiftingArr.$personalityStyleArr;  // now print the item name and it (See CCB API documentation for more $apiService fields)

	}
}

echo $response_object;



function prepareFitOutput($title,$arrayData){

	$dataArr = '<h2>'.$title.'</h2>';

	foreach($arrayData as $Data){

		$dataArr .= $Data.'<br/>';

	}

	return $dataArr;

}

?>

Ok, save your file, and open the file using a web browser. This tutorial code produces the following output:

screen-shot-2016-10-29-at-5-59-00-pm

Next week, I’ll show you how to update an individual’s fit options using the CCB’s API.

Have a great week and I’ll see you around.

prepareFitOutput function

This function accepts a string as it’s first argument and an array as the second argument.

I used this function to simplify the code, reducing it by an approximate 30 lines.

Anytime you use the same line of code within the same file, then it likely needs to be a function.

Nevertheless, I pass the title of the fit section as the first argument, and the selected options for each fit as the second argument.

I then iterate over each selected option.

Finally, I return both the title and options encapsulated within HTML. That’s it.

<?PHP

function prepareFitOutput($title,$arrayData){

	$dataArr = '<h2>'.$title.'</h2>';

	foreach($arrayData as $Data){

		$dataArr .= $Data.'<br/>';

	}

	return $dataArr;

}

?>

 

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...