Accessing and Displaying Group Profiles By ID

In today’s tutorial, I’m sharing with you how to access and display group profiles by id.

Not to be confused with the group_profiles API service — which allows you to pass in a given date and have all groups created or modified since that date returned to you, today’s tutorial will access group_profiles_from_id API service.

So instead of focusing on returning ALL group profiles, we’ll focus on accessing and displaying a specific group by its group id (as shown below).

 

That stated, let’s get started with today’s tutorial. 

One of the first actions to take is opening a text editor of your choice, and naming and saving the following php file: group-profile-id.php.

Setting of Variables and Include Files

As with previous tutorials, be sure to include the config.php file and the appropriate comments.

Next, it’s time to define the following required parameters for the group_profiles_from_id API service:

  • apiService – value equals group_profile_from_id
  • groupId – value is equal to the specific group id
  • imageLink – value is false by default, but set the value equal to true for this tutorial

Once required variables are defined, each variable must be bound to its respective label as defined by CCB’s API Documentation for group_profiles_from_id.

Set binded variables and labels within a filtered array via the urlData variable.

Once urlData variable is appropriately defined, the ccbDetails function can be instantiated by passing get as the first argument and the urlData as the second argument.

The ccbDetails function does the heavy lifting to authenticate, authorize, access, and retrieve data from the CCB system.

Once the response is successfully returned as defined by the rss variable, create a nodes variable and set it equal to the rss variable.

The rss variable uses a reference or pointer to parse the response data using the following expression in conjunction to PHP’s XPATH query method: //groups/group.

Now that the response data has been accessed and parse for the specific group id, it’s time to access each data point for display to the web browser.

To do so, create an empty response_object variable and then create a foreach statement to iterate the nodes variable.

Within the foreach statement, the following data points for the specific group id can be accessed and concatenated using HTML tags via the response_object variable:

<?PHP

$node['id']; // group id
$node->name; // group name
$node->description; // group description
$node->image; // group image
$node->campus; // church campus for selected group
$node->campus['id']; // church campus id for selected group
$node->group_type; // group type name
$node->group_type['id']; // group type id
$node->department; // department name
$node->department['id']; // department id
$node->calendar_feed; // group web calendar link
$node->registration_forms; // registration forms
$node->current_members; // number of active/current members listed
$node->group_capacity; // type of capacity available for group; set number or unlimited by default
$node->addresses; // group addresses
$node->meeting_day; // group meets on this day
$node->meeting_time; // group meets at this time
$node->childcare_provided; // whether or not childcare is provided
$node->interaction_type; // group interaction type allowed
$node->notification; // whether or not notifications are enabled
$node->user_defined_fields; // user defined fields associated with group
$node->listed; // group is publicly listed
$node->public_search; // group is available for public search
$node->inactive; // whether or not group is set to inactive
$node->creator; // person that created group
$node->creator['id']; // person id that created group
$node->modifier; // person that last modified group
$node->creator['id']; // person id that last modified group
$node-created; // date group was created
$node-modified; // date group was last modified

// MAIN LEADER INFORMATION
$node->main_leader['id']; // main group leader id
$node->main_leader->first_name; // main group leader first name
$node->main_leader->last_name; // main group leader last name
$node->main_leader->full_name; // main group leader full name
$node->main_leader->email; // main group leader email
$node->main_leader->phones->phone; // main group leader phone number
$node->main_leader->phones->phone['type']; // main group leader phone type

// LEADER(S) INFORMATION -- same information is available for participants
$node->leader['id']; // group leader id
$node->leader->first_name; // group leader first name
$node->leader->last_name; // group leader last name
$node->leader->full_name; // group leader full name
$node->leader->email; // group leader email
$node->leader->phones->phone; // group leader phone number
$node->leader->phones->phone['type']; // group leader phone type

?>

Once the aforementioned data points have been defined with the foreach statement, don’t forget the close the foreach statement and echo the response_object as the last step before saving.

Guess What Time It Is?

Yes, it’s time to test your technical prowess. Below is the code in it’s entirety. Be sure to save the file before opening it via a web browser.

<?PHP

/**
 * group profile from id
 */

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

$apiService = 'group_profile_from_id'; // CCB api service
$groupID = '159'; // Adult Worship Team
$imageLink = true; // includes image link if set to true; default is false

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

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

$nodes = $rss->xpath('//groups/group');  // xpath for groups

$response_object = '';

foreach ($nodes as $node)
{
    
	$response_object .= '<h2>'.$node->name.'</h2>';
	$response_object .= '<p>Group Type: <b>'.$node->group_type.'</b>  |  Deparment: <b>'.$node->department.'</b>  |  Campus: <b>'.$node->campus.'</b></p>';
	$response_object .= '<p>Meeting Day: '.$node->meeting_day.'  |  Meeting Time: '.$node->meeting_time.'  |  <a href="'.$node->calendar_feed.'">Calendar</a></p>';
	$response_object .= '<p><img src="'.$node->image.'" />'.$node->description.'</p>';	

    /*  // GROUP OPTIONS
    	$node['id']; 								// group id
		$node->name; 								// group name
		$node->description;							// group description
		$node->image;								// group image
		$node->campus;								// church campus for selected group
		$node->campus['id']; 						// church campus id for selected group
		$node->group_type;							// group type name
		$node->group_type['id'];					// group type id
		$node->department;							// department name
		$node->department['id'];					// department id
		$node->calendar_feed;						// group web calendar link
		$node->registration_forms;					// registration forms
		$node->current_members;						// number of active/current members listed
		$node->group_capacity;						// type of capacity available for group; set number or unlimited by default
		$node->addresses; 							// group addresses
		$node->meeting_day;							// group meets on this day
		$node->meeting_time;						// group meets at this time
		$node->childcare_provided;					// whether or not childcare is provided
		$node->interaction_type;					// group interaction type allowed
		$node->notification;						// whether or not notifications are enabled
		$node->user_defined_fields;					// user defined fields associated with group
		$node->listed; 								// group is publicly listed
		$node->public_search;						// group is available for public search
		$node->inactive;							// whether or not group is set to inactive
		$node->creator;								// person that created group
		$node->creator['id'];						// person id that created group
		$node->modifier;							// person that last modified group
		$node->creator['id'];						// person id that last modified group
		$node-created;								// date group was created
		$node-modified;								// date group was last modified
		

		// MAIN LEADER INFORMATION
		$node->main_leader['id'];					// main group leader id
		$node->main_leader->first_name;				// main group leader first name
		$node->main_leader->last_name;				// main group leader last name
		$node->main_leader->full_name;				// main group leader full name
		$node->main_leader->email;					// main group leader email
		$node->main_leader->phones->phone;			// main group leader phone number
		$node->main_leader->phones->phone['type'];	// main group leader phone type


		// LEADER(S) INFORMATION -- same information is available for participants
		$node->leader['id'];						// group leader id
		$node->leader->first_name;					// group leader first name
		$node->leader->last_name;					// group leader last name
		$node->leader->full_name;					// group leader full name
		$node->leader->email;						// group leader email
		$node->leader->phones->phone;				// group leader phone number
		$node->leader->phones->phone['type'];		// group leader phone type
		
    */
}

echo $response_object;

?>

Barring any technical errors, the following or something similar should be displayed via the web browser:

 

In closing, this tutorial should help you unlock the door to displaying group info via your website or church app (hint, hint). 😉

I’m signing off now, but let me know if you have questions or encounter any technical challenges.

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