Allow bidirectional assignment of relationships from search results
authorMorgan <morgan@palantetech.coop>
Wed, 27 May 2020 21:48:57 +0000 (17:48 -0400)
committerMorgan <morgan@palantetech.coop>
Tue, 2 Jun 2020 02:05:38 +0000 (22:05 -0400)
CRM/Case/Form/AddToCaseAsRole.php
CRM/Contact/BAO/Relationship.php

index f2809047e3c97398e3caf18df8f555d3f7319307..91d55122a985d4fe3a9c8e2bd24ad54c7cd76041 100644 (file)
@@ -51,7 +51,10 @@ class CRM_Case_Form_AddToCaseAsRole extends CRM_Contact_Form_Task {
     $roleTypes = [];
 
     foreach ($relType as $k => $v) {
-      $roleTypes[substr($k, 0, strpos($k, '_'))] = $v;
+      //Limit this to relationship types from contact A to B
+      if (substr($k, -4) == "_a_b") {
+        $roleTypes[substr($k, 0, strpos($k, '_'))] = $v;
+      }
     }
 
     return $roleTypes;
index 3dc3b0321ca79ac8fed8385c3f7e0a4c5f5b924b..24122a128a84b9a4ecc81227948e5ffa2ed92300 100644 (file)
@@ -1489,13 +1489,14 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
   }
 
   /**
-   * Get get list of relationship type based on the target contact type.
+   * Get list of relationship type based on the target contact type.
+   * Both directions of relationships are included if their labels are not the same.
    *
    * @param string $targetContactType
-   *   It's valid contact tpye(may be Individual , Organization , Household).
+   *   A valid contact type (may be Individual, Organization, Household).
    *
    * @return array
-   *   array reference of all relationship types with context to current contact type .
+   *   array reference of all relationship types with context to current contact type.
    */
   public static function getRelationType($targetContactType) {
     $relationshipType = [];
@@ -1505,6 +1506,11 @@ LEFT JOIN  civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
       if ($type['contact_type_b'] == $targetContactType || empty($type['contact_type_b'])) {
         $relationshipType[$key . '_a_b'] = $type['label_a_b'];
       }
+      if (($type['contact_type_a'] == $targetContactType || empty($type['contact_type_a']))
+        && $type['label_a_b'] != $type['label_b_a']
+      ) {
+        $relationshipType[$key . '_b_a'] = $type['label_b_a'];
+      }
     }
 
     return $relationshipType;