Commit d5af01b4 authored by jaapjansma's avatar jaapjansma
Browse files

Fixed issue with related memberships

parent a0a1b36c
Version 1.5
Version 1.7
------------------------------
* Added action Get Relationship By Contact ID
* Added action Get State/Province ID by name
* Added action Add Tag to Contact
* Fixed issue with action create and create/update relationship and related memberships
Version 1.6
-----------
* Update related membership when create relationship or create/update relationship action is performed.
* Added action Get Contact By Custom Field.
Version 1.5
-----------
* Added action Get Relationship By Contact ID
* Fixed issue with the Get Relationship action
Version 1.4
......
......@@ -117,11 +117,25 @@ class CreateOrUpdateRelationship extends CreateRelationship {
try {
// Do not use api as the api checks for an existing relationship.
$relationship = \CRM_Contact_BAO_Relationship::add($relationshipParams);
$output->setParameter('id', $relationship->id);
$relationship_id = $relationship->id;
// Update the related memberships
$contact_ids = [
'contactTarget' => $relationshipParams['contact_id_b'],
'contact' => $relationshipParams['contact_id_a'],
];
// When the relationship end date is set to 'null' related memberships are deleted
if ($relationshipParams['end_date'] == 'null') {
$relationshipParams['end_date'] = null;
}
$action = !empty($relationshipParams['id']) ? \CRM_Core_Action::UPDATE : \CRM_Core_Action::ADD;
\CRM_Contact_BAO_Relationship::relatedMemberships($relationshipParams['contact_id_a'], $relationshipParams, $contact_ids, $action, TRUE);
$output->setParameter('id', $relationship_id);
} catch (\Exception $e) {
// Do nothing.
echo $e;
}
}
}
\ No newline at end of file
}
......@@ -130,10 +130,24 @@ class CreateRelationship extends AbstractAction {
try {
// Do not use api as the api checks for an existing relationship.
$relationship = \CRM_Contact_BAO_Relationship::add($relationshipParams);
$output->setParameter('id', $relationship->id);
$relationship_id = $relationship->id;
// Update the related memberships
$contact_ids = [
'contactTarget' => $relationshipParams['contact_id_b'],
'contact' => $relationshipParams['contact_id_a'],
];
// When the relationship end date is set to 'null' related memberships are deleted
if ($relationshipParams['end_date'] == 'null') {
$relationshipParams['end_date'] = null;
}
$action = \CRM_Core_Action::ADD;
\CRM_Contact_BAO_Relationship::relatedMemberships($relationshipParams['contact_id_a'], $relationshipParams, $contact_ids, $action, TRUE);
$output->setParameter('id', $relationship_id);
} catch (\Exception $e) {
// Do nothing.
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment