CRM-16055 fix relationship form to be adding related memberships properly (in the...
authorEileen McNaughton <eileen@fuzion.co.nz>
Mon, 16 Mar 2015 12:30:37 +0000 (01:30 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 16 Mar 2015 12:35:37 +0000 (01:35 +1300)
CRM/Contact/BAO/Relationship.php
CRM/Contact/Form/Relationship.php

index 8058f331669503a8d825e5a9aba1aa745f147d2f..e2be22f36ba6bffb560a2fc5da83a9bf18224873 100644 (file)
@@ -60,8 +60,12 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
     }
     $relationship = self::add($params);
     if (!empty($params['contact_id_a'])) {
-      $ids = array('contactTarget' => $relationship->contact_id_b, 'contact' => $params['contact_id_a']);
-      CRM_Contact_BAO_Relationship::relatedMemberships($params['contact_id_a'], $values, $ids, (empty($params['id']) ? CRM_Core_Action::ADD : CRM_Core_Action::UPDATE));
+      $ids = array(
+        'contactTarget' => $relationship->contact_id_b,
+        'contact' => $params['contact_id_a'],
+      );
+      CRM_Contact_BAO_Relationship::relatedMemberships($params['contact_id_a'], $params, $ids, (empty($params['id']) ?
+        CRM_Core_Action::ADD : CRM_Core_Action::UPDATE));
     }
 
     // Alter related membership if the is_active param is changed.
@@ -72,6 +76,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
       }
       CRM_Contact_BAO_Relationship::disableEnableRelationship($params['id'], $action);
     }
+
     self::addRecent($params, $relationship);
     return $relationship;
   }
@@ -1362,6 +1367,7 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
     // Check the end date and set the status of the relationship
     // accordingly.
     $status = self::CURRENT;
+    $targetContact = $targetContact = CRM_Utils_Array::value('contact_check', $params, array());
 
     if (!empty($params['end_date'])) {
       $endDate = CRM_Utils_Date::setDateDefaults(CRM_Utils_Date::format($params['end_date']), NULL, 'Ymd');
@@ -1391,13 +1397,13 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
       // this call is coming from somewhere where the direction was resolved early on (e.g an api call)
       // so we can assume _a_b
       $relDirection = "_a_b";
+      $targetContact = array($params['contact_id_b'] => 1);
     }
-    $targetContact = array();
+
     if (($action & CRM_Core_Action::ADD) ||
       ($action & CRM_Core_Action::DELETE)
     ) {
       $contact = $contactId;
-      $targetContact = CRM_Utils_Array::value('contact_check', $params);
     }
     elseif ($action & CRM_Core_Action::UPDATE) {
       $contact = $ids['contact'];
index 073d596f1d65f07483785ded481eccdc779df5cf..453178ad73322ba93cc7fbb5a0e6d541f1c1676a 100644 (file)
@@ -478,13 +478,6 @@ class CRM_Contact_Form_Relationship extends CRM_Core_Form {
 
     $params['relationship_ids'] = $relationshipIds;
 
-    if ($this->_action & CRM_Core_Action::ADD && !empty($params['is_active'])) {
-      CRM_Contact_BAO_Relationship::relatedMemberships($this->_contactId,
-        $params, $ids,
-        $this->_action
-      );
-    }
-
     // Refresh contact tabs which might have been affected
     $this->ajaxResponse['updateTabs'] = array(
       '#tab_member' => CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId),