Welcome back to CCBTutorials.com for this week’s tutorial.  

A few weeks back, I stumbled across a request about adding a group of people to a significant event via Church Community Builder’s (CCB) The Village.

I waited a few days to see if a response would surface, but nothing ever surfaced.  Here’s the person’s original request:

We have set up our system so a person’s baptism date is a Significant Event with Date. Normally entering them is fine since we usually only do a handful of baptisms at a time so it goes quickly. 

However, a couple of weeks ago we had a “Baptism Service” and we had around 100 people get baptized in one evening. I thought as the Master Admin I’d be able to do a mass add, but it doesn’t look like the Significant Event field is an option for a mass change. 

Does anyone have any ideas about how to do this without doing them one at a time?   

So, you guessed right if you guessed that today’s tutorial is about adding significant events for individuals.

Let’s get started…

As usual, I won’t go into great detail with this tutorial. 

Fortunately, there are more than enough CCB tutorials that go into detail about how to make the CCB API call and parse the XML response.

To break down the opening statement and question, compile the significant event data for individuals using an Excel/CSV file (see example below).

Add Significant Event to Individual Excel/CSV Files

Once data is compiled, then you’re ready to parse your Excel and CSV File using PHP.

Open a text editor of your choice, naming and saving the file as parse-ase.php.  The ‘ase’ part of file is short for add significant event. 

For more explanation of the parsing Excel and CSV files using PHP, click here.

Notice within the code that there are two functions executed: getPersonId and addPersonSignificantEvent.  Before I explain both functions, don’t forget to include the functions in the general.php file.

The getPersonId function originates from the How to Search for Inactive Individuals or Profiles tutorial.

In short, you provide the function the first name, last name, email and/or phone number, and the function returns the person’s individual CCB id.

Then, take the person’s id, event id, event date and significantEventName, and create another array to be passed to the addPersonSignificantEvent function.

The addPersonSignificantEvent function does the heavy lifting  to add the respective significant event to the person’s profile.

Once the significant event has been successfully created, then the addPersonSignificantEvent function returns a string stating such (see web browser display below).

Add Significant Event to Individual Web Browser Display

Let me close saying that this tutorial could use a bit more error and validation pertaining to the functions.

I simply wanted to provide you with the main scaffolding, and allow you to fill in the rest where you see fit (maybe using other CCB Tutorials).

That’s it for this tutorial.  Save your file, test away in a web browser, and do let me know if you have questions or comments.

Hopefully, you can now kiss those days of manually adding significant events to individuals by hand good bye, and say hello to harnessing the power of CCB’s API automation.

From hours to minutes, I wish you much success.  Now go and find more tasks to do with your newly found time savings. 😉

See you back here next week for another tutorial.

<?PHP

/**
 * Adding a Significant Event to Individual
 * person-ase.php
 */

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

// file containing persons

$err_upTmpName = 'person-ase.csv';

$reportPersonSignificantEvent = '';

$row = 0;

if (($handle = fopen($err_upTmpName, "r")) !== FALSE) {

	while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {

		if($row == 0){ 
			$row++; 
		} else {

			// $data[0] = first name; $data[1] = last name; $data[2] = email; $data[3] = phone; $data[4] = eventId; $data[5] = eventDate; $data[6] = significantEventName;
			/*********************************************************************************************************************/
			if(!empty($data[0]) && !empty($data[1])){ 

				$personId = getPersonId($data);
				$eventId = $data[4];
				$eventDateTime = $data[5]; // YYYY-MM-DD
				$significantEventName = $data[6];

				$eventInfo = array();
				$eventInfo = array("$personId", "$eventId","$eventDateTime","$significantEventName");


				if(!empty($personId) && !empty($eventId) && !empty($eventDateTime)){

					$reportPersonSignificantEvent .= addPersonSignificantEvent($eventInfo);

				}
			}

		}

	}

} else {

	echo 'File could not be opened.';
}	

fclose($handle);

echo $reportPersonSignificantEvent;


/*****************************************************
** FUNCTION RETURNS THE PERSON ID
*****************************************************/

function getPersonId($data){

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

// sample field to search for (See CCB API documentation for more $apiService fields)
$firstname = "$data[0]"; 
$lastname = "$data[1]"; 
//$phone = "$data[2]"; 
//$email = "$data[3]"; 

$urlData = array_filter( array(
	'srv' => "$apiService",
	'first_name' => "$firstname",
	'last_name' => "$lastname"
	) );

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

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

$response_object = '';

foreach ($nodes as $node)
{
    $response_object = $node['id'];  // now print the person's full name and age (See CCB API documentation for more $apiService fields)
}

return $response_object;

}

/*****************************************************
** FUNCTION ADDS SIGNIFICANT EVENT FOR INDIVIDUAL
*****************************************************/

function addPersonSignificantEvent($data){

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

	$urlData = array_filter( array(
	'srv' => "$apiService",
	'id' => "$data[0]",
	'event_id' => "$data[1]",
	'date' => "$data[2]"
	) );

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

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

$response_object = '';

foreach ($nodes as $node)
{
    if($node->name == $data[3]){

    	$response_object = 'Significant Event ('.$node->name.') was added for person id <b>'.$data[0].'</b> pertaining to event id <b>'.$data[1].'</b> on <b>'.$data[2].'</b>.<br>';  // now print event id (See CCB API documentation for more $apiService fields)

    }
}

return $response_object;

}


?>

 

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