I'm trying to use a php hook to automatically create a relationship between two contacts. Let me set the stage for you.
Meeting Extender: a custom data set that extends the meeting activity(activity entity). It basically records a few custom fields, two of which are contact references(think pitcher and pitchee). These two fields would be two integers referring to contact A and contact B. Basically, I want to write a hook that creates a relationship, called Pitched to (A to B) and been Pitched(B to A).
The pipeline
A meeting is created, in the custom field set Google is saved as contact A and Apple is saved as contact B. The hook should realize a new activity has been created, check if the Pitched relationship exists between Google --> Apple and if not create it.
This was my attempt so far(in an extension)
function checkActivityMakeRelationship_civicrm_post($op, $objectName, $objectId, &$objectRef) {
/* This file checks if an activity was created and if so
*/
if(($op == 'create' || $op == 'edit') && $objectName == 'Activity') {
$result = civicrm_api3('Relationship', 'create', array(
'sequential' => 1,
'contact_id_a' => **integer-referring-to-contact-a**,
'contact_id_b' => **integer-referring-to-contact-b**,
'relationship_type_id' => 11,//this is the relationship type for pitched
));
}
}
Ignoring the 'relationship-already-exists' check for now, how to I find the correct integers for the contact A and contact B i just entered in to my custom data set. I imagine it is a part of $op but I'm not sure how to access it. Any help is appreciated, thanks. V
PS: I'm running wordpress 4.2.4 and civicrm 4.6.6