I am trying to pull the [title]
out of the following array and then perform a function with each title.
Array:
Array (
[is_error] => 0
[version] => 3
[count] => 2
[values] => Array (
[5] => Array (
[id] => 5
[group_id] => 1
[title] => 2014rootedemail
[visibility] => User and User Admin Only
[is_hidden] => 0
[in_date] => 2014-08-01 07:45:39
[in_method] => Admin
)
[6] => Array (
[id] => 6
[group_id] => 2
[title] => Student 2014
[visibility] => User and User Admin Only
[is_hidden] => 0
[in_date] => 2014-08-01 08:23:22
[in_method] => Admin
)
)
)
Here is the php I am using to try and take the group title and then pass each of them through an API for an SMS service to add the create each group on the 3rd party site and then add the contact to that group.
foreach ($result as &$groupt){
$group = $project->getOrCreateGroup($groupt['title']);
$contact->addToGroup($group);
}
Here is the full code:
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgCiviCRMBase extends JPlugin
{
/**
* Base Civicrm Plugin.
*
* @package Civicrm
* @subpackage Joomla plugins
* @since 1.6
*/
function civicrm_post( $op, $objectName, $objectId, &$objectRef )
{
if (($op == 'create' || $op =='edit') && $objectName == 'Individual') {
//Telerivet API CONNECT
require_once JPATH_SITE.'/media/civicrm/telerivet/telerivet.php';
$API_KEY = '----';
$PROJECT_ID = '----';
$telerivet = new Telerivet_API($API_KEY);
$project = $telerivet->initProjectById($PROJECT_ID);
//Get Variables Civicrm
$firstName = $objectRef->first_name;
$lastName = $objectRef->last_name;
$phone = $objectRef->phone[0]->phone;
$displayName = $objectRef->display_name;
//Get Groups the contact is in... Returns Above array
$params = array( 'contact_id' => $objectRef->id,'version' => 3,);
require_once 'api/api.php';
$result = civicrm_api( 'group_contact','get',$params );
// Telerivet Post New Contact to Telerivet
$contact = $project->getOrCreateContact(array(
'name' => $displayName,
'phone_number' => $phone,
'vars' => array('first' => $firstName, 'last' => $lastName)
));
// Add Contact to Telerivet Groups
//? Now how do I get each of the groups and then add the contact below for each group. for the contact?
foreach ($result as &$groupt){
$group = $project->getOrCreateGroup($groupt['title']);
$contact->addToGroup($group);
}
//print_r($groupt);
//exit();
}
}
}