我试图[title]
从以下数组中提取出来,然后对每个标题执行一个函数。
大批:
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
)
)
)
这是我用来尝试获取组标题的 php,然后将它们中的每一个传递给 SMS 服务的 API,以在第 3 方站点上添加创建每个组,然后将联系人添加到该组。
foreach ($result as &$groupt){
$group = $project->getOrCreateGroup($groupt['title']);
$contact->addToGroup($group);
}
这是完整的代码:
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();
}
}
}