Ok, I’m back with another tutorial this week. This tutorial is sure to get ideas flowing for you.

A few weeks ago, I walked through how to insert, delete, update and list Lookup Table Services.

Last week I followed up with how to read a person’s individual fit using the CCB API.

And this week I’m sharing how to update a person’s individual fit using the CCB API.

We don’t have time to waste, so let’s get started.

Start by copying code

Rather than have you rewrite code from scratch, I’ll have you copy and paste code from last week’s tutorial.

Open a text editor of your choice, copy and paste the last week’s code, and save the new file.

Changing and adding variables

You should have defined apiService and personID variables. Change both to the following:

  • Set apiService equal to update_individual_fit
  • Set personID equal to respective person id (I used 3224 in this tutorial)

Making the CCB API call to update data

Okay, so here’s where things change up a bit.

For starters, you’ll need to ensure that the ccbDetails function in the general.php has been updated. Simply copy, paste, and replace the old ccbDetails function with the new ccbDetails function.

We’re now ready to define servData and urlData variables.

The servData variable is set equal to an array containing binded labels and data:

  • Bind srv label to apiService variable
  • Bind individual_id label to personID variable

The urlData variable is set equal to a multi-dimensional array containing binded labels and data.

In this example, I used spiritual_gifts and then the option id 14, which is Leadership in our CCB account.

Nevertheless, the following individual fit parameters can be updated as integers or integer arrays:

  • spiritual_gifts
  • passions
  • abilities
  • personality_style

Finally, define the rss variable and set it equal to the newly updated ccbDetails function, passing get as the first argument, servData variable as the second argument, and urlData variable as the third argument.

And that’s it! All the other code can stay the same.

NOTE: It’s very important to remember that updating a person’s individual_fit DELETES their previously selected options. If you desire to keep their previously selected or existing options or simply add to their selected or existing options, then you must list or read the person’s individual fit options first and save all as a multi-dimensional array. Once this happens, then simply append the multi-dimensional array with the new fit options for their respective array.

Bringing it all together

Here’s what your code should now look like:

<?PHP

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

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

$personID = 3224;

$servData = array_filter( array(
	'srv' => "$apiService",
	'individual_id' => $personID
	) );

$urlData = array_filter(
	array(
		'spiritual_gifts' => array(
			14
			)
		)
	);

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

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

$response_object = '';

foreach ($nodes as $node)
{

		$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;

?>

Save your file and open the file using a web browser.

You should now be able to update a person’s individual fit options.

Now go and check the CCB web interface.  Search for the person you updated, and then edit their project and check the My Fit section for your updates to see if they were applied.

With a little work, you could make the script a bit more dynamic by adding the following functionality:

  • Use CCB function to look up a person’s id instead of hardcoding it
  • Add functionality to capture existing individual fit options and then append new options

Well that’s all for now. I’ll see you next week with a brand new tutorial.

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