Retrieve a list of significant events for individuals

Welcome back. Not too long ago, we discussed how to add significant events to a group of persons within CCB.

Well, today’s tutorial expounds upon the aforementioned tutorial whereby I’ll show you how to retrieve a list of significant events for a specific individual.

Although this tutorial focuses on a single individual, this tutorial can be modified to return significant events for a group of persons too.

Let us get started.

Set up variables, comments and inclusion files

Open a text editor of your choice, saving and naming a php file the following: person-lse.php.

As usual, be sure to include the necessary comments and files inclusions. Once you complete this step, then define the following variables and their respective values:

  • apiService – Set the value to be the individual_significant_events CCB API Service
  • personId – This is an optional integer field for a specific individual’s CCB id

If you’re in search of a specific person’s CCB id, then review this tutorial.

However, you may be starting with one or more CBB individual ids in spreadsheet format.

If within a spreadsheet, then you may want to brush up on how you parse and retrieve information Excel/CSV data.

However you decide to input data is your choice, but there are a few ways to develop this tutorial. Again, we’ll focus on the single id for now.

Once variables are defined and assigned their respective values, it’s now time to prepare the data to be passed to the ccbDetails function that makes the API call.

To prepare the data, create a urlData variable and assign it an array encased within the built-in PHP array_filter method that contains the following fields:

  • srv => apiService variable
  • id => personId variable (optional)

Time for API Call and XML Response Parsing

The data has been prepared, and now it’s time for the heavy lifting use of ccbDetails function to make the API Call.

Should you not be familiar with the CCB function, then take a moment to review here.

To get started, define the rss variable, making it equal to the ccbDetails function.

Next, set nodes variable equal to $rss->path function, using the following XPATH expression: //individuals/individual.

Next, set an empty response_object variable. This variable will be used to capture and concatenate each person’s data.

Now it’s time to parse, rather iterate, through each person contained via the nodes variable using a foreach statement.

Once within the initial foreach statement, create and set the response_object variable to concatenate each individual’s name using $node->full_name between h4 header tags.

Next, create a procdata variable to capture significant event data.

You may be after one or more significant events for a person or group of persons.

To display significant event data, you’ll want to check to be sure there is data to display using an if statement for the procdata variable.

Once within the if statement, then create a second foreach statement that iterates the procdata variable.

Within this same foreach statement, set the response_object variable to concatenate each significant event’s data points as indicated below:

  • $data->name
  • $data->date

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

Ready to test your code?

Okay, so it’s now time to put your code into one file, save it and test it. Here’s what you should have:

Open your file using a web browser and hopefully you see something like the image below:

Screen Shot 2016-08-16 at 4.47.26 PM

Well, that’s it for this week. As always, there are a myriad of ways to build and extend this tutorial’s functionality.

From reading and parsing Excel/CSV files to automating this report and emailing it, the sky is the limit with the number of actions to take using this tutorial.

Let me know if you have questions. Thanks and see you back soon for the next tutorial.


Please comment if this tutorial has helped you.